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