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