Debian Codegraph @

gcc/testsuite/g++.dg/cpp0x/attr-no_unique_address1.C

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