summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/switch-implicit-fallthrough-macro.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2016-03-08 00:32:55 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2016-03-08 00:32:55 +0000
commit4f902c7eccd47cc3e1d0ceebca3025406a2e5fa7 (patch)
treef4f111a17e5cb2aa89e7050bd5c8ef41e30bc2f2 /clang/test/SemaCXX/switch-implicit-fallthrough-macro.cpp
parent12350a8e133caefd43d1bc1d18baa66ba5202a3d (diff)
downloadbcm5719-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-macro.cpp')
-rw-r--r--clang/test/SemaCXX/switch-implicit-fallthrough-macro.cpp30
1 files changed, 22 insertions, 8 deletions
diff --git a/clang/test/SemaCXX/switch-implicit-fallthrough-macro.cpp b/clang/test/SemaCXX/switch-implicit-fallthrough-macro.cpp
index add212fcf5d..11df2cbfb53 100644
--- a/clang/test/SemaCXX/switch-implicit-fallthrough-macro.cpp
+++ b/clang/test/SemaCXX/switch-implicit-fallthrough-macro.cpp
@@ -1,4 +1,8 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wimplicit-fallthrough -DCOMMAND_LINE_FALLTHROUGH=[[clang::fallthrough]] %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wimplicit-fallthrough -DCLANG_PREFIX -DCOMMAND_LINE_FALLTHROUGH=[[clang::fallthrough]] -DUNCHOSEN=[[fallthrough]] %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wimplicit-fallthrough -DCOMMAND_LINE_FALLTHROUGH=[[fallthrough]] %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z -Wimplicit-fallthrough -DCLANG_PREFIX -DCOMMAND_LINE_FALLTHROUGH=[[clang::fallthrough]] %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z -Wimplicit-fallthrough -DCOMMAND_LINE_FALLTHROUGH=[[clang::fallthrough]] %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z -Wimplicit-fallthrough -DCOMMAND_LINE_FALLTHROUGH=[[fallthrough]] -DUNCHOSEN=[[clang::fallthrough]] %s
int fallthrough_compatibility_macro_from_command_line(int n) {
switch (n) {
@@ -10,15 +14,12 @@ int fallthrough_compatibility_macro_from_command_line(int n) {
return n;
}
-#ifdef __clang__
-#if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
+#ifdef CLANG_PREFIX
#define COMPATIBILITY_FALLTHROUGH [ [ /* test */ clang /* test */ \
:: fallthrough ] ] // testing whitespace and comments in macro definition
-#endif
-#endif
-
-#ifndef COMPATIBILITY_FALLTHROUGH
-#define COMPATIBILITY_FALLTHROUGH do { } while (0)
+#else
+#define COMPATIBILITY_FALLTHROUGH [ [ /* test */ /* test */ \
+ fallthrough ] ] // testing whitespace and comments in macro definition
#endif
int fallthrough_compatibility_macro_from_source(int n) {
@@ -32,7 +33,11 @@ int fallthrough_compatibility_macro_from_source(int n) {
}
// Deeper macro substitution
+#ifdef CLANG_PREFIX
#define M1 [[clang::fallthrough]]
+#else
+#define M1 [[fallthrough]]
+#endif
#ifdef __clang__
#define M2 M1
#else
@@ -59,12 +64,17 @@ int fallthrough_compatibility_macro_in_macro(int n) {
#undef M2
#undef COMPATIBILITY_FALLTHROUGH
#undef COMMAND_LINE_FALLTHROUGH
+#undef UNCHOSEN
int fallthrough_compatibility_macro_undefined(int n) {
switch (n) {
case 0:
n = n * 20;
+#if __cplusplus <= 201402L
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}}
+#else
+ case 1: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert '[[fallthrough]];' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}}
+#endif
;
}
#define TOO_LATE [[clang::fallthrough]]
@@ -83,7 +93,11 @@ int fallthrough_compatibility_macro_history(int n) {
case 0:
n = n * 20;
#undef MACRO_WITH_HISTORY
+#if __cplusplus <= 201402L
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}}
+#else
+ case 1: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert '[[fallthrough]];' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}}
+#endif
;
#define MACRO_WITH_HISTORY [[clang::fallthrough]]
}
OpenPOWER on IntegriCloud