This revision was automatically updated to reflect the committed changes. Closed by commit rL341490: [Sema] Don't warn about omitting unavailable enum constants in a switch (authored by epilk, committed by ). Herald added a subscriber: llvm-commits.
Changed prior to commit: https://reviews.llvm.org/D51649?vs=163863&id=164100#toc Repository: rL LLVM https://reviews.llvm.org/D51649 Files: cfe/trunk/lib/Sema/SemaStmt.cpp cfe/trunk/test/Sema/switch-availability.c Index: cfe/trunk/test/Sema/switch-availability.c =================================================================== --- cfe/trunk/test/Sema/switch-availability.c +++ cfe/trunk/test/Sema/switch-availability.c @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -verify -Wswitch -triple x86_64-apple-macosx10.12 %s + +enum SwitchOne { + Unavail __attribute__((availability(macos, unavailable))), +}; + +void testSwitchOne(enum SwitchOne so) { + switch (so) {} // no warning +} + +enum SwitchTwo { + Ed __attribute__((availability(macos, deprecated=10.12))), + Vim __attribute__((availability(macos, deprecated=10.13))), + Emacs, +}; + +void testSwitchTwo(enum SwitchTwo st) { + switch (st) {} // expected-warning{{enumeration values 'Vim' and 'Emacs' not handled in switch}} +} + +enum SwitchThree { + New __attribute__((availability(macos, introduced=1000))), +}; + +void testSwitchThree(enum SwitchThree st) { + switch (st) {} // expected-warning{{enumeration value 'New' not handled in switch}} +} Index: cfe/trunk/lib/Sema/SemaStmt.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaStmt.cpp +++ cfe/trunk/lib/Sema/SemaStmt.cpp @@ -1164,7 +1164,21 @@ SmallVector<DeclarationName,8> UnhandledNames; - for (EI = EnumVals.begin(); EI != EIEnd; EI++){ + for (EI = EnumVals.begin(); EI != EIEnd; EI++) { + // Don't warn about omitted unavailable EnumConstantDecls. + switch (EI->second->getAvailability()) { + case AR_Deprecated: + // Omitting a deprecated constant is ok; it should never materialize. + case AR_Unavailable: + continue; + + case AR_NotYetIntroduced: + // Partially available enum constants should be present. Note that we + // suppress -Wunguarded-availability diagnostics for such uses. + case AR_Available: + break; + } + // Drop unneeded case values while (CI != CaseVals.end() && CI->first < EI->first) CI++;
Index: cfe/trunk/test/Sema/switch-availability.c =================================================================== --- cfe/trunk/test/Sema/switch-availability.c +++ cfe/trunk/test/Sema/switch-availability.c @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -verify -Wswitch -triple x86_64-apple-macosx10.12 %s + +enum SwitchOne { + Unavail __attribute__((availability(macos, unavailable))), +}; + +void testSwitchOne(enum SwitchOne so) { + switch (so) {} // no warning +} + +enum SwitchTwo { + Ed __attribute__((availability(macos, deprecated=10.12))), + Vim __attribute__((availability(macos, deprecated=10.13))), + Emacs, +}; + +void testSwitchTwo(enum SwitchTwo st) { + switch (st) {} // expected-warning{{enumeration values 'Vim' and 'Emacs' not handled in switch}} +} + +enum SwitchThree { + New __attribute__((availability(macos, introduced=1000))), +}; + +void testSwitchThree(enum SwitchThree st) { + switch (st) {} // expected-warning{{enumeration value 'New' not handled in switch}} +} Index: cfe/trunk/lib/Sema/SemaStmt.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaStmt.cpp +++ cfe/trunk/lib/Sema/SemaStmt.cpp @@ -1164,7 +1164,21 @@ SmallVector<DeclarationName,8> UnhandledNames; - for (EI = EnumVals.begin(); EI != EIEnd; EI++){ + for (EI = EnumVals.begin(); EI != EIEnd; EI++) { + // Don't warn about omitted unavailable EnumConstantDecls. + switch (EI->second->getAvailability()) { + case AR_Deprecated: + // Omitting a deprecated constant is ok; it should never materialize. + case AR_Unavailable: + continue; + + case AR_NotYetIntroduced: + // Partially available enum constants should be present. Note that we + // suppress -Wunguarded-availability diagnostics for such uses. + case AR_Available: + break; + } + // Drop unneeded case values while (CI != CaseVals.end() && CI->first < EI->first) CI++;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits