| 1 |
// C++ 26 P2552R3 - On the ignorability of standard attributes |
| 2 |
// { dg-do compile { target c++11 } } |
| 3 |
|
| 4 |
int arr[2]; |
| 5 |
struct S { int a, b; }; |
| 6 |
S arr2[2]; |
| 7 |
|
| 8 |
void |
| 9 |
foo (int n) |
| 10 |
{ |
| 11 |
switch (n) |
| 12 |
{ |
| 13 |
case 1: |
| 14 |
[[fallthrough (n > 0)]]; // { dg-error "'fallthrough' attribute does not take any arguments" } |
| 15 |
case 2: |
| 16 |
break; |
| 17 |
case 3: |
| 18 |
[[fallthrough]]; |
| 19 |
case 4: |
| 20 |
break; |
| 21 |
case 5: |
| 22 |
[[fallthrough ("abc")]]; // { dg-error "'fallthrough' attribute does not take any arguments" } |
| 23 |
case 6: |
| 24 |
break; |
| 25 |
case 7: |
| 26 |
[[fallthrough (1, 2, 3)]]; // { dg-error "'fallthrough' attribute does not take any arguments" } |
| 27 |
case 8: |
| 28 |
[[fallthrough]]; // { dg-error "attribute 'fallthrough' not preceding a case label or default label" } |
| 29 |
foo (n - 1); |
| 30 |
break; |
| 31 |
default: |
| 32 |
break; |
| 33 |
} |
| 34 |
|
| 35 |
[[fallthrough]] int x1; // { dg-error "'fallthrough' attribute ignored" } |
| 36 |
|
| 37 |
auto a = [] [[fallthrough]] () {}; // { dg-error "'fallthrough' attribute ignored" } |
| 38 |
auto b = [] constexpr [[fallthrough]] {}; // { dg-error "'fallthrough' attribute ignored" } |
| 39 |
// { dg-error "parameter declaration before lambda declaration specifiers only optional with" "" { target c++20_down } .-1 } |
| 40 |
// { dg-error "'constexpr' lambda only available with" "" { target c++14_down } .-2 } |
| 41 |
auto c = [] noexcept [[fallthrough]] {}; // { dg-error "'fallthrough' attribute ignored" } |
| 42 |
// { dg-error "parameter declaration before lambda exception specification only optional with" "" { target c++20_down } .-1 } |
| 43 |
auto d = [] () [[fallthrough]] {}; // { dg-error "'fallthrough' attribute ignored" } |
| 44 |
auto e = new int [n] [[fallthrough]]; // { dg-warning "attributes ignored on outermost array type in new expression" } |
| 45 |
auto e2 = new int [n] [[fallthrough]] [42]; // { dg-warning "attributes ignored on outermost array type in new expression" } |
| 46 |
auto f = new int [n][42] [[fallthrough]]; // { dg-error "'fallthrough' attribute ignored" } |
| 47 |
[[fallthrough]] {} // { dg-warning "attributes at the beginning of statement are ignored" } |
| 48 |
[[fallthrough]] if (true) {} // { dg-warning "attributes at the beginning of statement are ignored" } |
| 49 |
[[fallthrough]] while (false) {} // { dg-warning "attributes at the beginning of statement are ignored" } |
| 50 |
[[fallthrough]] goto lab; // { dg-warning "attributes at the beginning of statement are ignored" } |
| 51 |
[[fallthrough]] lab:; // { dg-error "'fallthrough' attribute ignored" } |
| 52 |
[[fallthrough]] try {} catch (int) {} // { dg-warning "attributes at the beginning of statement are ignored" } |
| 53 |
if ([[fallthrough]] int x = 0) {} // { dg-error "'fallthrough' attribute ignored" } |
| 54 |
switch (n) |
| 55 |
{ |
| 56 |
[[fallthrough]] case 1: // { dg-error "'fallthrough' attribute ignored" } |
| 57 |
[[fallthrough]] break; // { dg-warning "attributes at the beginning of statement are ignored" } |
| 58 |
[[fallthrough]] default: // { dg-error "'fallthrough' attribute ignored" } |
| 59 |
break; |
| 60 |
} |
| 61 |
for ([[fallthrough]] auto a : arr) {} // { dg-error "'fallthrough' attribute ignored" } |
| 62 |
for ([[fallthrough]] auto [a, b] : arr2) {} // { dg-error "'fallthrough' attribute ignored" } |
| 63 |
// { dg-error "structured bindings only available with" "" { target c++14_down } .-1 } |
| 64 |
[[fallthrough]] asm (""); // { dg-warning "attributes ignored on 'asm' declaration" } |
| 65 |
try {} catch ([[fallthrough]] int x) {} // { dg-error "'fallthrough' attribute ignored" } |
| 66 |
try {} catch ([[fallthrough]] int) {} // { dg-error "'fallthrough' attribute ignored" } |
| 67 |
try {} catch (int [[fallthrough]] x) {} // { dg-warning "attribute ignored" } |
| 68 |
try {} catch (int [[fallthrough]]) {} // { dg-warning "attribute ignored" } |
| 69 |
try {} catch (int x [[fallthrough]]) {} // { dg-error "'fallthrough' attribute ignored" } |
| 70 |
} |
| 71 |
|
| 72 |
[[fallthrough]] int bar (); // { dg-error "'fallthrough' attribute ignored" } |
| 73 |
using foobar [[fallthrough]] = int; // { dg-error "'fallthrough' attribute ignored" } |
| 74 |
[[fallthrough]] int a; // { dg-error "'fallthrough' attribute ignored" } |
| 75 |
[[fallthrough]] auto [b, c] = arr; // { dg-error "'fallthrough' attribute ignored" } |
| 76 |
// { dg-error "structured bindings only available with" "" { target c++14_down } .-1 } |
| 77 |
[[fallthrough]]; // { dg-warning "attribute ignored" } |
| 78 |
inline [[fallthrough]] void baz () {} // { dg-warning "attribute ignored" } |
| 79 |
// { dg-error "standard attributes in middle of decl-specifiers" "" { target *-*-* } .-1 } |
| 80 |
constexpr [[fallthrough]] int qux () { return 0; } // { dg-warning "attribute ignored" } |
| 81 |
// { dg-error "standard attributes in middle of decl-specifiers" "" { target *-*-* } .-1 } |
| 82 |
int [[fallthrough]] d; // { dg-warning "attribute ignored" } |
| 83 |
int const [[fallthrough]] e = 1; // { dg-warning "attribute ignored" } |
| 84 |
struct A {} [[fallthrough]]; // { dg-warning "attribute ignored in declaration of 'struct A'" } |
| 85 |
struct A [[fallthrough]]; // { dg-warning "attribute ignored" } |
| 86 |
struct A [[fallthrough]] a1; // { dg-warning "attribute ignored" } |
| 87 |
A [[fallthrough]] a2; // { dg-warning "attribute ignored" } |
| 88 |
enum B { B0 } [[fallthrough]]; // { dg-warning "attribute ignored in declaration of 'enum B'" } |
| 89 |
enum B [[fallthrough]]; // { dg-warning "attribute ignored" } |
| 90 |
enum B [[fallthrough]] b1; // { dg-warning "attribute ignored" } |
| 91 |
B [[fallthrough]] b2; // { dg-warning "attribute ignored" } |
| 92 |
struct [[fallthrough]] C {}; // { dg-error "'fallthrough' attribute ignored" } |
| 93 |
int f [[fallthrough]]; // { dg-error "'fallthrough' attribute ignored" } |
| 94 |
int g[2] [[fallthrough]]; // { dg-error "'fallthrough' attribute ignored" } |
| 95 |
int g2 [[fallthrough]] [2]; // { dg-error "'fallthrough' attribute ignored" } |
| 96 |
int corge () [[fallthrough]]; // { dg-error "'fallthrough' attribute ignored" } |
| 97 |
int *[[fallthrough]] h; // { dg-error "'fallthrough' attribute ignored" } |
| 98 |
int & [[fallthrough]] i = f; // { dg-error "'fallthrough' attribute ignored" } |
| 99 |
int && [[fallthrough]] j = 0; // { dg-error "'fallthrough' attribute ignored" } |
| 100 |
int S::* [[fallthrough]] k; // { dg-error "'fallthrough' attribute ignored" } |
| 101 |
auto l = sizeof (int [2] [[fallthrough]]); // { dg-error "'fallthrough' attribute ignored" } |
| 102 |
int freddy ([[fallthrough]] int a, // { dg-error "'fallthrough' attribute ignored" } |
| 103 |
[[fallthrough]] int, // { dg-error "'fallthrough' attribute ignored" } |
| 104 |
[[fallthrough]] int c = 0, // { dg-error "'fallthrough' attribute ignored" } |
| 105 |
[[fallthrough]] int = 0); // { dg-error "'fallthrough' attribute ignored" } |
| 106 |
void |
| 107 |
corge ([[fallthrough]] int a, // { dg-error "'fallthrough' attribute ignored" } |
| 108 |
[[fallthrough]] int, // { dg-error "'fallthrough' attribute ignored" } |
| 109 |
[[fallthrough]] int c = 0, // { dg-error "'fallthrough' attribute ignored" } |
| 110 |
[[fallthrough]] int = 0) // { dg-error "'fallthrough' attribute ignored" } |
| 111 |
{ |
| 112 |
} |
| 113 |
[[fallthrough]] void |
| 114 |
garply () // { dg-error "'fallthrough' attribute ignored" } |
| 115 |
{ |
| 116 |
} |
| 117 |
int grault (int [[fallthrough]] a, // { dg-warning "attribute ignored" } |
| 118 |
int [[fallthrough]], // { dg-warning "attribute ignored" } |
| 119 |
int [[fallthrough]] c = 0, // { dg-warning "attribute ignored" } |
| 120 |
int [[fallthrough]] = 0); // { dg-warning "attribute ignored" } |
| 121 |
void |
| 122 |
waldo (int [[fallthrough]] a, // { dg-warning "attribute ignored" } |
| 123 |
int [[fallthrough]], // { dg-warning "attribute ignored" } |
| 124 |
int [[fallthrough]] c = 0, // { dg-warning "attribute ignored" } |
| 125 |
int [[fallthrough]] = 0) // { dg-warning "attribute ignored" } |
| 126 |
{ |
| 127 |
} |
| 128 |
int plugh (int a [[fallthrough]], // { dg-error "'fallthrough' attribute ignored" } |
| 129 |
int b [[fallthrough]] = 0); // { dg-error "'fallthrough' attribute ignored" } |
| 130 |
void |
| 131 |
thud (int a [[fallthrough]], // { dg-error "'fallthrough' attribute ignored" } |
| 132 |
int b [[fallthrough]] = 0) // { dg-error "'fallthrough' attribute ignored" } |
| 133 |
{ |
| 134 |
} |
| 135 |
enum [[fallthrough]] D { D0 }; // { dg-error "'fallthrough' attribute ignored" } |
| 136 |
enum class [[fallthrough]] E { E0 }; // { dg-error "'fallthrough' attribute ignored" } |
| 137 |
enum F {}; |
| 138 |
enum [[fallthrough]] F; // { dg-warning "type attributes ignored after type is already defined" } |
| 139 |
enum G { |
| 140 |
G0 [[fallthrough]], // { dg-error "'fallthrough' attribute ignored" } |
| 141 |
G1 [[fallthrough]] = 2 // { dg-error "'fallthrough' attribute ignored" } |
| 142 |
}; |
| 143 |
namespace [[fallthrough]] H { using H0 = int; } // { dg-warning "'fallthrough' attribute directive ignored" } */ |
| 144 |
namespace [[fallthrough]] {} // { dg-warning "'fallthrough' attribute directive ignored" } |
| 145 |
[[fallthrough]] using namespace H; // { dg-warning "'fallthrough' attribute directive ignored" } |
| 146 |
struct [[fallthrough]] I // { dg-error "'fallthrough' attribute ignored" } |
| 147 |
{ |
| 148 |
[[fallthrough]]; // { dg-error "declaration does not declare anything" } |
| 149 |
[[fallthrough]] int i; // { dg-error "'fallthrough' attribute ignored" } |
| 150 |
[[fallthrough]] int foo (); // { dg-error "'fallthrough' attribute ignored" } |
| 151 |
[[fallthrough]] int bar () { return 1; } // { dg-error "'fallthrough' attribute ignored" } |
| 152 |
[[fallthrough]] int : 0; // { dg-error "'fallthrough' attribute ignored" } |
| 153 |
[[fallthrough]] int i2 : 5; // { dg-error "'fallthrough' attribute ignored" } |
| 154 |
[[fallthrough]] static int i3; // { dg-error "'fallthrough' attribute ignored" } |
| 155 |
static int i4; |
| 156 |
}; |
| 157 |
[[fallthrough]] int I::i4 = 0; // { dg-error "'fallthrough' attribute ignored" } |
| 158 |
struct J : [[fallthrough]] C {}; // { dg-warning "attributes on base specifiers are ignored" } |
| 159 |
#if __cpp_concepts >= 201907L |
| 160 |
template <typename T> |
| 161 |
concept K [[fallthrough]] = requires { true; }; // { dg-error "'fallthrough' attribute ignored" "" { target c++20 } } |
| 162 |
#endif |
| 163 |
typedef int L [[fallthrough]]; // { dg-error "'fallthrough' attribute ignored" } |
| 164 |
template <typename T> |
| 165 |
struct M {}; |
| 166 |
template <> |
| 167 |
struct [[fallthrough]] M<int> { int m; }; // { dg-error "'fallthrough' attribute ignored" } |
| 168 |
typedef int N[2] [[fallthrough]]; // { dg-error "'fallthrough' attribute ignored" } |
| 169 |
typedef int O [[fallthrough]] [2]; // { dg-error "'fallthrough' attribute ignored" } |