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