Debian Codegraph @

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