return n;
}
-int fallthrough_targets(int n) {
- [[clang::fallthrough]]; // expected-error{{fallthrough annotation is outside switch statement}}
-
- [[clang::fallthrough]] // expected-error{{fallthrough attribute is only allowed on empty statements}}
- switch (n) {
- case 121:
- n += 400;
- [[clang::fallthrough]]; // no warning here, correct target
- case 123:
- [[clang::fallthrough]] // expected-error{{fallthrough attribute is only allowed on empty statements}}
- n += 800;
- break;
- [[clang::fallthrough]] // expected-error{{fallthrough attribute is only allowed on empty statements}} expected-note{{did you forget ';'?}}
- case 125:
- n += 1600;
- }
- return n;
-}
-
// Fallthrough annotations in local classes used to generate "fallthrough
// annotation does not directly precede switch label" warning.
void fallthrough_in_local_class() {
[[clang::fallthrough]]; // no diagnostics
case 1:
x++;
+ default: // \
+ expected-warning{{unannotated fall-through between switch labels}} \
+ expected-note{{insert 'break;' to avoid fall-through}}
break;
}
}
};
}
+// Fallthrough annotations in lambdas used to generate "fallthrough
+// annotation does not directly precede switch label" warning.
+void fallthrough_in_lambda() {
+ (void)[] {
+ int x = 0;
+ switch (x) {
+ case 0:
+ x++;
+ [[clang::fallthrough]]; // no diagnostics
+ case 1:
+ x++;
+ default: // \
+ expected-warning{{unannotated fall-through between switch labels}} \
+ expected-note{{insert 'break;' to avoid fall-through}}
+ break;
+ }
+ };
+}
+
namespace PR18983 {
void fatal() __attribute__((noreturn));
int num();
}
}
}
+
+int fallthrough_targets(int n) {
+ [[clang::fallthrough]]; // expected-error{{fallthrough annotation is outside switch statement}}
+
+ [[clang::fallthrough]] // expected-error{{fallthrough attribute is only allowed on empty statements}}
+ switch (n) {
+ case 121:
+ n += 400;
+ [[clang::fallthrough]]; // no warning here, correct target
+ case 123:
+ [[clang::fallthrough]] // expected-error{{fallthrough attribute is only allowed on empty statements}}
+ n += 800;
+ break;
+ [[clang::fallthrough]] // expected-error{{fallthrough attribute is only allowed on empty statements}} expected-note{{did you forget ';'?}}
+ case 125:
+ n += 1600;
+ }
+ return n;
+}