diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-03-08 00:32:55 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-03-08 00:32:55 +0000 |
commit | 4f902c7eccd47cc3e1d0ceebca3025406a2e5fa7 (patch) | |
tree | f4f111a17e5cb2aa89e7050bd5c8ef41e30bc2f2 /clang/test/SemaCXX/switch-implicit-fallthrough.cpp | |
parent | 12350a8e133caefd43d1bc1d18baa66ba5202a3d (diff) | |
download | bcm5719-llvm-4f902c7eccd47cc3e1d0ceebca3025406a2e5fa7.tar.gz bcm5719-llvm-4f902c7eccd47cc3e1d0ceebca3025406a2e5fa7.zip |
P0188R1: add support for standard [[fallthrough]] attribute. This is almost
exactly the same as clang's existing [[clang::fallthrough]] attribute, which
has been updated to have the same semantics. The one significant difference
is that [[fallthrough]] is ill-formed if it's not used immediately before a
switch label (even when -Wimplicit-fallthrough is disabled). To support that,
we now build a CFG of any function that uses a '[[fallthrough]];' statement
to check.
In passing, fix some bugs with our support for statement attributes -- in
particular, diagnose their use on declarations, rather than asserting.
llvm-svn: 262881
Diffstat (limited to 'clang/test/SemaCXX/switch-implicit-fallthrough.cpp')
-rw-r--r-- | clang/test/SemaCXX/switch-implicit-fallthrough.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/clang/test/SemaCXX/switch-implicit-fallthrough.cpp b/clang/test/SemaCXX/switch-implicit-fallthrough.cpp index 0bc43cdbd45..9540b1ff288 100644 --- a/clang/test/SemaCXX/switch-implicit-fallthrough.cpp +++ b/clang/test/SemaCXX/switch-implicit-fallthrough.cpp @@ -179,18 +179,15 @@ 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}} 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}} 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}} + ; } long p = static_cast<long>(n) * n; @@ -282,6 +279,23 @@ namespace PR18983 { } } +int fallthrough_placement_error(int n) { + switch (n) { + [[clang::fallthrough]]; // expected-warning{{fallthrough annotation in unreachable code}} + n += 300; + case 221: + [[clang::fallthrough]]; // expected-error{{fallthrough annotation does not directly precede switch label}} + return 1; + case 222: + [[clang::fallthrough]]; // expected-error{{fallthrough annotation does not directly precede switch label}} + n += 400; + [[clang::fallthrough]]; + case 223: + [[clang::fallthrough]]; // expected-error{{fallthrough annotation does not directly precede switch label}} + } + return n; +} + int fallthrough_targets(int n) { [[clang::fallthrough]]; // expected-error{{fallthrough annotation is outside switch statement}} |