diff options
author | Alexander Kornienko <alexfh@google.com> | 2014-06-24 15:28:21 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2014-06-24 15:28:21 +0000 |
commit | bf91164f1c8690a9ab1804de8a50396bc57a90cb (patch) | |
tree | 44dea1c28d1e9e14b1e48f552114d6c41bcf1157 /clang/test/SemaCXX/switch-implicit-fallthrough.cpp | |
parent | 3b92c5bd41b5c75b6baae52904081f683d8a9718 (diff) | |
download | bcm5719-llvm-bf91164f1c8690a9ab1804de8a50396bc57a90cb.tar.gz bcm5719-llvm-bf91164f1c8690a9ab1804de8a50396bc57a90cb.zip |
Fix "warning: fallthrough annotation does not directly precede switch label" in lambdas.
Summary: This patch fixes http://llvm.org/PR17864 - "warning: fallthrough annotation does not directly precede switch label" in lambdas.
Reviewers: rsmith
Reviewed By: rsmith
Subscribers: rnk, cfe-commits
Differential Revision: http://reviews.llvm.org/D4258
llvm-svn: 211599
Diffstat (limited to 'clang/test/SemaCXX/switch-implicit-fallthrough.cpp')
-rw-r--r-- | clang/test/SemaCXX/switch-implicit-fallthrough.cpp | 60 |
1 files changed, 41 insertions, 19 deletions
diff --git a/clang/test/SemaCXX/switch-implicit-fallthrough.cpp b/clang/test/SemaCXX/switch-implicit-fallthrough.cpp index 831324a64e9..0bc43cdbd45 100644 --- a/clang/test/SemaCXX/switch-implicit-fallthrough.cpp +++ b/clang/test/SemaCXX/switch-implicit-fallthrough.cpp @@ -229,25 +229,6 @@ int fallthrough_covered_enums(Enum e) { 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() { @@ -259,12 +240,34 @@ 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(); @@ -278,3 +281,22 @@ namespace PR18983 { } } } + +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; +} |