diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index e8c1f8490342a..990d2fadaf5aa 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -1667,8 +1667,12 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, // Don't warn about omitted unavailable EnumConstantDecls. switch (EI->second->getAvailability()) { case AR_Deprecated: - // Omitting a deprecated constant is ok; it should never materialize. + // Deprecated enumerators still need to be handled: they may be + // deprecated, but can still occur. + break; + case AR_Unavailable: + // Omitting an unavailable enumerator is ok; it should never occur. continue; case AR_NotYetIntroduced: diff --git a/clang/test/Sema/switch-availability.c b/clang/test/Sema/switch-availability.c index 888edddac463d..fc44375fc83a0 100644 --- a/clang/test/Sema/switch-availability.c +++ b/clang/test/Sema/switch-availability.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -verify -Wswitch -triple x86_64-apple-macosx10.12 %s +// RUN: %clang_cc1 -verify -Wswitch -Wreturn-type -triple x86_64-apple-macosx10.12 %s enum SwitchOne { Unavail __attribute__((availability(macos, unavailable))), @@ -15,7 +15,7 @@ enum SwitchTwo { }; void testSwitchTwo(enum SwitchTwo st) { - switch (st) {} // expected-warning{{enumeration values 'Vim' and 'Emacs' not handled in switch}} + switch (st) {} // expected-warning{{enumeration values 'Ed', 'Vim', and 'Emacs' not handled in switch}} } enum SwitchThree { @@ -25,3 +25,16 @@ enum SwitchThree { void testSwitchThree(enum SwitchThree st) { switch (st) {} // expected-warning{{enumeration value 'New' not handled in switch}} } + +enum SwitchFour { + Red, + Green, + Blue [[deprecated]] +}; + +int testSwitchFour(enum SwitchFour e) { + switch (e) { // expected-warning{{enumeration value 'Blue' not handled in switch}} + case Red: return 1; + case Green: return 2; + } +} // expected-warning{{non-void function does not return a value in all control paths}}