[clang] [Sema] Warn about omitting deprecated enumerator in switch (PR #138562)
via cfe-commits
cfe-commits at lists.llvm.org
Mon May 5 11:31:19 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Hans Wennborg (zmodem)
<details>
<summary>Changes</summary>
This undoes part of 3e4e3b17c14c15c23c0ed18ca9165b42b1b13ae3 which added the "Omitting a deprecated constant is ok; it should never materialize." logic.
That seems wrong: deprecated means the enumerator is likely to be removed in future versions, not that it cannot materialize.
---
Full diff: https://github.com/llvm/llvm-project/pull/138562.diff
2 Files Affected:
- (modified) clang/lib/Sema/SemaStmt.cpp (+5-1)
- (modified) clang/test/Sema/switch-availability.c (+1-1)
``````````diff
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..b4f8726addc0b 100644
--- a/clang/test/Sema/switch-availability.c
+++ b/clang/test/Sema/switch-availability.c
@@ -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 {
``````````
</details>
https://github.com/llvm/llvm-project/pull/138562
More information about the cfe-commits
mailing list