1 // RUN: %clang_cc1 -fsyntax-only -verify -ast-dump -std=c++2c -Wunused-parameter -Wunused -Wpre-c++26-compat %s | FileCheck %s
4 static int _
; // expected-note {{previous definition is here}} \
5 // expected-note {{candidate}}
6 static int _
; // expected-error {{redefinition of '_'}}
7 int _
; // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}} \
8 // expected-note {{candidate}}
9 _
++; // expected-error{{reference to '_' is ambiguous}}
13 int _
; // expected-note {{previous definition is here}}
14 static int _
; // expected-error {{redefinition of '_'}}
18 int arr
[4] = {0, 1, 2, 3};
19 auto [_
, _
, _
, _
] = arr
; // expected-warning 3{{placeholder variables are incompatible with C++ standards before C++2c}} \
20 // expected-note 4{{placeholder declared here}}
21 _
== 42; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
23 // no extension warning as we only introduce a single placeholder.
24 auto [_
, a
, b
, c
] = arr
; // expected-warning {{unused variable '[_, a, b, c]'}}
27 auto [_
, _
, b
, c
] = arr
; // expected-warning {{unused variable '[_, _, b, c]'}} \
28 // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}}
31 // There are only 3 extension warnings because the first
32 // introduction of `_` is valid in all C++ standards
33 auto [_
, _
, _
, _
] = arr
; // expected-warning 3{{placeholder variables are incompatible with C++ standards before C++2c}}
37 namespace StaticBindings
{
40 static auto [_
, _
] = arr
; // expected-error {{redefinition of '_'}} \
41 // expected-note {{previous definition is here}}
45 static auto [_
, _
] = arr
; // expected-error {{redefinition of '_'}} \
46 // expected-note {{previous definition is here}}
52 (void)[_
= 0, _
= 1] { // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}} \
53 // expected-note 2{{placeholder declared here}}
54 (void)_
++; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
59 (void)[_
= 0]{ return _
;}; // no warning (different scope)
62 auto GH107024
= [_
= 42]() { return _
; }();
65 namespace global_var
{
66 int _
; // expected-note {{previous definition is here}}
67 int _
; // expected-error {{redefinition of '_'}}
71 int _
; // expected-note {{previous definition is here}}
72 int _
; // expected-error {{redefinition of '_'}}
76 namespace global_fun
{
80 void _() {} // expected-note {{previous definition is here}}
81 void _() {} // expected-error {{redefinition of '_'}}
86 typedef int _
; // Type redeclaration, nothing to do with placeholders
90 extern int _
; // expected-note {{candidate}}
91 int _
; //expected-note {{candidate}}
92 _
++; // expected-error {{reference to '_' is ambiguous}}
97 int _
; // expected-note 2{{placeholder declared here}}
98 int _
; // expected-warning{{placeholder variables are incompatible with C++ standards before C++2c}} \
99 // expected-note 2{{placeholder declared here}}
101 _
++; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
103 void attributes() __attribute__((diagnose_if(_
!= 0, "oh no!", "warning"))); // expected-error{{ambiguous reference to placeholder '_', which is defined multiple times}}
107 int _
; // expected-note {{target of using declaration}}
109 int _
; // expected-note {{conflicting declaration}}
111 using using_::_
; // expected-error {{target of using declaration conflicts with declaration already in scope}}
117 void test_param(int _
) {}
118 void test_params(int _
, int _
); // expected-error {{redefinition of parameter '_'}} \
119 // expected-note {{previous declaration is here}}
121 template <auto _
, auto _
> // expected-error {{declaration of '_' shadows template parameter}} \
122 // expected-note {{template parameter is declared here}}
125 template <typename T
>
126 concept C
= requires(T _
, T _
) { // expected-error {{redefinition of parameter '_'}} \
127 // expected-note {{previous declaration is here}}
135 void f(S a
, S _
) { // expected-warning {{unused parameter 'a'}}
139 void unused_warning() {
140 int _
= 12; // placeholder variable, no unused-but-set warning
141 int x
= 12; // expected-warning {{unused variable 'x'}}
142 int _
= 12; // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}}
145 struct ShadowMembers
{
149 _
= 12; // Ok, access the local variable
150 (void)({ int _
= 12; _
;}); // Ok, inside a different scope
155 int _
, _
; // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}} \
156 // expected-note 4{{placeholder declared here}}
158 constexpr int oh_no
= __builtin_offsetof(MemberPtrs
, _
); // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
159 int MemberPtrs::* ref
= &MemberPtrs::_
; // expected-error{{ambiguous reference to placeholder '_', which is defined multiple times}}
162 struct MemberInitializer
{
163 MemberInitializer() : _(0) {} // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
164 int _
, _
; // expected-note 2{{placeholder declared here}} \
165 // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}}
168 struct MemberAndUnion
{
169 int _
; // expected-note {{placeholder declared here}}
170 union { int _
; int _
; }; // expected-note 2 {{placeholder declared here}} \
171 // expected-warning 2{{placeholder variables are incompatible with C++ standards before C++2c}}
174 MemberAndUnion() : _(0) {} // expected-error {{ambiguous reference to placeholder '_', which is defined multiple time}}
177 struct Union
{ union { int _
, _
, _
; }; }; // expected-note 3{{placeholder declared here}} \
178 // expected-warning 2{{placeholder variables are incompatible with C++ standards before C++2c}}
182 c
._
= 0; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
185 void AnonymousLocals() {
186 union {int _
, _
;}; // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}} \
187 // expected-note 2{{placeholder declared here}}
188 union {int _
, _
;}; // expected-warning 2{{placeholder variables are incompatible with C++ standards before C++2c}} \
189 // expected-note 2{{placeholder declared here}}
190 _
. = 0; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
193 namespace StaticUnions
{
195 static union { int _
= 42; }; // expected-note {{previous declaration is here}}
196 static union { int _
= 43; }; // expected-error {{member of anonymous union redeclares '_'}}
198 inline void StaticUnion() {
199 static union { int _
{}; }; // expected-note {{previous declaration is here}}
200 static union { int _
{}; }; // expected-error {{member of anonymous union redeclares '_'}}
205 namespace TagVariables
{
207 [[maybe_unused
]] struct {
208 int _
, _
, _
; // expected-warning 2{{placeholder variables are incompatible with C++ standards before C++2c}}
211 [[maybe_unused
]] union {
212 int _
, _
, _
; // expected-warning 2{{placeholder variables are incompatible with C++ standards before C++2c}}
217 namespace MemberLookupTests
{
220 int _
, _
; // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}} \
221 // expected-note 8{{placeholder declared here}}
224 _
++ ; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
233 S s
{._
=0}; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
234 S
{}._
; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
235 T
{}._
; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
242 int _
, _
; // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}} \
243 // expected-note 2{{placeholder declared here}}
247 int _
, _
; // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}} \
248 // expected-note 2{{placeholder declared here}}
251 _
; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
252 S::_
; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}} \
253 // expected-error {{a type specifier is required for all declarations}}
270 [[maybe_unused
]] A
<int> a
;
273 // CHECK: NamespaceDecl {{.*}} GH114069
274 // CHECK: ClassTemplateSpecializationDecl {{.*}} struct A definition
275 // CHECK: CXXConstructorDecl {{.*}} implicit used constexpr A 'void () noexcept'
276 // CHECK-NEXT: CXXCtorInitializer Field {{.*}} '_' 'int'
277 // CHECK-NEXT: CXXDefaultInitExpr {{.*}} 'int' has rewritten init
278 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1
279 // CHECK-NEXT: CXXCtorInitializer Field {{.*}} '_' 'int'
280 // CHECK-NEXT: CXXDefaultInitExpr {{.*}} 'int' has rewritten init
281 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 2
282 // CHECK-NEXT: CXXCtorInitializer Field {{.*}} 'a' 'int'
283 // CHECK-NEXT: CXXDefaultInitExpr {{.*}} 'int' has rewritten init
284 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 3
285 // CHECK-NEXT: CXXCtorInitializer Field {{.*}} '_' 'int'
286 // CHECK-NEXT: CXXDefaultInitExpr {{.*}} 'int' has rewritten init
287 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 4
288 // CHECK-NEXT: CompoundStmt {{.*}}