summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2014-06-24 15:28:21 +0000
committerAlexander Kornienko <alexfh@google.com>2014-06-24 15:28:21 +0000
commitdc372a9212ae124e4b634f50a0339f0488b6d6b5 (patch)
tree7eb48191861cef70aadce7b038832d18f6b90e60
parent8d4db1f1af86be205b576abb3707da937f31ecd5 (diff)
downloadclang-dc372a9212ae124e4b634f50a0339f0488b6d6b5.tar.gz
clang-dc372a9212ae124e4b634f50a0339f0488b6d6b5.tar.bz2
clang-dc372a9212ae124e4b634f50a0339f0488b6d6b5.tar.xz
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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211599 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/AnalysisBasedWarnings.cpp3
-rw-r--r--test/SemaCXX/switch-implicit-fallthrough.cpp60
2 files changed, 44 insertions, 19 deletions
diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp
index 0e522dc415..c4524cde93 100644
--- a/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/lib/Sema/AnalysisBasedWarnings.cpp
@@ -1025,6 +1025,9 @@ namespace {
// methods separately.
bool TraverseDecl(Decl *D) { return true; }
+ // We analyze lambda bodies separately. Skip them here.
+ bool TraverseLambdaBody(LambdaExpr *LE) { return true; }
+
private:
static const AttributedStmt *asFallThroughAttr(const Stmt *S) {
diff --git a/test/SemaCXX/switch-implicit-fallthrough.cpp b/test/SemaCXX/switch-implicit-fallthrough.cpp
index 831324a64e..0bc43cdbd4 100644
--- a/test/SemaCXX/switch-implicit-fallthrough.cpp
+++ b/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;
+}