aboutsummaryrefslogtreecommitdiff
path: root/test/SemaCXX/switch-implicit-fallthrough.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2013-01-30 03:49:44 +0000
committerAlexander Kornienko <alexfh@google.com>2013-01-30 03:49:44 +0000
commit4874a8143dc3032205f97527ff619730db3d1f57 (patch)
treefd6f43451e458f74a7ff35f7756820bca0651a84 /test/SemaCXX/switch-implicit-fallthrough.cpp
parente28f6abf588f51a21d1db638e460f9c086c08db4 (diff)
Don't warn on fall-through from unreachable code.
Summary: A motivating example: class ClassWithDtor { public: ~ClassWithDtor() {} }; void fallthrough3(int n) { switch (n) { case 2: do { ClassWithDtor temp; return; } while (0); // This generates a chain of unreachable CFG blocks. case 3: break; } } Reviewers: rsmith, doug.gregor, alexfh Reviewed By: alexfh CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D330 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173889 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/switch-implicit-fallthrough.cpp')
-rw-r--r--test/SemaCXX/switch-implicit-fallthrough.cpp29
1 files changed, 22 insertions, 7 deletions
diff --git a/test/SemaCXX/switch-implicit-fallthrough.cpp b/test/SemaCXX/switch-implicit-fallthrough.cpp
index 93e724e86c..912b21ebfd 100644
--- a/test/SemaCXX/switch-implicit-fallthrough.cpp
+++ b/test/SemaCXX/switch-implicit-fallthrough.cpp
@@ -10,7 +10,7 @@ int fallthrough(int n) {
} else if (n - 3) {
n = 102;
}
- case -1: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert '[[clang::fallthrough]];' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}}
+ case -1: // no warning here, ignore fall-through from unreachable code
;
case 0: {// expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert '[[clang::fallthrough]];' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}}
}
@@ -39,14 +39,13 @@ int fallthrough(int n) {
break;
}
switch (n / 15) {
-label_case_70:
- case 70:
+label_default:
+ default:
n += 333;
+ if (n % 10)
+ goto label_default;
break;
- case 71:
- n += 334;
- goto label_case_70;
- case 72:
+ case 70:
n += 335;
break;
}
@@ -130,6 +129,22 @@ void fallthrough2(int n) {
}
}
+void fallthrough3(int n) {
+ switch (n) {
+ case 1:
+ do {
+ return;
+ } while (0);
+ case 2:
+ do {
+ ClassWithDtor temp;
+ return;
+ } while (0);
+ case 3:
+ break;
+ }
+}
+
#define MY_SWITCH(X, Y, Z, U, V) switch (X) { case Y: Z; case U: V; }
#define MY_SWITCH2(X, Y, Z) switch (X) { Y; Z; }
#define MY_CASE(X, Y) case X: Y