diff options
author | Alexander Kornienko <alexfh@google.com> | 2013-02-07 02:17:19 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2013-02-07 02:17:19 +0000 |
commit | 878d0ad2c9d83ee6485fd16e21c5082acc63a890 (patch) | |
tree | f0cd536477945ab29c3e14de06c463ee476afdf0 /test/SemaCXX/switch-implicit-fallthrough.cpp | |
parent | cd3b036dbdd29b0ddcaa12b5cce69b647b2ac5ba (diff) |
-Wimplicit-fallthrough: fixed two cases where "fallthrough annotation in unreachable code" was issued incorrectly.
Summary:
-Wimplicit-fallthrough: fixed two cases where "fallthrough annotation in unreachable code" was issued incorrectly:
1. In actual unreachable code, but not immediately on a fall-through execution
path "fallthrough annotation does not directly precede switch label" is better;
2. After default: in a switch with covered enum cases. Actually, these shouldn't
be treated as unreachable code for our purpose.
Reviewers: rsmith
Reviewed By: rsmith
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D374
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174575 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/switch-implicit-fallthrough.cpp')
-rw-r--r-- | test/SemaCXX/switch-implicit-fallthrough.cpp | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/test/SemaCXX/switch-implicit-fallthrough.cpp b/test/SemaCXX/switch-implicit-fallthrough.cpp index bc94c9e750..0f7891dc53 100644 --- a/test/SemaCXX/switch-implicit-fallthrough.cpp +++ b/test/SemaCXX/switch-implicit-fallthrough.cpp @@ -179,38 +179,56 @@ void fallthrough_cfgblock_with_null_successor(int x) { int fallthrough_position(int n) { switch (n) { + [[clang::fallthrough]]; // expected-warning{{fallthrough annotation does not directly precede switch label}} + n += 300; [[clang::fallthrough]]; // expected-warning{{fallthrough annotation in unreachable code}} case 221: - [[clang::fallthrough]]; // expected-warning{{fallthrough annotation does not directly precede switch label}} + [[clang::fallthrough]]; // expected-warning{{fallthrough annotation does not directly precede switch label}} return 1; [[clang::fallthrough]]; // expected-warning{{fallthrough annotation in unreachable code}} case 222: - [[clang::fallthrough]]; // expected-warning{{fallthrough annotation does not directly precede switch label}} + [[clang::fallthrough]]; // expected-warning{{fallthrough annotation does not directly precede switch label}} n += 400; case 223: // 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}} [[clang::fallthrough]]; // expected-warning{{fallthrough annotation does not directly precede switch label}} } - // TODO: uncomment this test after CFG gets more options to deal with - // unreachable code: - // http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20120507/057370.html -#if 0 long p = static_cast<long>(n) * n; switch (sizeof(p)) { - case 9: // this test will not work on compilers with 72-bit long + case 9: n += static_cast<int>(p >> 32); [[clang::fallthrough]]; // no warning here - case 5: // it is not intended to work on compilers with 40-bit long as well + case 5: n += static_cast<int>(p); - break; + [[clang::fallthrough]]; // no warning here default: - break; + n += 1; + break; } -#endif return n; } +enum Enum { + Value1, Value2 +}; + +int fallthrough_covered_enums(Enum e) { + int n = 0; + switch (e) { + default: + n += 17; + [[clang::fallthrough]]; // no warning here, this shouldn't be treated as unreachable code + case Value1: + n += 19; + break; + case Value2: + n += 21; + break; + } + return n; +} + int fallthrough_targets(int n) { [[clang::fallthrough]]; // expected-error{{fallthrough annotation is outside switch statement}} |