1 // C++ 26 P2552R3 - On the ignorability of standard attributes
2 // { dg-do compile { target c++11 } }
5 struct S { int a, b; };
12 alignas ("foobar") int x2; // { dg-error "'alignas' argument has non-integral type 'const char \\\[7\\\]'" }
13 alignas (0) int x3; // { dg-warning "requested alignment '0' is not a positive power of 2" }
14 alignas ("foo", "bar", "baz") int x4; // { dg-error "'alignas' argument has non-integral type 'const char \\\[4\\\]'" }
15 // { dg-error "expected '\\\)' before ',' token" "" { target *-*-* } .-1 }
16 // { dg-error "expected declaration before ',' token" "" { target *-*-* } .-2 }
17 // { dg-error "expected primary-expression before ',' token" "" { target *-*-* } .-3 }
18 alignas (0, 1, 2) int x5; // { dg-error "expected '\\\)' before ',' token" }
19 // { dg-error "expected declaration before ',' token" "" { target *-*-* } .-1 }
20 // { dg-error "expected primary-expression before ',' token" "" { target *-*-* } .-2 }
22 auto a = [] alignas (int) () {}; // { dg-error "'alignas' on function declaration" }
23 auto b = [] constexpr alignas (int) {}; // { dg-error "'alignas' on a type other than class" }
24 // { dg-error "parameter declaration before lambda declaration specifiers only optional with" "" { target c++20_down } .-1 }
25 // { dg-error "'constexpr' lambda only available with" "" { target c++14_down } .-2 }
26 auto c = [] noexcept alignas (int) {}; // { dg-error "'alignas' on a type other than class" }
27 // { dg-error "parameter declaration before lambda exception specification only optional with" "" { target c++20_down } .-1 }
28 auto d = [] () alignas (int) {}; // { dg-error "'alignas' on a type other than class" }
29 auto e = new int [n] alignas (int); // { dg-warning "attributes ignored on outermost array type in new expression" }
30 auto e2 = new int [n] alignas (int) [42]; // { dg-warning "attributes ignored on outermost array type in new expression" }
31 auto f = new int [n][42] alignas (int); // { dg-error "'alignas' on a type other than class" }
32 alignas (int); // { dg-warning "attributes at the beginning of statement are ignored" }
33 alignas (int) {} // { dg-warning "attributes at the beginning of statement are ignored" }
34 alignas (int) if (true) {} // { dg-warning "attributes at the beginning of statement are ignored" }
35 alignas (int) while (false) {} // { dg-warning "attributes at the beginning of statement are ignored" }
36 alignas (int) goto lab; // { dg-warning "attributes at the beginning of statement are ignored" }
37 alignas (int) lab:; // { dg-error "alignment may not be specified for 'lab'" }
38 alignas (int) try {} catch (int) {} // { dg-warning "attributes at the beginning of statement are ignored" }
39 if (alignas (int) int x = 0) {}
42 alignas (int) case 1: // { dg-error "alignment may not be specified for" }
43 alignas (int) break; // { dg-warning "attributes at the beginning of statement are ignored" }
44 alignas (int) default: // { dg-error "alignment may not be specified for" }
47 for (alignas (int) auto a : arr) {}
48 for (alignas (int) auto [a, b] : arr2) {} // { dg-error "structured bindings only available with" "" { target c++14_down } }
49 alignas (int) asm (""); // { dg-warning "attributes ignored on 'asm' declaration" }
50 try {} catch (alignas (int) int x) {} // { dg-error "'alignas' on exception declaration" }
51 try {} catch (alignas (int) int) {} // { dg-error "'alignas' on exception declaration" }
52 try {} catch (int alignas (int) x) {} // { dg-warning "attribute ignored" }
53 try {} catch (int alignas (int)) {} // { dg-warning "attribute ignored" }
54 try {} catch (int x alignas (int)) {} // { dg-error "'alignas' on exception declaration" }
57 alignas (int) int bar (); // { dg-error "'alignas' on function declaration" }
58 using foobar alignas (int) = int; // { dg-error "'alignas' on a type alias" }
60 alignas (int) auto [b, c] = arr; // { dg-error "structured bindings only available with" "" { target c++14_down } }
61 alignas (int); // { dg-warning "attribute ignored" }
62 inline alignas (int) void baz () {} // { dg-warning "attribute ignored" }
63 // { dg-error "standard attributes in middle of decl-specifiers" "" { target *-*-* } .-1 }
64 constexpr alignas (int) int qux () { return 0; } // { dg-warning "attribute ignored" }
65 // { dg-error "standard attributes in middle of decl-specifiers" "" { target *-*-* } .-1 }
66 int alignas (int) d; // { dg-warning "attribute ignored" }
67 int const alignas (int) e = 1; // { dg-warning "attribute ignored" }
68 struct A {} alignas (int); // { dg-warning "attribute ignored in declaration of 'struct A'" }
69 struct A alignas (int); // { dg-warning "attribute ignored" }
70 struct A alignas (int) a1; // { dg-warning "attribute ignored" }
71 A alignas (int) a2; // { dg-warning "attribute ignored" }
72 enum B { B0 } alignas (int); // { dg-warning "attribute ignored in declaration of 'enum B'" }
73 enum B alignas (int); // { dg-warning "attribute ignored" }
74 enum B alignas (int) b1; // { dg-warning "attribute ignored" }
75 B alignas (int) b2; // { dg-warning "attribute ignored" }
76 struct alignas (int) C {};
78 struct alignas (int) Y;
79 int g[2] alignas (int); // { dg-error "'alignas' on a type other than class" }
80 int g2 alignas (int) [2];
81 int corge () alignas (int); // { dg-error "'alignas' on a type other than class" }
82 int *alignas (int) h; // { dg-error "'alignas' on a type other than class" }
83 int & alignas (int) i = f; // { dg-error "'alignas' on a type other than class" }
84 int && alignas (int) j = 0; // { dg-error "'alignas' on a type other than class" }
85 int S::* alignas (int) k; // { dg-error "'alignas' on a type other than class" }
86 auto l = sizeof (int [2] alignas (int)); // { dg-error "'alignas' on a type other than class" }
87 int freddy (alignas (int) int a, // { dg-error "alignment may not be specified for 'a'" }
88 alignas (int) int, // { dg-error "alignment may not be specified for '<anonymous>'" }
89 alignas (int) int c = 0, // { dg-error "alignment may not be specified for 'c'" }
90 alignas (int) int = 0); // { dg-error "alignment may not be specified for '<anonymous>'" }
92 corge (alignas (int) int a, // { dg-error "alignment may not be specified for 'a'" }
93 alignas (int) int, // { dg-error "alignment may not be specified for '<anonymous>'" }
94 alignas (int) int c = 0, // { dg-error "alignment may not be specified for 'c'" }
95 alignas (int) int = 0) // { dg-error "alignment may not be specified for '<anonymous>'" }
99 garply () // { dg-error "'alignas' on function declaration" }
102 int grault (int alignas (int) a, // { dg-warning "attribute ignored" }
103 int alignas (int), // { dg-warning "attribute ignored" }
104 int alignas (int) c = 0, // { dg-warning "attribute ignored" }
105 int alignas (int) = 0); // { dg-warning "attribute ignored" }
107 waldo (int alignas (int) a, // { dg-warning "attribute ignored" }
108 int alignas (int), // { dg-warning "attribute ignored" }
109 int alignas (int) c = 0, // { dg-warning "attribute ignored" }
110 int alignas (int) = 0) // { dg-warning "attribute ignored" }
113 int plugh (int a alignas (int), // { dg-error "alignment may not be specified for 'a'" }
114 int b alignas (int) = 0); // { dg-error "alignment may not be specified for 'b'" }
116 thud (int a alignas (int), // { dg-error "alignment may not be specified for 'a'" }
117 int b alignas (int) = 0) // { dg-error "alignment may not be specified for 'b'" }
120 enum alignas (int) D { D0 }; // { dg-error "'alignas' on enumerated type" }
121 enum class alignas (int) E { E0 }; // { dg-error "'alignas' on enumerated type" }
123 enum alignas (int) F; // { dg-warning "type attributes ignored after type is already defined" }
125 G0 alignas (int), // { dg-error "alignment may not be specified for 'G0'" }
126 G1 alignas (int) = 2 // { dg-error "alignment may not be specified for 'G1'" }
128 namespace alignas (int) H { using H0 = int; } // { dg-error "expected identifier before 'alignas'" }
129 // { dg-error "H' does not name a type" "" { target *-*-* } .-1 }
130 namespace alignas (int) {} // { dg-error "expected identifier before 'alignas'" }
131 // { dg-error "expected unqualified-id before '\\\{' token" "" { target *-*-* } .-1 }
132 alignas (int) using namespace H;
133 // { dg-error "'H' is not a namespace-name" "" { target *-*-* } .-1 }
134 struct alignas (int) I
136 alignas (int); // { dg-error "declaration does not declare anything" }
138 alignas (int) int foo (); // { dg-error "'alignas' on function declaration" }
139 alignas (int) int bar () { return 1; } // { dg-error "'alignas' on function declaration" }
140 alignas (int) int : 0; // { dg-error "'alignas' on bit-field" }
141 alignas (int) int i2 : 5; // { dg-error "'alignas' on bit-field" }
142 alignas (int) static int i3;
145 alignas (int) int I::i4 = 0;
146 struct J : alignas (int) C {}; // { dg-warning "attributes on base specifiers are ignored" }
147 #if __cpp_concepts >= 201907L
148 template <typename T>
149 concept K alignas (int) = requires { true; }; // { dg-error "alignment may not be specified for 'K'" "" { target c++20 } }
151 typedef int L alignas (int); // { dg-error "'alignas' on a type alias" }
152 template <typename T>
155 struct alignas (int) M<int> { int m; };
156 typedef int N[2] alignas (int); // { dg-error "'alignas' on a type other than class" }
157 typedef int O alignas (int) [2]; // { dg-error "'alignas' on a type alias" }