Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3e4e3b1

Browse filesBrowse files
committed
[Sema] Don't warn about omitting unavailable enum constants in a switch
rdar://42717026 Differential revision: https://reviews.llvm.org/D51649 llvm-svn: 341490
1 parent 52a503d commit 3e4e3b1
Copy full SHA for 3e4e3b1

File tree

Expand file treeCollapse file tree

2 files changed

+42
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+42
-1
lines changed

‎clang/lib/Sema/SemaStmt.cpp

Copy file name to clipboardExpand all lines: clang/lib/Sema/SemaStmt.cpp
+15-1Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,21 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch,
11641164

11651165
SmallVector<DeclarationName,8> UnhandledNames;
11661166

1167-
for (EI = EnumVals.begin(); EI != EIEnd; EI++){
1167+
for (EI = EnumVals.begin(); EI != EIEnd; EI++) {
1168+
// Don't warn about omitted unavailable EnumConstantDecls.
1169+
switch (EI->second->getAvailability()) {
1170+
case AR_Deprecated:
1171+
// Omitting a deprecated constant is ok; it should never materialize.
1172+
case AR_Unavailable:
1173+
continue;
1174+
1175+
case AR_NotYetIntroduced:
1176+
// Partially available enum constants should be present. Note that we
1177+
// suppress -Wunguarded-availability diagnostics for such uses.
1178+
case AR_Available:
1179+
break;
1180+
}
1181+
11681182
// Drop unneeded case values
11691183
while (CI != CaseVals.end() && CI->first < EI->first)
11701184
CI++;

‎clang/test/Sema/switch-availability.c

Copy file name to clipboard
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %clang_cc1 -verify -Wswitch -triple x86_64-apple-macosx10.12 %s
2+
3+
enum SwitchOne {
4+
Unavail __attribute__((availability(macos, unavailable))),
5+
};
6+
7+
void testSwitchOne(enum SwitchOne so) {
8+
switch (so) {} // no warning
9+
}
10+
11+
enum SwitchTwo {
12+
Ed __attribute__((availability(macos, deprecated=10.12))),
13+
Vim __attribute__((availability(macos, deprecated=10.13))),
14+
Emacs,
15+
};
16+
17+
void testSwitchTwo(enum SwitchTwo st) {
18+
switch (st) {} // expected-warning{{enumeration values 'Vim' and 'Emacs' not handled in switch}}
19+
}
20+
21+
enum SwitchThree {
22+
New __attribute__((availability(macos, introduced=1000))),
23+
};
24+
25+
void testSwitchThree(enum SwitchThree st) {
26+
switch (st) {} // expected-warning{{enumeration value 'New' not handled in switch}}
27+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.