1 // RUN: %clang -cc1 -fsyntax-only -verify -std=c++2c -Wunused-parameter -Wunused -Wpre-c++26-compat %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 4{{placeholder declared here}}
54 (void)_
++; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
59 (void)[_
= 0]{}; // no warning (different scope)
63 namespace global_var
{
64 int _
; // expected-note {{previous definition is here}}
65 int _
; // expected-error {{redefinition of '_'}}
69 int _
; // expected-note {{previous definition is here}}
70 int _
; // expected-error {{redefinition of '_'}}
74 namespace global_fun
{
78 void _() {} // expected-note {{previous definition is here}}
79 void _() {} // expected-error {{redefinition of '_'}}
84 typedef int _
; // Type redeclaration, nothing to do with placeholders
88 extern int _
; // expected-note {{candidate}}
89 int _
; //expected-note {{candidate}}
90 _
++; // expected-error {{reference to '_' is ambiguous}}
95 int _
; // expected-note 2{{placeholder declared here}}
96 int _
; // expected-warning{{placeholder variables are incompatible with C++ standards before C++2c}} \
97 // expected-note 2{{placeholder declared here}}
99 _
++; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
101 void attributes() __attribute__((diagnose_if(_
!= 0, "oh no!", "warning"))); // expected-error{{ambiguous reference to placeholder '_', which is defined multiple times}}
105 int _
; // expected-note {{target of using declaration}}
107 int _
; // expected-note {{conflicting declaration}}
109 using using_::_
; // expected-error {{target of using declaration conflicts with declaration already in scope}}
115 void test_param(int _
) {}
116 void test_params(int _
, int _
); // expected-error {{redefinition of parameter '_'}} \
117 // expected-note {{previous declaration is here}}
119 template <auto _
, auto _
> // expected-error {{declaration of '_' shadows template parameter}} \
120 // expected-note {{template parameter is declared here}}
123 template <typename T
>
124 concept C
= requires(T _
, T _
) { // expected-error {{redefinition of parameter '_'}} \
125 // expected-note {{previous declaration is here}}
133 void f(S a
, S _
) { // expected-warning {{unused parameter 'a'}}
137 void unused_warning() {
138 int _
= 12; // placeholder variable, no unused-but-set warning
139 int x
= 12; // expected-warning {{unused variable 'x'}}
140 int _
= 12; // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}}
143 struct ShadowMembers
{
147 _
= 12; // Ok, access the local variable
148 (void)({ int _
= 12; _
;}); // Ok, inside a different scope
153 int _
, _
; // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}} \
154 // expected-note 4{{placeholder declared here}}
156 constexpr int oh_no
= __builtin_offsetof(MemberPtrs
, _
); // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
157 int MemberPtrs::* ref
= &MemberPtrs::_
; // expected-error{{ambiguous reference to placeholder '_', which is defined multiple times}}
160 struct MemberInitializer
{
161 MemberInitializer() : _(0) {} // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
162 int _
, _
; // expected-note 2{{placeholder declared here}} \
163 // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}}
166 struct MemberAndUnion
{
167 int _
; // expected-note {{placeholder declared here}}
168 union { int _
; int _
; }; // expected-note 2 {{placeholder declared here}} \
169 // expected-warning 2{{placeholder variables are incompatible with C++ standards before C++2c}}
172 MemberAndUnion() : _(0) {} // expected-error {{ambiguous reference to placeholder '_', which is defined multiple time}}
175 struct Union
{ union { int _
, _
, _
; }; }; // expected-note 3{{placeholder declared here}} \
176 // expected-warning 2{{placeholder variables are incompatible with C++ standards before C++2c}}
180 c
._
= 0; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
183 void AnonymousLocals() {
184 union {int _
, _
;}; // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}} \
185 // expected-note 2{{placeholder declared here}}
186 union {int _
, _
;}; // expected-warning 2{{placeholder variables are incompatible with C++ standards before C++2c}} \
187 // expected-note 2{{placeholder declared here}}
188 _
. = 0; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
191 namespace StaticUnions
{
193 static union { int _
= 42; }; // expected-note {{previous declaration is here}}
194 static union { int _
= 43; }; // expected-error {{member of anonymous union redeclares '_'}}
196 inline void StaticUnion() {
197 static union { int _
{}; }; // expected-note {{previous declaration is here}}
198 static union { int _
{}; }; // expected-error {{member of anonymous union redeclares '_'}}
203 namespace TagVariables
{
205 [[maybe_unused
]] struct {
206 int _
, _
, _
; // expected-warning 2{{placeholder variables are incompatible with C++ standards before C++2c}}
209 [[maybe_unused
]] union {
210 int _
, _
, _
; // expected-warning 2{{placeholder variables are incompatible with C++ standards before C++2c}}
215 namespace MemberLookupTests
{
218 int _
, _
; // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}} \
219 // expected-note 8{{placeholder declared here}}
222 _
++ ; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
231 S s
{._
=0}; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
232 S
{}._
; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
233 T
{}._
; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
240 int _
, _
; // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}} \
241 // expected-note 2{{placeholder declared here}}
245 int _
, _
; // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}} \
246 // expected-note 2{{placeholder declared here}}
249 _
; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
250 S::_
; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}} \
251 // expected-error {{a type specifier is required for all declarations}}