Skip to content

Commit a7930a0

Browse files
committed
[domain availability] Don't diagnose unguarded uses of enumerators
inside case label expressions rdar://160337621
1 parent 4975a64 commit a7930a0

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

clang/lib/Sema/SemaFeatureAvailability.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ class DiagnoseUnguardedFeatureAvailability
6767

6868
bool TraverseIfStmt(IfStmt *If);
6969

70+
// Ignore unguarded uses of enumerators inside case label expressions.
71+
bool TraverseCaseStmt(CaseStmt *Case) {
72+
return TraverseStmt(Case->getSubStmt());
73+
}
74+
7075
bool VisitDeclRefExpr(DeclRefExpr *DRE) {
7176
diagnoseDeclFeatureAvailability(DRE->getDecl(), DRE->getBeginLoc());
7277
return true;

clang/test/Sema/feature-availability.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,17 @@ void test7(void) {
235235
enum E e;
236236
e = EA;
237237
e = EB; // expected-error {{cannot use 'EB' because feature 'feature2' is unavailable in this context}}
238+
239+
switch (e) {
240+
case EA: {
241+
if (__builtin_available(domain:feature2))
242+
e = EB;
243+
break;
244+
}
245+
case EB: // no diagnostic
246+
e = EB; // expected-error {{cannot use 'EB' because feature 'feature2' is unavailable in this context}}
247+
break;
248+
}
238249
}
239250

240251
if (__builtin_available(domain:feature2)) {

0 commit comments

Comments
 (0)