1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
// RUN: %clang -cc1 -fsyntax-only -verify -std=c++2c -Wunused-parameter -Wunused -Wpre-c++26-compat %s
void static_var() {
static int _; // expected-note {{previous definition is here}} \
// expected-note {{candidate}}
static int _; // expected-error {{redefinition of '_'}}
int _; // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}} \
// expected-note {{candidate}}
_++; // expected-error{{reference to '_' is ambiguous}}
}
void static_var_2() {
int _; // expected-note {{previous definition is here}}
static int _; // expected-error {{redefinition of '_'}}
}
void bindings() {
int arr[4] = {0, 1, 2, 3};
auto [_, _, _, _] = arr; // expected-warning 3{{placeholder variables are incompatible with C++ standards before C++2c}} \
// expected-note 4{{placeholder declared here}}
_ == 42; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
{
// no extension warning as we only introduce a single placeholder.
auto [_, a, b, c] = arr; // expected-warning {{unused variable '[_, a, b, c]'}}
}
{
auto [_, _, b, c] = arr; // expected-warning {{unused variable '[_, _, b, c]'}} \
// expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}}
}
{
// There are only 3 extension warnings because the first
// introduction of `_` is valid in all C++ standards
auto [_, _, _, _] = arr; // expected-warning 3{{placeholder variables are incompatible with C++ standards before C++2c}}
}
}
namespace StaticBindings {
int arr[2] = {0, 1};
static auto [_, _] = arr; // expected-error {{redefinition of '_'}} \
// expected-note {{previous definition is here}}
void f() {
int arr[2] = {0, 1};
static auto [_, _] = arr; // expected-error {{redefinition of '_'}} \
// expected-note {{previous definition is here}}
}
}
void lambda() {
(void)[_ = 0, _ = 1] { // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}} \
// expected-note 2{{placeholder declared here}}
(void)_++; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
};
{
int _ = 12;
(void)[_ = 0]{ return _;}; // no warning (different scope)
}
auto GH107024 = [_ = 42]() { return _; }();
}
namespace global_var {
int _; // expected-note {{previous definition is here}}
int _; // expected-error {{redefinition of '_'}}
}
namespace {
int _; // expected-note {{previous definition is here}}
int _; // expected-error {{redefinition of '_'}}
}
namespace global_fun {
void _();
void _();
void _() {} // expected-note {{previous definition is here}}
void _() {} // expected-error {{redefinition of '_'}}
void _(int){}
}
typedef int _;
typedef int _; // Type redeclaration, nothing to do with placeholders
void extern_test() {
extern int _;
extern int _; // expected-note {{candidate}}
int _; //expected-note {{candidate}}
_++; // expected-error {{reference to '_' is ambiguous}}
}
struct Members {
int _; // expected-note 2{{placeholder declared here}}
int _; // expected-warning{{placeholder variables are incompatible with C++ standards before C++2c}} \
// expected-note 2{{placeholder declared here}}
void f() {
_++; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
}
void attributes() __attribute__((diagnose_if(_ != 0, "oh no!", "warning"))); // expected-error{{ambiguous reference to placeholder '_', which is defined multiple times}}
};
namespace using_ {
int _; // expected-note {{target of using declaration}}
void f() {
int _; // expected-note {{conflicting declaration}}
_ = 0;
using using_::_; // expected-error {{target of using declaration conflicts with declaration already in scope}}
}
}
void call(int);
void test_param(int _) {}
void test_params(int _, int _); // expected-error {{redefinition of parameter '_'}} \
// expected-note {{previous declaration is here}}
template <auto _, auto _> // expected-error {{declaration of '_' shadows template parameter}} \
// expected-note {{template parameter is declared here}}
auto i = 0;
template <typename T>
concept C = requires(T _, T _) { // expected-error {{redefinition of parameter '_'}} \
// expected-note {{previous declaration is here}}
T{};
};
struct S {
int a;
};
void f(S a, S _) { // expected-warning {{unused parameter 'a'}}
}
void unused_warning() {
int _ = 12; // placeholder variable, no unused-but-set warning
int x = 12; // expected-warning {{unused variable 'x'}}
int _ = 12; // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}}
}
struct ShadowMembers {
int _;
void f() {
int _;
_ = 12; // Ok, access the local variable
(void)({ int _ = 12; _;}); // Ok, inside a different scope
}
};
struct MemberPtrs {
int _, _; // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}} \
// expected-note 4{{placeholder declared here}}
};
constexpr int oh_no = __builtin_offsetof(MemberPtrs, _); // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
int MemberPtrs::* ref = &MemberPtrs::_; // expected-error{{ambiguous reference to placeholder '_', which is defined multiple times}}
struct MemberInitializer {
MemberInitializer() : _(0) {} // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
int _, _; // expected-note 2{{placeholder declared here}} \
// expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}}
};
struct MemberAndUnion {
int _; // expected-note {{placeholder declared here}}
union { int _; int _; }; // expected-note 2 {{placeholder declared here}} \
// expected-warning 2{{placeholder variables are incompatible with C++ standards before C++2c}}
MemberAndUnion() : _(0) {} // expected-error {{ambiguous reference to placeholder '_', which is defined multiple time}}
};
struct Union { union { int _, _, _; }; }; // expected-note 3{{placeholder declared here}} \
// expected-warning 2{{placeholder variables are incompatible with C++ standards before C++2c}}
void TestUnion() {
Union c;
c._ = 0; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
}
void AnonymousLocals() {
union {int _, _;}; // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}} \
// expected-note 2{{placeholder declared here}}
union {int _, _;}; // expected-warning 2{{placeholder variables are incompatible with C++ standards before C++2c}} \
// expected-note 2{{placeholder declared here}}
_. = 0; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
}
namespace StaticUnions {
static union { int _ = 42; }; // expected-note {{previous declaration is here}}
static union { int _ = 43; }; // expected-error {{member of anonymous union redeclares '_'}}
inline void StaticUnion() {
static union { int _{}; }; // expected-note {{previous declaration is here}}
static union { int _{}; }; // expected-error {{member of anonymous union redeclares '_'}}
}
}
namespace TagVariables {
[[maybe_unused]] struct {
int _, _, _; // expected-warning 2{{placeholder variables are incompatible with C++ standards before C++2c}}
} a;
[[maybe_unused]] union {
int _, _, _; // expected-warning 2{{placeholder variables are incompatible with C++ standards before C++2c}}
} b;
}
namespace MemberLookupTests {
struct S {
int _, _; // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}} \
// expected-note 8{{placeholder declared here}}
void f() {
_ ++ ; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
}
};
struct T : S {
};
void Test() {
S s{._ =0}; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
S{}._; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
T{}._; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
};
};
namespace Bases {
struct S {
int _, _; // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}} \
// expected-note 2{{placeholder declared here}}
int a;
};
struct T : S{
int _, _; // expected-warning {{placeholder variables are incompatible with C++ standards before C++2c}} \
// expected-note 2{{placeholder declared here}}
int a;
void f() {
_; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
S::_; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}} \
// expected-error {{a type specifier is required for all declarations}}
}
};
}
|