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