Debian Codegraph @

gcc/testsuite/g++.dg/cpp26/name-independent-decl2.C

raw
1 // P2169R4 - A nice placeholder with no name
2 // { dg-do compile { target c++11 } }
3 // { dg-options "" }
4
5 int a[3];
6
7 void
8 foo ()
9 {
10 {
11 extern int _ (int);
12 int _ = 2; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
13 extern long _ (long); // { dg-error "redeclared as different kind of entity" }
14 }
15 {
16 int _ = 3;
17 extern int _ (int); // { dg-error "redeclared as different kind of entity" }
18 }
19 {
20 int _ = 4;
21 static int _ = 5; // { dg-error "redeclaration of 'int _'" }
22 } // { dg-message "static variable is not name-independent" "" { target c++26 } .-1 }
23 {
24 int _ = 6;
25 int _ = 7; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
26 ++_; // { dg-error "reference to '_' is ambiguous" }
27 }
28 {
29 int _ = 8;
30 int _ = 9; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
31 int _ = 10; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
32 ++_; // { dg-error "reference to '_' is ambiguous" }
33 }
34 {
35 static int _ = 11;
36 static int _ = 12; // { dg-error "redeclaration of 'int _'" }
37 int _ = 13; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
38 } // { dg-message "static variable is not name-independent" "" { target c++26 } .-2 }
39 {
40 extern int _ (int);
41 extern long _ (long);
42 extern float _ (float);
43 int _ = 1; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
44 ++_; // { dg-error "reference to '_' is ambiguous" }
45 }
46 {
47 extern double _ (double);
48 extern short _ (short);
49 int _ = 1; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
50 ++_; // { dg-error "reference to '_' is ambiguous" }
51 int _ = 2; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
52 ++_; // { dg-error "reference to '_' is ambiguous" }
53 }
54 {
55 auto [i, _, _] = a; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
56 // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 }
57 ++_; // { dg-error "reference to '_' is ambiguous" }
58 }
59 {
60 auto [i, j, _] = a; // { dg-warning "structured bindings only available with" "" { target c++14_down } }
61 auto [k, _, l] = a; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
62 // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 }
63 ++_; // { dg-error "reference to '_' is ambiguous" }
64 }
65 {
66 static auto [i, _, _] = a; // { dg-error "redeclaration of 'auto _'" }
67 // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 }
68 // { dg-warning "structured binding declaration can be 'static' only in" "" { target c++17_down } .-2 }
69 } // { dg-message "static structured binding is not name-independent" "" { target c++26 } .-3 }
70 }
71
72 int
73 bar (int _ = 0)
74 {
75 int _ = 1; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
76 ++_; // { dg-error "reference to '_' is ambiguous" }
77 return 0;
78 }
79
80 void
81 baz ()
82 {
83 if (int _ = bar ())
84 {
85 int _ = 6; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
86 ++_; // { dg-error "reference to '_' is ambiguous" }
87 }
88 else
89 {
90 int _ = 7; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
91 ++_; // { dg-error "reference to '_' is ambiguous" }
92 }
93 while (int _ = bar ())
94 {
95 int _ = 8; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
96 ++_; // { dg-error "reference to '_' is ambiguous" }
97 }
98 for (int _ = bar (); _; ++_)
99 {
100 int _ = 9; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
101 ++_; // { dg-error "reference to '_' is ambiguous" }
102 }
103 }
104
105 namespace A
106 {
107 int _ = 1;
108 int _ = 1; // { dg-error "redefinition of 'int A::_'" }
109 } // { dg-message "variable at namespace scope is not name-independent" "" { target c++26 } .-1 }
110
111 namespace B
112 {
113 auto [_, _, _] = a; // { dg-error "redefinition of 'auto B::_'" }
114 // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 }
115 } // { dg-message "structured binding at namespace scope is not name-independent" "" { target c++26 } .-2 }
116
117 void
118 qux ()
119 {
120 auto c = [_ = 2, _ = 3] () { // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
121 // { dg-warning "lambda capture initializers only available with" "" { target c++11_down } .-1 }
122 (void) _; // { dg-error "reference to '_' is ambiguous" }
123 };
124 {
125 int _ = 4;
126 auto d = [_, _ = 5] () { // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
127 // { dg-warning "lambda capture initializers only available with" "" { target c++11_down } .-1 }
128 (void) _; // { dg-error "reference to '_' is ambiguous" }
129 };
130 }
131 auto e = [_ = 1] (int _) {}; // { dg-warning "lambda capture initializers only available with" "" { target c++11_down } }
132 } // { dg-error "lambda parameter '_' previously declared as a capture" "" { target *-*-* } .-1 }
133
134 void
135 corge (int _, int _) // { dg-error "redefinition of 'int _'" }
136 { // { dg-message "parameter declaration is not name-independent" "" { target c++26 } .-1 }
137 }
138
139 namespace C
140 {
141 typedef int _;
142 typedef int _;
143 }
144
145 namespace D
146 {
147 namespace {
148 int _;
149 int _; // { dg-error "redefinition of 'int D::.anonymous.::_'" }
150 } // { dg-message "variable at namespace scope is not name-independent" "" { target c++26 } .-1 }
151 }
152
153 namespace E
154 {
155 int _ (int);
156 int _ (int);
157 int _ (int) { return 0; }
158 int _ (int) { return 0; } // { dg-error "redefinition of 'int E::_\\\(int\\\)'" }
159 long _ (long) { return 1; }
160 }
161
162 template <int _, int _> // { dg-error "redefinition of 'int _'" }
163 void
164 garply ()
165 {
166 }
167
168 #if __cpp_concepts >= 202002L
169 template <typename T>
170 concept F = requires (T _, T _) { T{}; }; // { dg-error "redefinition of 'T _'" "" { target c++20 } }
171 #endif // { dg-message "parameter declaration is not name-independent" "" { target c++26 } .-1 }