| 1 |
// RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98-23,cxx98-11,cxx98-14,cxx98-17,cxx98 -fexceptions -fcxx-exceptions -pedantic-errors |
| 2 |
// RUN: %clang_cc1 -std=c++11 %s -verify=expected,cxx98-23,cxx98-11,cxx98-14,cxx98-17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors |
| 3 |
// RUN: %clang_cc1 -std=c++14 %s -verify=expected,cxx98-23,cxx98-14,cxx98-17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors |
| 4 |
// RUN: %clang_cc1 -std=c++17 %s -verify=expected,cxx98-23,since-cxx17,cxx98-17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors |
| 5 |
// RUN: %clang_cc1 -std=c++20 %s -verify=expected,cxx98-23,since-cxx20,since-cxx17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors |
| 6 |
// RUN: %clang_cc1 -std=c++23 %s -verify=expected,cxx98-23,since-cxx23,since-cxx20,since-cxx17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors |
| 7 |
// RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx26,since-cxx23,since-cxx20,since-cxx17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors |
| 8 |
|
| 9 |
#if __cplusplus == 199711L |
| 10 |
#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__) |
| 11 |
// cxx98-error@-1 {{variadic macros are a C99 feature}} |
| 12 |
#endif |
| 13 |
|
| 14 |
// FIXME: This is included to avoid a diagnostic with no source location |
| 15 |
// pointing at the implicit operator new. We can't match such a diagnostic |
| 16 |
// with -verify. |
| 17 |
__extension__ typedef __SIZE_TYPE__ size_t; |
| 18 |
void *operator new(size_t); // #cwg5xx-global-operator-new |
| 19 |
// cxx98-error@-1 {{'operator new' is missing exception specification 'throw(std::bad_alloc)'}} |
| 20 |
#if __cplusplus > 201402L |
| 21 |
namespace std { |
| 22 |
enum class align_val_t : size_t {}; |
| 23 |
} |
| 24 |
void *operator new(size_t, std::align_val_t); // #cwg5xx-global-operator-new-aligned |
| 25 |
#endif |
| 26 |
|
| 27 |
namespace std { |
| 28 |
struct type_info; |
| 29 |
} |
| 30 |
|
| 31 |
namespace cwg500 { // cwg500: dup 372 |
| 32 |
class D; |
| 33 |
class A { |
| 34 |
class B; |
| 35 |
class C; |
| 36 |
friend class D; |
| 37 |
}; |
| 38 |
class A::B {}; |
| 39 |
class A::C : public A::B {}; |
| 40 |
class D : public A::B {}; |
| 41 |
} |
| 42 |
|
| 43 |
namespace cwg501 { // cwg501: yes |
| 44 |
struct A { |
| 45 |
friend void f() {} |
| 46 |
void g() { |
| 47 |
void (*p)() = &f; |
| 48 |
// expected-error@-1 {{use of undeclared identifier 'f'}} |
| 49 |
} |
| 50 |
}; |
| 51 |
} |
| 52 |
|
| 53 |
namespace cwg502 { // cwg502: yes |
| 54 |
struct Q {}; |
| 55 |
template<typename T> struct A { |
| 56 |
enum E { e = 1 }; |
| 57 |
void q1() { f(e); } |
| 58 |
void q2() { Q arr[sizeof(E)]; f(arr); } |
| 59 |
void q3() { Q arr[e]; f(arr); } |
| 60 |
void sanity() { Q arr[1]; f(arr); } |
| 61 |
// expected-error@-1 {{use of undeclared identifier 'f'}} |
| 62 |
}; |
| 63 |
int f(A<int>::E); |
| 64 |
template<int N> int f(Q (&)[N]); |
| 65 |
template struct A<int>; |
| 66 |
} |
| 67 |
|
| 68 |
namespace cwg505 { // cwg505: yes |
| 69 |
const char *exts = "\e\(\{\[\%"; |
| 70 |
// expected-error@-1 {{use of non-standard escape character '\e'}} |
| 71 |
// expected-error@-2 {{use of non-standard escape character '\('}} |
| 72 |
// expected-error@-3 {{use of non-standard escape character '\{'}} |
| 73 |
// expected-error@-4 {{use of non-standard escape character '\['}} |
| 74 |
// expected-error@-5 {{use of non-standard escape character '\%'}} |
| 75 |
const char *unknown = "\Q"; |
| 76 |
// expected-error@-1 {{unknown escape sequence '\Q'}} |
| 77 |
} |
| 78 |
|
| 79 |
namespace cwg506 { // cwg506: yes |
| 80 |
struct NonPod { ~NonPod(); }; |
| 81 |
void f(...); |
| 82 |
void g(NonPod np) { f(np); } |
| 83 |
// cxx98-error@-1 {{cannot pass object of non-POD type 'NonPod' through variadic function; call will abort at runtime}} |
| 84 |
// since-cxx11-error@-2 {{cannot pass object of non-trivial type 'NonPod' through variadic function; call will abort at runtime}} |
| 85 |
} |
| 86 |
|
| 87 |
// FIXME: Add tests here once CWG260 is resolved. |
| 88 |
// cwg507: dup 260 |
| 89 |
|
| 90 |
// cwg508: na |
| 91 |
// cwg509: na |
| 92 |
// cwg510: na |
| 93 |
|
| 94 |
namespace cwg512 { // cwg512: yes |
| 95 |
struct A { // #cwg512-A |
| 96 |
A(int); // #cwg512-A-ctor |
| 97 |
}; |
| 98 |
union U { A a; }; |
| 99 |
// cxx98-error@-1 {{union member 'a' has a non-trivial default constructor}} |
| 100 |
// cxx98-note@#cwg512-A {{because type 'cwg512::A' has no default constructor}} |
| 101 |
// cxx98-note@#cwg512-A-ctor {{implicit default constructor suppressed by user-declared constructor}} |
| 102 |
} |
| 103 |
|
| 104 |
// cwg513: na |
| 105 |
|
| 106 |
namespace cwg514 { // cwg514: yes |
| 107 |
namespace A { extern int x, y; } |
| 108 |
int A::x = y; |
| 109 |
} |
| 110 |
|
| 111 |
namespace cwg515 { // cwg515: sup 1017 |
| 112 |
// FIXME: cwg1017 reverses the wording of cwg515, but the current draft has |
| 113 |
// cwg515's wording, with a different fix for cwg1017. |
| 114 |
|
| 115 |
struct X { int n; }; |
| 116 |
template<typename T> struct Y : T { |
| 117 |
int f() { return X::n; } |
| 118 |
}; |
| 119 |
int k = Y<X>().f(); |
| 120 |
|
| 121 |
struct A { int a; }; |
| 122 |
struct B { void f() { int k = sizeof(A::a); } }; |
| 123 |
// cxx98-error@-1 {{invalid use of non-static data member 'a'}} |
| 124 |
} |
| 125 |
|
| 126 |
// cwg516: na |
| 127 |
|
| 128 |
namespace cwg517 { // cwg517: no |
| 129 |
// This is NDR, but we should diagnose it anyway. |
| 130 |
template<typename T> struct S {}; |
| 131 |
template<typename T> int v = 0; |
| 132 |
// cxx98-11-error@-1 {{variable templates are a C++14 extension}} |
| 133 |
|
| 134 |
template struct S<int*>; |
| 135 |
template int v<int*>; |
| 136 |
|
| 137 |
S<char&> s; |
| 138 |
int k = v<char&>; |
| 139 |
|
| 140 |
// FIXME: These are both ill-formed. |
| 141 |
template<typename T> struct S<T*> {}; |
| 142 |
template<typename T> int v<T*> = 0; |
| 143 |
|
| 144 |
// FIXME: These are both ill-formed. |
| 145 |
template<typename T> struct S<T&> {}; |
| 146 |
template<typename T> int v<T&> = 0; |
| 147 |
} |
| 148 |
|
| 149 |
namespace cwg518 { // cwg518: yes c++11 |
| 150 |
enum E { e, }; |
| 151 |
// cxx98-error@-1 {{commas at the end of enumerator lists are a C++11 extension}} |
| 152 |
} |
| 153 |
|
| 154 |
// cwg519 is in cwg519.cpp |
| 155 |
// cwg520: na |
| 156 |
|
| 157 |
// cwg521: no |
| 158 |
// FIXME: The wording here is broken. It's not reasonable to expect a |
| 159 |
// diagnostic here. Once the relevant DR gets a number, mark this as a dup. |
| 160 |
|
| 161 |
namespace cwg522 { // cwg522: yes |
| 162 |
struct S {}; |
| 163 |
template<typename T> void b1(volatile T &); |
| 164 |
template<typename T> void b2(volatile T * const *); |
| 165 |
template<typename T> void b2(volatile T * const S::*); |
| 166 |
template<typename T> void b2(volatile T * const S::* const *); |
| 167 |
template<typename T> void b2a(volatile T *S::* const *); // #cwg522-b2a |
| 168 |
|
| 169 |
template<typename T> struct Base {}; |
| 170 |
struct Derived : Base<int> {}; |
| 171 |
template<typename T> void b3(Base<T>); |
| 172 |
template<typename T> void b3(Base<T> *); |
| 173 |
|
| 174 |
void test(int n, const int cn, int **p, int *S::*pm) { |
| 175 |
int *a[3], *S::*am[3]; |
| 176 |
const Derived cd = Derived(); |
| 177 |
Derived d[3]; |
| 178 |
|
| 179 |
b1(n); |
| 180 |
b1(cn); |
| 181 |
b2(p); |
| 182 |
b2(pm); |
| 183 |
b2(a); |
| 184 |
b2(am); |
| 185 |
b2a(am); |
| 186 |
// expected-error@-1 {{no matching function for call to 'b2a'}} |
| 187 |
// expected-note@#cwg522-b2a {{candidate template ignored: deduced type 'volatile int *cwg522::S::*const *' of 1st parameter does not match adjusted type 'int *cwg522::S::**' of argument}} |
| 188 |
b3(d); |
| 189 |
b3(cd); |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
namespace cwg524 { // cwg524: yes |
| 194 |
template<typename T> void f(T a, T b) { operator+(a, b); } |
| 195 |
// expected-error@-1 {{call to function 'operator+' that is neither visible in the template definition nor found by argument-dependent lookup}} |
| 196 |
// expected-note@#cwg524-f-N-S {{in instantiation of function template specialization 'cwg524::f<cwg524::N::S>' requested here}} |
| 197 |
// expected-note@#cwg524-operator-plus {{'operator+' should be declared prior to the call site or in namespace 'cwg524::N'}} |
| 198 |
|
| 199 |
struct S {}; |
| 200 |
void operator+(S, S); |
| 201 |
template void f(S, S); |
| 202 |
|
| 203 |
namespace N { struct S {}; } |
| 204 |
void operator+(N::S, N::S); // #cwg524-operator-plus |
| 205 |
template void f(N::S, N::S); // #cwg524-f-N-S |
| 206 |
} |
| 207 |
|
| 208 |
namespace cwg525 { // cwg525: yes |
| 209 |
namespace before { |
| 210 |
// Note, the example was correct prior to the change; instantiation is |
| 211 |
// required for cases like this: |
| 212 |
template <class T> struct D { operator T*(); }; |
| 213 |
void g(D<double> ppp) { |
| 214 |
delete ppp; |
| 215 |
} |
| 216 |
} |
| 217 |
namespace after { |
| 218 |
template <class T> struct D { typename T::error e; }; |
| 219 |
// expected-error@-1 {{type 'double' cannot be used prior to '::' because it has no members}} |
| 220 |
// expected-note@#cwg525-ppp {{in instantiation of template class 'cwg525::after::D<double>' requested here}} |
| 221 |
void g(D<double> *ppp) { |
| 222 |
delete ppp; // #cwg525-ppp |
| 223 |
} |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
namespace cwg526 { // cwg526: yes |
| 228 |
template<int> struct S {}; |
| 229 |
template<int N> void f1(S<N> s); |
| 230 |
template<int N> void f2(S<(N)> s); // #cwg526-f2 |
| 231 |
template<int N> void f3(S<+N> s); // #cwg526-f3 |
| 232 |
template<int N> void g1(int (&)[N]); |
| 233 |
template<int N> void g2(int (&)[(N)]); // #cwg526-g2 |
| 234 |
template<int N> void g3(int (&)[+N]); // #cwg526-g3 |
| 235 |
|
| 236 |
void test(int (&a)[3], S<3> s) { |
| 237 |
f1(s); |
| 238 |
f2(s); |
| 239 |
// expected-error@-1 {{no matching function for call to 'f2'}} |
| 240 |
// expected-note@#cwg526-f2 {{candidate template ignored: couldn't infer template argument 'N'}} |
| 241 |
f3(s); |
| 242 |
// expected-error@-1 {{no matching function for call to 'f3'}} |
| 243 |
// expected-note@#cwg526-f3 {{candidate template ignored: couldn't infer template argument 'N'}} |
| 244 |
g1(a); |
| 245 |
g2(a); |
| 246 |
// expected-error@-1 {{no matching function for call to 'g2'}} |
| 247 |
// expected-note@#cwg526-g2 {{candidate template ignored: couldn't infer template argument 'N'}} |
| 248 |
g3(a); |
| 249 |
// expected-error@-1 {{no matching function for call to 'g3'}} |
| 250 |
// expected-note@#cwg526-g3 {{candidate template ignored: couldn't infer template argument 'N'}} |
| 251 |
} |
| 252 |
|
| 253 |
template<int N> struct X { |
| 254 |
typedef int type; |
| 255 |
X<N>::type v1; |
| 256 |
X<(N)>::type v2; |
| 257 |
// cxx98-17-error@-1 {{missing 'typename' prior to dependent type name X<(N)>::type; implicit 'typename' is a C++20 extension}} |
| 258 |
X<+N>::type v3; |
| 259 |
// cxx98-17-error@-1 {{missing 'typename' prior to dependent type name X<+N>::type; implicit 'typename' is a C++20 extension}} |
| 260 |
}; |
| 261 |
} |
| 262 |
|
| 263 |
namespace cwg527 { // cwg527: na |
| 264 |
// This DR is meaningless. It removes a required diagnostic from the case |
| 265 |
// where a not-externally-visible object is odr-used but not defined, which |
| 266 |
// requires a diagnostic for a different reason. |
| 267 |
extern struct { int x; } a; // FIXME: We should reject this, per cwg389. |
| 268 |
static struct { int x; } b; |
| 269 |
extern "C" struct { int x; } c; |
| 270 |
namespace { extern struct { int x; } d; } |
| 271 |
typedef struct { int x; } *P; |
| 272 |
struct E { static P e; }; // FIXME: We should reject this, per cwg389. |
| 273 |
namespace { struct F { static P f; }; } |
| 274 |
|
| 275 |
int ax = a.x, bx = b.x, cx = c.x, dx = d.x, ex = E::e->x, fx = F::f->x; |
| 276 |
} |
| 277 |
|
| 278 |
namespace cwg528 { // cwg528: 2.7 |
| 279 |
|
| 280 |
struct S; // #cwg528-S |
| 281 |
|
| 282 |
void f() { |
| 283 |
typeid(S); |
| 284 |
// expected-error@-1 {{'typeid' of incomplete type 'S'}} |
| 285 |
// expected-note@#cwg528-S {{forward declaration of 'cwg528::S'}} |
| 286 |
} |
| 287 |
|
| 288 |
} // namespace cwg528 |
| 289 |
|
| 290 |
namespace cwg530 { // cwg530: yes |
| 291 |
template<int*> struct S { enum { N = 1 }; }; |
| 292 |
template<void(*)()> struct T { enum { N = 1 }; }; |
| 293 |
int n; |
| 294 |
void f(); |
| 295 |
int a[S<&n>::N]; |
| 296 |
int b[T<&f>::N]; |
| 297 |
} |
| 298 |
|
| 299 |
namespace cwg531 { // cwg531: partial |
| 300 |
namespace good { |
| 301 |
template<typename T> struct A { |
| 302 |
void f(T) { T::error; } |
| 303 |
template<typename U> void g(T, U) { T::error; } |
| 304 |
struct B { typename T::error error; }; |
| 305 |
template<typename U> struct C { typename T::error error; }; |
| 306 |
static T n; |
| 307 |
}; |
| 308 |
template<typename T> T A<T>::n = T::error; |
| 309 |
|
| 310 |
template<> void A<int>::f(int) {} |
| 311 |
template<> template<typename U> void A<int>::g(int, U) {} |
| 312 |
template<> struct A<int>::B {}; |
| 313 |
template<> template<typename U> struct A<int>::C {}; |
| 314 |
template<> int A<int>::n = 0; |
| 315 |
|
| 316 |
void use(A<int> a) { |
| 317 |
a.f(a.n); |
| 318 |
a.g(0, 0); |
| 319 |
A<int>::B b; |
| 320 |
A<int>::C<int> c; |
| 321 |
} |
| 322 |
|
| 323 |
template<> struct A<char> { |
| 324 |
void f(char); |
| 325 |
template<typename U> void g(char, U); |
| 326 |
struct B; |
| 327 |
template<typename U> struct C; |
| 328 |
static char n; |
| 329 |
}; |
| 330 |
|
| 331 |
void A<char>::f(char) {} |
| 332 |
template<typename U> void A<char>::g(char, U) {} |
| 333 |
struct A<char>::B {}; |
| 334 |
template<typename U> struct A<char>::C {}; |
| 335 |
char A<char>::n = 0; |
| 336 |
} |
| 337 |
|
| 338 |
namespace bad { |
| 339 |
template<typename T> struct A { |
| 340 |
void f(T) { T::error; } |
| 341 |
template<typename U> void g(T, U) { T::error; } |
| 342 |
struct B { typename T::error error; }; |
| 343 |
template<typename U> struct C { typename T::error error; }; // #cwg531-C |
| 344 |
static T n; |
| 345 |
}; |
| 346 |
template<typename T> T A<T>::n = T::error; |
| 347 |
|
| 348 |
void A<int>::f(int) {} |
| 349 |
// expected-error@-1 {{template specialization requires 'template<>'}} |
| 350 |
template<typename U> void A<int>::g(int, U) {} |
| 351 |
// expected-error@-1 {{template parameter list matching the non-templated nested type 'cwg531::bad::A<int>' should be empty}} |
| 352 |
struct A<int>::B {}; |
| 353 |
// expected-error@-1 {{template specialization requires 'template<>'}} |
| 354 |
template<typename U> struct A<int>::C {}; |
| 355 |
// expected-error@-1 {{template parameter list matching the non-templated nested type 'cwg531::bad::A<int>' should be empty}} |
| 356 |
// expected-error@-2 {{redefinition of 'C' as different kind of symbol}} |
| 357 |
// expected-note@#cwg531-C {{previous definition is here}} |
| 358 |
int A<int>::n = 0; |
| 359 |
// expected-error@-1 {{template specialization requires 'template<>'}} |
| 360 |
|
| 361 |
template<> struct A<char> { // #cwg531-A-char |
| 362 |
void f(char); |
| 363 |
template<typename U> void g(char, U); |
| 364 |
struct B; // #cwg531-B |
| 365 |
template<typename U> struct C; |
| 366 |
static char n; |
| 367 |
}; |
| 368 |
|
| 369 |
template<> void A<char>::f(char) {} |
| 370 |
// expected-error@-1 {{no function template matches function template specialization 'f'}} |
| 371 |
template<> template<typename U> void A<char>::g(char, U) {} |
| 372 |
// expected-error@-1 {{extraneous template parameter list in template specialization}} |
| 373 |
// expected-note@#cwg531-A-char {{'template<>' header not required for explicitly-specialized class 'cwg531::bad::A<char>' declared here}} |
| 374 |
template<> struct A<char>::B {}; |
| 375 |
// expected-error@-1 {{extraneous 'template<>' in declaration of struct 'B'}} |
| 376 |
// expected-error@-2 {{specialization of member 'cwg531::bad::A<char>::B' does not specialize an instantiated member}} |
| 377 |
// expected-note@#cwg531-B {{attempt to specialize declaration here}} |
| 378 |
template<> template<typename U> struct A<char>::C {}; |
| 379 |
// expected-error@-1 {{extraneous template parameter list in template specialization}} |
| 380 |
// expected-note@#cwg531-A-char {{'template<>' header not required for explicitly-specialized class 'cwg531::bad::A<char>' declared here}} |
| 381 |
template<> char A<char>::n = 0; |
| 382 |
// expected-error@-1 {{extraneous 'template<>' in declaration of variable 'n'}} |
| 383 |
} |
| 384 |
|
| 385 |
namespace nested { |
| 386 |
template<typename T> struct A { |
| 387 |
template<typename U> struct B; |
| 388 |
}; |
| 389 |
template<> template<typename U> struct A<int>::B { |
| 390 |
void f(); |
| 391 |
void g(); |
| 392 |
template<typename V> void h(); |
| 393 |
template<typename V> void i(); |
| 394 |
}; |
| 395 |
template<> template<typename U> void A<int>::B<U>::f() {} |
| 396 |
template<typename U> void A<int>::B<U>::g() {} |
| 397 |
// expected-error@-1 {{template parameter list matching the non-templated nested type 'cwg531::nested::A<int>' should be empty ('template<>')}} |
| 398 |
|
| 399 |
template<> template<typename U> template<typename V> void A<int>::B<U>::h() {} |
| 400 |
template<typename U> template<typename V> void A<int>::B<U>::i() {} |
| 401 |
// expected-error@-1 {{template parameter list matching the non-templated nested type 'cwg531::nested::A<int>' should be empty ('template<>')}} |
| 402 |
|
| 403 |
#if __cplusplus <= 201703L |
| 404 |
// FIXME: All of those declarations shouldn't crash in C++20 mode. |
| 405 |
template<> template<> void A<int>::B<int>::f() {} |
| 406 |
template<> template<> template<typename V> void A<int>::B<int>::h() {} |
| 407 |
template<> template<> template<> void A<int>::B<int>::h<int>() {} |
| 408 |
|
| 409 |
template<> void A<int>::B<char>::f() {} |
| 410 |
// cxx98-17-error@-1 {{template specialization requires 'template<>'}} |
| 411 |
template<> template<typename V> void A<int>::B<char>::h() {} |
| 412 |
// cxx98-17-error@-1 {{template parameter list matching the non-templated nested type 'cwg531::nested::A<int>::B<char>' should be empty ('template<>')}} |
| 413 |
#endif |
| 414 |
} |
| 415 |
} |
| 416 |
|
| 417 |
// PR8130 |
| 418 |
namespace cwg532 { // cwg532: 3.5 |
| 419 |
struct A { }; |
| 420 |
|
| 421 |
template<class T> struct B { |
| 422 |
template<class R> int &operator*(R&); |
| 423 |
}; |
| 424 |
|
| 425 |
template<class T, class R> float &operator*(T&, R&); |
| 426 |
void test() { |
| 427 |
A a; |
| 428 |
B<A> b; |
| 429 |
int &ir = b * a; |
| 430 |
} |
| 431 |
} |
| 432 |
|
| 433 |
// cwg533: na |
| 434 |
|
| 435 |
namespace cwg534 { // cwg534: 2.9 |
| 436 |
struct S {}; |
| 437 |
template<typename T> void operator+(S, T); |
| 438 |
template<typename T> void operator+<T*>(S, T*) {} |
| 439 |
// expected-error@-1 {{function template partial specialization is not allowed}} |
| 440 |
} |
| 441 |
|
| 442 |
namespace cwg535 { // cwg535: yes |
| 443 |
class X { private: X(const X&); }; |
| 444 |
struct A { |
| 445 |
X x; |
| 446 |
template<typename T> A(T&); |
| 447 |
}; |
| 448 |
struct B : A { |
| 449 |
X y; |
| 450 |
B(volatile A&); |
| 451 |
}; |
| 452 |
|
| 453 |
extern A a1; |
| 454 |
A a2(a1); // ok, uses constructor template |
| 455 |
|
| 456 |
extern volatile B b1; |
| 457 |
B b2(b1); // ok, uses converting constructor |
| 458 |
|
| 459 |
void f() { throw a1; } |
| 460 |
|
| 461 |
#if __cplusplus >= 201103L |
| 462 |
struct C { |
| 463 |
constexpr C() : n(0) {} |
| 464 |
template<typename T> constexpr C(T&t) : n(t.n == 0 ? throw 0 : 0) {} |
| 465 |
int n; |
| 466 |
}; |
| 467 |
constexpr C c() { return C(); } |
| 468 |
// ok, copy is elided |
| 469 |
constexpr C x = c(); |
| 470 |
#endif |
| 471 |
} |
| 472 |
|
| 473 |
// cwg536: na |
| 474 |
// cwg537: na |
| 475 |
// cwg538: na |
| 476 |
|
| 477 |
// cwg539: yes |
| 478 |
const cwg539( |
| 479 |
// expected-error@-1 {{a type specifier is required for all declarations}} |
| 480 |
const a) { |
| 481 |
// expected-error@-1 {{unknown type name 'a'}} |
| 482 |
const b; |
| 483 |
// expected-error@-1 {{a type specifier is required for all declarations}} |
| 484 |
new const; |
| 485 |
// expected-error@-1 {{expected a type}} |
| 486 |
try {} catch (const n) {} |
| 487 |
// expected-error@-1 {{unknown type name 'n'}} |
| 488 |
try {} catch (const) {} |
| 489 |
// expected-error@-1 {{expected a type}} |
| 490 |
if (const n = 0) {} |
| 491 |
// expected-error@-1 {{a type specifier is required for all declarations}} |
| 492 |
switch (const n = 0) {} |
| 493 |
// expected-error@-1 {{a type specifier is required for all declarations}} |
| 494 |
while (const n = 0) {} |
| 495 |
// expected-error@-1 {{a type specifier is required for all declarations}} |
| 496 |
for (const n = 0; |
| 497 |
// expected-error@-1 {{a type specifier is required for all declarations}} |
| 498 |
const m = 0; ) {} |
| 499 |
// expected-error@-1 {{a type specifier is required for all declarations}} |
| 500 |
sizeof(const); |
| 501 |
// expected-error@-1 {{a type specifier is required for all declarations}} |
| 502 |
struct S { |
| 503 |
const n; |
| 504 |
// expected-error@-1 {{a type specifier is required for all declarations}} |
| 505 |
operator const(); |
| 506 |
// expected-error@-1 {{expected a type}} |
| 507 |
}; |
| 508 |
#if __cplusplus >= 201103L |
| 509 |
int arr[3]; |
| 510 |
// FIXME: The extra braces here are to avoid the parser getting too |
| 511 |
// badly confused when recovering here. We should fix this recovery. |
| 512 |
{ for (const n |
| 513 |
// since-cxx11-error@-1 {{unknown type name 'n'}} |
| 514 |
// since-cxx11-note@-2 {{}} |
| 515 |
: arr) ; {} } |
| 516 |
// since-cxx11-error@-1 +{{}} |
| 517 |
(void) [](const) {}; |
| 518 |
// since-cxx11-error@-1 {{a type specifier is required for all declarations}} |
| 519 |
(void) [](const n) {}; |
| 520 |
// since-cxx11-error@-1 {{unknown type name 'n'}} |
| 521 |
enum E : const {}; |
| 522 |
// since-cxx11-error@-1 {{expected a type}} |
| 523 |
using T = const; |
| 524 |
// since-cxx11-error@-1 {{expected a type}} |
| 525 |
auto f() -> const; |
| 526 |
// since-cxx11-error@-1 {{expected a type}} |
| 527 |
#endif |
| 528 |
} |
| 529 |
|
| 530 |
namespace cwg540 { // cwg540: yes |
| 531 |
typedef int &a; |
| 532 |
typedef const a &a; |
| 533 |
// expected-warning@-1 {{'const' qualifier on reference type 'a' (aka 'int &') has no effect}} |
| 534 |
typedef const int &b; |
| 535 |
typedef b &b; |
| 536 |
typedef const a &c; // #cwg540-typedef-a-c |
| 537 |
// expected-warning@-1 {{'const' qualifier on reference type 'a' (aka 'int &') has no effect}} |
| 538 |
typedef const b &c; // #cwg540-typedef-b-c |
| 539 |
// expected-error@#cwg540-typedef-b-c {{typedef redefinition with different types ('const int &' vs 'int &')}} |
| 540 |
// expected-note@#cwg540-typedef-a-c {{previous definition is here}} |
| 541 |
// expected-warning@#cwg540-typedef-b-c {{'const' qualifier on reference type 'b' (aka 'const int &') has no effect}} |
| 542 |
} |
| 543 |
|
| 544 |
namespace cwg541 { // cwg541: yes |
| 545 |
template<int> struct X { typedef int type; }; |
| 546 |
template<typename T> struct S { |
| 547 |
int f(T); |
| 548 |
|
| 549 |
int g(int); |
| 550 |
T g(bool); |
| 551 |
|
| 552 |
int h(); |
| 553 |
int h(T); |
| 554 |
|
| 555 |
void x() { |
| 556 |
// These are type-dependent expressions, even though we could |
| 557 |
// determine that all calls have type 'int'. |
| 558 |
X<sizeof(f(0))>::type a; |
| 559 |
// expected-error@-1 {{expected ';' after expression}} |
| 560 |
// expected-error@-2 {{use of undeclared identifier 'a'}} |
| 561 |
X<sizeof(g(0))>::type b; |
| 562 |
// expected-error@-1 {{expected ';' after expression}} |
| 563 |
// expected-error@-2 {{use of undeclared identifier 'b'}} |
| 564 |
X<sizeof(h(0))>::type b; |
| 565 |
// expected-error@-1 {{expected ';' after expression}} |
| 566 |
// expected-error@-2 {{use of undeclared identifier 'b'}} |
| 567 |
|
| 568 |
typename X<sizeof(f(0))>::type a; |
| 569 |
typename X<sizeof(h(0))>::type b; |
| 570 |
} |
| 571 |
}; |
| 572 |
} |
| 573 |
|
| 574 |
namespace cwg542 { // cwg542: yes |
| 575 |
#if __cplusplus >= 201103L |
| 576 |
// In C++20 A and B are no longer aggregates and thus the constructor is |
| 577 |
// called, which fails. |
| 578 |
struct A { A() = delete; int n; }; // #cwg542-A |
| 579 |
// ok, constructor not called |
| 580 |
A a[32] = {}; // #cwg542-a |
| 581 |
// since-cxx20-error@-1 {{call to deleted constructor of 'A'}} |
| 582 |
// since-cxx20-note@#cwg542-A {{'A' has been explicitly marked deleted here}} |
| 583 |
// since-cxx20-note@#cwg542-a {{in implicit initialization of array element 0 with omitted initializer}} |
| 584 |
|
| 585 |
struct B { |
| 586 |
int n; |
| 587 |
private: |
| 588 |
B() = default; // #cwg542-B-ctor |
| 589 |
}; |
| 590 |
B b[32] = {}; // ok, constructor not called |
| 591 |
// since-cxx20-error@-1 {{calling a private constructor of class 'cwg542::B'}} |
| 592 |
// since-cxx20-note@#cwg542-B-ctor {{declared private here}} |
| 593 |
#endif |
| 594 |
} |
| 595 |
|
| 596 |
namespace cwg543 { // cwg543: 3.0 |
| 597 |
// In C++98+CWG543, this is valid because value-initialization doesn't call a |
| 598 |
// trivial default constructor, so we never notice that defining the |
| 599 |
// constructor would be ill-formed. |
| 600 |
// |
| 601 |
// In C++11+CWG543, this is ill-formed, because the default constructor is |
| 602 |
// deleted, and value-initialization *does* call a deleted default |
| 603 |
// constructor, even if it is trivial. |
| 604 |
struct A { |
| 605 |
const int n; // #cwg543-A-n |
| 606 |
}; |
| 607 |
A a = A(); |
| 608 |
// since-cxx11-error@-1 {{call to implicitly-deleted default constructor of 'A'}} |
| 609 |
// since-cxx11-note@#cwg543-A-n {{default constructor of 'A' is implicitly deleted because field 'n' of const-qualified type 'const int' would not be initialized}} |
| 610 |
} |
| 611 |
|
| 612 |
namespace cwg544 { // cwg544: yes |
| 613 |
int *n; |
| 614 |
|
| 615 |
template<class T> struct A { int n; }; |
| 616 |
template<class T> struct B : A<T> { int get(); }; |
| 617 |
template<> int B<int>::get() { return n; } |
| 618 |
int k = B<int>().get(); |
| 619 |
} |
| 620 |
|
| 621 |
namespace cwg546 { // cwg546: yes |
| 622 |
template<typename T> struct A { void f(); }; |
| 623 |
template struct A<int>; |
| 624 |
template<typename T> void A<T>::f() { T::error; } |
| 625 |
} |
| 626 |
|
| 627 |
namespace cwg547 { // cwg547: 3.2 |
| 628 |
template<typename T> struct X; |
| 629 |
template<typename T> struct X<T() const> {}; |
| 630 |
template<typename T, typename C> X<T> f(T C::*) { return X<T>(); } |
| 631 |
|
| 632 |
struct S { void f() const; }; |
| 633 |
X<void() const> x = f(&S::f); |
| 634 |
} |
| 635 |
|
| 636 |
namespace cwg548 { // cwg548: dup 482 |
| 637 |
template<typename T> struct S {}; |
| 638 |
template<typename T> void f() {} |
| 639 |
template struct cwg548::S<int>; |
| 640 |
template void cwg548::f<int>(); |
| 641 |
} |
| 642 |
|
| 643 |
// cwg550: dup 393 |
| 644 |
|
| 645 |
namespace cwg551 { // cwg551: yes c++11 |
| 646 |
// FIXME: This obviously should apply in C++98 mode too. |
| 647 |
template<typename T> void f() {} |
| 648 |
template inline void f<int>(); |
| 649 |
// since-cxx11-error@-1 {{explicit instantiation cannot be 'inline'}} |
| 650 |
|
| 651 |
template<typename T> inline void g() {} |
| 652 |
template inline void g<int>(); |
| 653 |
// since-cxx11-error@-1 {{explicit instantiation cannot be 'inline'}} |
| 654 |
|
| 655 |
template<typename T> struct X { |
| 656 |
void f() {} |
| 657 |
}; |
| 658 |
template inline void X<int>::f(); |
| 659 |
// since-cxx11-error@-1 {{explicit instantiation cannot be 'inline'}} |
| 660 |
} |
| 661 |
|
| 662 |
namespace cwg552 { // cwg552: yes |
| 663 |
template<typename T, typename T::U> struct X {}; |
| 664 |
struct Y { typedef int U; }; |
| 665 |
X<Y, 0> x; |
| 666 |
} |
| 667 |
|
| 668 |
// cwg553: 2.7 |
| 669 |
struct cwg553_class { |
| 670 |
friend void *operator new(size_t, cwg553_class); |
| 671 |
}; |
| 672 |
namespace cwg553 { |
| 673 |
cwg553_class c; |
| 674 |
// Contrary to the apparent intention of the DR, operator new is not actually |
| 675 |
// looked up with a lookup mechanism that performs ADL; the standard says it |
| 676 |
// "is looked up in global scope", where it is not visible. |
| 677 |
void *p = new (c) int; |
| 678 |
// expected-error@-1 {{no matching function for call to 'operator new'}} |
| 679 |
// since-cxx17-note@#cwg5xx-global-operator-new-aligned {{candidate function not viable: no known conversion from 'cwg553_class' to 'std::align_val_t' for 2nd argument}} |
| 680 |
// expected-note@#cwg5xx-global-operator-new {{candidate function not viable: requires 1 argument, but 2 were provided}} |
| 681 |
|
| 682 |
struct namespace_scope { |
| 683 |
friend void *operator new(size_t, namespace_scope); |
| 684 |
// expected-error@-1 {{'operator new' cannot be declared inside a namespace}} |
| 685 |
}; |
| 686 |
} |
| 687 |
|
| 688 |
// cwg554: na |
| 689 |
|
| 690 |
namespace cwg555 { // cwg555: 2.8 |
| 691 |
typedef int I; |
| 692 |
typedef const int CI; |
| 693 |
typedef volatile int VI; |
| 694 |
void f(int *a, CI *b, VI *c) { |
| 695 |
a->~I(); |
| 696 |
a->~CI(); |
| 697 |
a->~VI(); |
| 698 |
a->I::~I(); |
| 699 |
a->CI::~CI(); |
| 700 |
a->VI::~VI(); |
| 701 |
|
| 702 |
a->CI::~VI(); // allowed by changes to [expr.id.prim.qual]/2 introduced in P1131R2 |
| 703 |
|
| 704 |
b->~I(); |
| 705 |
b->~CI(); |
| 706 |
b->~VI(); |
| 707 |
b->I::~I(); |
| 708 |
b->CI::~CI(); |
| 709 |
b->VI::~VI(); |
| 710 |
|
| 711 |
c->~I(); |
| 712 |
c->~CI(); |
| 713 |
c->~VI(); |
| 714 |
c->I::~I(); |
| 715 |
c->CI::~CI(); |
| 716 |
c->VI::~VI(); |
| 717 |
} |
| 718 |
|
| 719 |
void g(int &a, CI &b, VI &c) { |
| 720 |
a.~I(); |
| 721 |
a.~CI(); |
| 722 |
a.~VI(); |
| 723 |
a.I::~I(); |
| 724 |
a.CI::~CI(); |
| 725 |
a.VI::~VI(); |
| 726 |
|
| 727 |
a.CI::~VI(); // allowed by changes to [expr.id.prim.qual]/2 introduced in P1131R2 |
| 728 |
|
| 729 |
b.~I(); |
| 730 |
b.~CI(); |
| 731 |
b.~VI(); |
| 732 |
b.I::~I(); |
| 733 |
b.CI::~CI(); |
| 734 |
b.VI::~VI(); |
| 735 |
|
| 736 |
c.~I(); |
| 737 |
c.~CI(); |
| 738 |
c.~VI(); |
| 739 |
c.I::~I(); |
| 740 |
c.CI::~CI(); |
| 741 |
c.VI::~VI(); |
| 742 |
} |
| 743 |
} // namespace cwg555 |
| 744 |
|
| 745 |
// cwg556: na |
| 746 |
|
| 747 |
namespace cwg557 { // cwg557: 3.1 |
| 748 |
template<typename T> struct S { |
| 749 |
friend void f(S<T> *); |
| 750 |
friend void g(S<S<T> > *); |
| 751 |
}; |
| 752 |
void x(S<int> *p, S<S<int> > *q) { |
| 753 |
f(p); |
| 754 |
g(q); |
| 755 |
} |
| 756 |
} |
| 757 |
|
| 758 |
namespace cwg558 { // cwg558: 2.9 |
| 759 |
wchar_t a = L'\uD7FF'; |
| 760 |
wchar_t b = L'\xD7FF'; |
| 761 |
wchar_t c = L'\uD800'; |
| 762 |
// expected-error@-1 {{invalid universal character}} |
| 763 |
wchar_t d = L'\xD800'; |
| 764 |
wchar_t e = L'\uDFFF'; |
| 765 |
// expected-error@-1 {{invalid universal character}} |
| 766 |
wchar_t f = L'\xDFFF'; |
| 767 |
wchar_t g = L'\uE000'; |
| 768 |
wchar_t h = L'\xE000'; |
| 769 |
} |
| 770 |
|
| 771 |
template<typename> struct cwg559 { typedef int T; cwg559::T u; }; // cwg559: yes |
| 772 |
|
| 773 |
namespace cwg560 { // cwg560: 16 |
| 774 |
|
| 775 |
template <class T> |
| 776 |
struct Outer { |
| 777 |
struct Inner { |
| 778 |
Inner* self(); |
| 779 |
}; |
| 780 |
}; |
| 781 |
template <class T> |
| 782 |
Outer<T>::Inner* Outer<T>::Inner::self() { return this; } |
| 783 |
// cxx98-17-error@-1 {{missing 'typename' prior to dependent type name Outer<T>::Inner; implicit 'typename' is a C++20 extension}} |
| 784 |
|
| 785 |
} // namespace cwg560 |
| 786 |
|
| 787 |
namespace cwg561 { // cwg561: yes |
| 788 |
template<typename T> void f(int); |
| 789 |
template<typename T> void g(T t) { |
| 790 |
f<T>(t); |
| 791 |
} |
| 792 |
namespace { |
| 793 |
struct S {}; |
| 794 |
template<typename T> static void f(S); |
| 795 |
} |
| 796 |
void h(S s) { |
| 797 |
g(s); |
| 798 |
} |
| 799 |
} |
| 800 |
|
| 801 |
// cwg562: na |
| 802 |
|
| 803 |
namespace cwg564 { // cwg564: yes |
| 804 |
extern "C++" void f(int); |
| 805 |
void f(int); // ok |
| 806 |
extern "C++" { extern int n; } |
| 807 |
int n; // ok |
| 808 |
} |
| 809 |
|
| 810 |
namespace cwg565 { // cwg565: yes |
| 811 |
namespace N { |
| 812 |
template<typename T> int f(T); // #cwg565-f |
| 813 |
} |
| 814 |
using N::f; // #cwg565-using |
| 815 |
template<typename T> int f(T*); |
| 816 |
template<typename T> void f(T); |
| 817 |
template<typename T, int = 0> int f(T); |
| 818 |
// cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}} |
| 819 |
template<typename T> int f(T, int = 0); |
| 820 |
template<typename T> int f(T); |
| 821 |
// expected-error@-1 {{declaration conflicts with target of using declaration already in scope}} |
| 822 |
// expected-note@#cwg565-f {{target of using declaration}} |
| 823 |
// expected-note@#cwg565-using {{using declaration}} |
| 824 |
} |
| 825 |
|
| 826 |
namespace cwg566 { // cwg566: yes |
| 827 |
#if __cplusplus >= 201103L |
| 828 |
static_assert(int(-3.99) == -3, ""); |
| 829 |
#endif |
| 830 |
} |
| 831 |
|
| 832 |
// cwg567: na |
| 833 |
|
| 834 |
namespace cwg568 { // cwg568: 3.0 c++11 |
| 835 |
// FIXME: This is a DR issue against C++98, so should probably apply there |
| 836 |
// too. |
| 837 |
struct x { int y; }; |
| 838 |
class trivial : x { |
| 839 |
x y; |
| 840 |
public: |
| 841 |
int n; |
| 842 |
}; |
| 843 |
static_assert(__is_trivial(trivial), ""); |
| 844 |
|
| 845 |
struct std_layout { |
| 846 |
std_layout(); |
| 847 |
std_layout(const std_layout &); |
| 848 |
~std_layout(); |
| 849 |
private: |
| 850 |
int n; |
| 851 |
}; |
| 852 |
static_assert(__is_standard_layout(std_layout), ""); |
| 853 |
|
| 854 |
struct aggregate { |
| 855 |
int x; |
| 856 |
int y; |
| 857 |
trivial t; |
| 858 |
std_layout sl; |
| 859 |
}; |
| 860 |
aggregate aggr = {}; |
| 861 |
|
| 862 |
void f(...); |
| 863 |
void g(trivial t) { f(t); } |
| 864 |
// cxx98-error@-1 {{cannot pass object of non-POD type 'trivial' through variadic function; call will abort at runtime}} |
| 865 |
|
| 866 |
void jump() { |
| 867 |
goto x; |
| 868 |
// cxx98-error@-1 {{cannot jump from this goto statement to its label}} |
| 869 |
// cxx98-note@#cwg568-t {{jump bypasses initialization of non-POD variable}} |
| 870 |
trivial t; // #cwg568-t |
| 871 |
x: ; |
| 872 |
} |
| 873 |
} |
| 874 |
|
| 875 |
namespace cwg569 { // cwg569: yes c++11 |
| 876 |
// FIXME: This is a DR issue against C++98, so should probably apply there |
| 877 |
// too. |
| 878 |
;;;;; |
| 879 |
// cxx98-error@-1 {{C++11 extension}} |
| 880 |
} |
| 881 |
|
| 882 |
namespace cwg570 { // cwg570: dup 633 |
| 883 |
int n; |
| 884 |
int &r = n; // #cwg570-r |
| 885 |
int &r = n; |
| 886 |
// expected-error@-1 {{redefinition of 'r'}} |
| 887 |
// expected-note@#cwg570-r {{previous definition is here}} |
| 888 |
} |
| 889 |
|
| 890 |
// cwg571 is in cwg571.cpp |
| 891 |
|
| 892 |
namespace cwg572 { // cwg572: yes |
| 893 |
enum E { a = 1, b = 2 }; |
| 894 |
static_assert(a + b == 3, ""); |
| 895 |
} |
| 896 |
|
| 897 |
namespace cwg573 { // cwg573: no |
| 898 |
void *a; |
| 899 |
int *b = reinterpret_cast<int*>(a); |
| 900 |
void (*c)() = reinterpret_cast<void(*)()>(a); |
| 901 |
// cxx98-error@-1 {{cast between pointer-to-function and pointer-to-object is an extension}} |
| 902 |
void *d = reinterpret_cast<void*>(c); |
| 903 |
// cxx98-error@-1 {{cast between pointer-to-function and pointer-to-object is an extension}} |
| 904 |
void f() { delete a; } |
| 905 |
// cxx98-23-error@-1 {{cannot delete expression with pointer-to-'void' type 'void *'}} |
| 906 |
// since-cxx26-error@-2 {{cannot delete pointer to incomplete type 'void'}} |
| 907 |
int n = d - a; |
| 908 |
// expected-error@-1 {{arithmetic on pointers to void}} |
| 909 |
// FIXME: This is ill-formed. |
| 910 |
template<void*> struct S; |
| 911 |
template<int*> struct T; |
| 912 |
} |
| 913 |
|
| 914 |
namespace cwg574 { // cwg574: 3.0 |
| 915 |
struct A { |
| 916 |
A &operator=(const A&) const; // #cwg574-A-copy-assign |
| 917 |
}; |
| 918 |
struct B { |
| 919 |
B &operator=(const B&) volatile; // #cwg574-B-copy-assign |
| 920 |
}; |
| 921 |
#if __cplusplus >= 201103L |
| 922 |
struct C { |
| 923 |
C &operator=(const C&) &; // #cwg574-C-copy-assign |
| 924 |
}; |
| 925 |
struct D { |
| 926 |
D &operator=(const D&) &&; // #cwg574-D-copy-assign |
| 927 |
}; |
| 928 |
void test(C c, D d) { |
| 929 |
c = c; |
| 930 |
C() = c; |
| 931 |
// since-cxx11-error@-1 {{no viable overloaded '='}} |
| 932 |
// since-cxx11-note@#cwg574-C-copy-assign {{candidate function not viable: expects an lvalue for object argument}} |
| 933 |
d = d; |
| 934 |
// since-cxx11-error@-1 {{no viable overloaded '='}} |
| 935 |
// since-cxx11-note@#cwg574-D-copy-assign {{candidate function not viable: expects an rvalue for object argument}} |
| 936 |
D() = d; |
| 937 |
} |
| 938 |
#endif |
| 939 |
struct Test { |
| 940 |
friend A &A::operator=(const A&); |
| 941 |
// expected-error@-1 {{friend declaration of 'operator=' does not match any declaration in 'cwg574::A'}} |
| 942 |
// expected-note@#cwg574-A-copy-assign {{candidate function has different qualifiers (expected unqualified but found 'const')}} |
| 943 |
friend B &B::operator=(const B&); |
| 944 |
// expected-error@-1 {{friend declaration of 'operator=' does not match any declaration in 'cwg574::B'}} |
| 945 |
// expected-note@#cwg574-B-copy-assign {{candidate function has different qualifiers (expected unqualified but found 'volatile')}} |
| 946 |
#if __cplusplus >= 202302L |
| 947 |
friend C &C::operator=(const C&); |
| 948 |
// since-cxx23-error@-1 {{conflicting types for 'operator='}} |
| 949 |
// since-cxx23-note@#cwg574-C-copy-assign {{previous declaration is here}} |
| 950 |
friend D &D::operator=(const D&); |
| 951 |
// since-cxx23-error@-1 {{conflicting types for 'operator='}} |
| 952 |
// since-cxx23-note@#cwg574-D-copy-assign {{previous declaration is here}} |
| 953 |
#elif __cplusplus >= 201103L |
| 954 |
// FIXME: We shouldn't produce the 'cannot overload' diagnostics here. |
| 955 |
friend C &C::operator=(const C&); // #cwg574-test-C |
| 956 |
// since-cxx11-error@#cwg574-test-C {{cannot overload}} |
| 957 |
// since-cxx11-note@#cwg574-C-copy-assign {{previous declaration is here}} |
| 958 |
// since-cxx11-error@#cwg574-test-C {{friend declaration of 'operator=' does not match any declaration in 'cwg574::C'}} |
| 959 |
// since-cxx11-note@#cwg574-C-copy-assign {{candidate function}} |
| 960 |
friend D &D::operator=(const D&); // #cwg574-test-D |
| 961 |
// since-cxx11-error@#cwg574-test-D {{cannot overload a member function without a ref-qualifier with a member function with ref-qualifier '&&'}} |
| 962 |
// since-cxx11-note@#cwg574-D-copy-assign {{previous declaration is here}} |
| 963 |
// since-cxx11-error@#cwg574-test-D {{friend declaration of 'operator=' does not match any declaration in 'cwg574::D'}} |
| 964 |
// since-cxx11-note@#cwg574-D-copy-assign {{candidate function}} |
| 965 |
#endif |
| 966 |
}; |
| 967 |
} |
| 968 |
|
| 969 |
namespace cwg575 { // cwg575: yes |
| 970 |
template<typename T, typename U = typename T::type> void a(T); void a(...); |
| 971 |
// cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}} |
| 972 |
template<typename T, typename T::type U = 0> void b(T); void b(...); |
| 973 |
// cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}} |
| 974 |
template<typename T, int U = T::value> void c(T); void c(...); |
| 975 |
// cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}} |
| 976 |
template<typename T> void d(T, int = T::value); void d(...); |
| 977 |
// expected-error@-1 {{type 'int' cannot be used prior to '::' because it has no members}} |
| 978 |
// expected-note@#cwg575-d {{in instantiation of default function argument expression for 'd<int>' required here}} |
| 979 |
void x() { |
| 980 |
a(0); |
| 981 |
b(0); |
| 982 |
c(0); |
| 983 |
d(0); // #cwg575-d |
| 984 |
} |
| 985 |
|
| 986 |
template<typename T = int&> void f(T* = 0); |
| 987 |
// cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}} |
| 988 |
template<typename T = int> void f(T = 0); |
| 989 |
// cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}} |
| 990 |
void g() { f<>(); } |
| 991 |
|
| 992 |
template<typename T> T &h(T *); |
| 993 |
template<typename T> T *h(T *); |
| 994 |
void *p = h((void*)0); |
| 995 |
} |
| 996 |
|
| 997 |
namespace cwg576 { // cwg576: 3.5 |
| 998 |
typedef void f() {} |
| 999 |
// expected-error@-1 {{function definition declared 'typedef'}} |
| 1000 |
void f(typedef int n); |
| 1001 |
// expected-error@-1 {{invalid storage class specifier in function declarator}} |
| 1002 |
void f(char c) { typedef int n; } |
| 1003 |
} |
| 1004 |
|
| 1005 |
namespace cwg577 { // cwg577: 3.5 |
| 1006 |
typedef void V; |
| 1007 |
typedef const void CV; |
| 1008 |
void a(void); |
| 1009 |
void b(const void); |
| 1010 |
// expected-error@-1 {{'void' as parameter must not have type qualifiers}} |
| 1011 |
void c(V); |
| 1012 |
void d(CV); |
| 1013 |
// expected-error@-1 {{'void' as parameter must not have type qualifiers}} |
| 1014 |
void (*e)(void) = c; |
| 1015 |
void (*f)(const void); |
| 1016 |
// expected-error@-1 {{'void' as parameter must not have type qualifiers}} |
| 1017 |
void (*g)(V) = a; |
| 1018 |
void (*h)(CV); |
| 1019 |
// expected-error@-1 {{'void' as parameter must not have type qualifiers}} |
| 1020 |
template<typename T> void i(T); // #cwg577-i |
| 1021 |
template<typename T> void j(void (*)(T)); // #cwg577-j |
| 1022 |
void k() { |
| 1023 |
a(); |
| 1024 |
c(); |
| 1025 |
i<void>(); |
| 1026 |
// expected-error@-1 {{no matching function for call to 'i'}} |
| 1027 |
// expected-note@#cwg577-i {{candidate function template not viable: requires 1 argument, but 0 were provided}} |
| 1028 |
i<const void>(); |
| 1029 |
// expected-error@-1 {{no matching function for call to 'i'}} |
| 1030 |
// expected-note@#cwg577-i {{candidate function template not viable: requires 1 argument, but 0 were provided}} |
| 1031 |
j<void>(0); |
| 1032 |
// expected-error@-1 {{no matching function for call to 'j'}} |
| 1033 |
// expected-note@#cwg577-j {{candidate template ignored: substitution failure [with T = void]: argument may not have 'void' type}} |
| 1034 |
j<const void>(0); |
| 1035 |
// expected-error@-1 {{no matching function for call to 'j'}} |
| 1036 |
// expected-note@#cwg577-j {{candidate template ignored: substitution failure [with T = const void]: argument may not have 'void' type}} |
| 1037 |
} |
| 1038 |
} |
| 1039 |
|
| 1040 |
namespace cwg580 { // cwg580: partial |
| 1041 |
class C; |
| 1042 |
struct A { static C c; }; |
| 1043 |
struct B { static C c; }; |
| 1044 |
class C { |
| 1045 |
C(); // #cwg580-C-ctor |
| 1046 |
~C(); // #cwg580-C-dtor |
| 1047 |
|
| 1048 |
typedef int I; // #cwg580-I |
| 1049 |
template<int> struct X; |
| 1050 |
template<int> friend struct Y; |
| 1051 |
template<int> void f(); |
| 1052 |
template<int> friend void g(); |
| 1053 |
friend struct A; |
| 1054 |
}; |
| 1055 |
|
| 1056 |
template<C::I> struct C::X {}; |
| 1057 |
template<C::I> struct Y {}; |
| 1058 |
template<C::I> struct Z {}; |
| 1059 |
// expected-error@-1 {{'I' is a private member of 'cwg580::C'}} |
| 1060 |
// expected-note@#cwg580-I {{implicitly declared private here}} |
| 1061 |
|
| 1062 |
struct C2 { |
| 1063 |
class X { |
| 1064 |
struct A; |
| 1065 |
typedef int I; |
| 1066 |
friend struct A; |
| 1067 |
}; |
| 1068 |
class Y { |
| 1069 |
// FIXME: We incorrectly accept this |
| 1070 |
// because we think C2::Y::A<...> might |
| 1071 |
// instantiate to C2::X::A |
| 1072 |
template<X::I> struct A {}; |
| 1073 |
}; |
| 1074 |
}; |
| 1075 |
|
| 1076 |
template<C::I> void C::f() {} |
| 1077 |
template<C::I> void g() {} |
| 1078 |
template<C::I> void h() {} |
| 1079 |
// expected-error@-1 {{'I' is a private member of 'cwg580::C'}} |
| 1080 |
// expected-note@#cwg580-I {{implicitly declared private here}} |
| 1081 |
|
| 1082 |
C A::c; |
| 1083 |
C B::c; // #cwg580-c |
| 1084 |
// expected-error@#cwg580-c {{calling a private constructor of class 'cwg580::C'}} |
| 1085 |
// expected-note@#cwg580-C-ctor {{implicitly declared private here}} |
| 1086 |
// expected-error@#cwg580-c {{variable of type 'C' has private destructor}} |
| 1087 |
// expected-note@#cwg580-C-dtor {{implicitly declared private here}} |
| 1088 |
} |
| 1089 |
|
| 1090 |
// cwg582: na |
| 1091 |
|
| 1092 |
namespace cwg583 { // cwg583: 4 |
| 1093 |
// see n3624 |
| 1094 |
int *p; |
| 1095 |
bool b1 = p < 0; |
| 1096 |
// expected-error@-1 {{ordered comparison between pointer and zero ('int *' and 'int')}} |
| 1097 |
bool b2 = p > 0; |
| 1098 |
// expected-error@-1 {{ordered comparison between pointer and zero ('int *' and 'int')}} |
| 1099 |
bool b3 = p <= 0; |
| 1100 |
// expected-error@-1 {{ordered comparison between pointer and zero ('int *' and 'int')}} |
| 1101 |
bool b4 = p >= 0; |
| 1102 |
// expected-error@-1 {{ordered comparison between pointer and zero ('int *' and 'int')}} |
| 1103 |
} |
| 1104 |
|
| 1105 |
// cwg584: na |
| 1106 |
|
| 1107 |
namespace cwg585 { // cwg585: 3.0 |
| 1108 |
template<typename> struct T; // #cwg585-struct-T |
| 1109 |
struct A { |
| 1110 |
friend T; |
| 1111 |
// cxx98-14-error@-1 {{a type specifier is required for all declarations}} |
| 1112 |
// cxx98-14-error@-2 {{friends can only be classes or functions}} |
| 1113 |
// since-cxx17-error@-3 {{use of class template 'T' requires template arguments; argument deduction not allowed in friend declaration}} |
| 1114 |
// since-cxx17-note@#cwg585-struct-T {{template is declared here}} |
| 1115 |
// FIXME: It's not clear whether the standard allows this or what it means, |
| 1116 |
// but the CWG585 writeup suggests it as an alternative. |
| 1117 |
template<typename U> friend T<U>; |
| 1118 |
// expected-error@-1 {{friend type templates must use an elaborated type}} |
| 1119 |
}; |
| 1120 |
template<template<typename> class T> struct B { // #cwg585-template-T |
| 1121 |
friend T; |
| 1122 |
// cxx98-14-error@-1 {{a type specifier is required for all declarations}} |
| 1123 |
// cxx98-14-error@-2 {{friends can only be classes or functions}} |
| 1124 |
// since-cxx17-error@-3 {{use of template template parameter 'T' requires template arguments; argument deduction not allowed in friend declaration}} |
| 1125 |
// since-cxx17-note@#cwg585-template-T {{template is declared here}} |
| 1126 |
template<typename U> friend T<U>; |
| 1127 |
// expected-error@-1 {{friend type templates must use an elaborated type}} |
| 1128 |
}; |
| 1129 |
} |
| 1130 |
|
| 1131 |
// cwg586: na |
| 1132 |
|
| 1133 |
namespace cwg587 { // cwg587: 3.2 |
| 1134 |
template<typename T> void f(bool b, const T x, T y) { |
| 1135 |
const T *p = &(b ? x : y); |
| 1136 |
} |
| 1137 |
struct S {}; |
| 1138 |
template void f(bool, const int, int); |
| 1139 |
template void f(bool, const S, S); |
| 1140 |
} |
| 1141 |
|
| 1142 |
namespace cwg588 { // cwg588: yes |
| 1143 |
struct A { int n; }; // #cwg588-A |
| 1144 |
template<typename T> int f() { |
| 1145 |
struct S : A, T { int f() { return n; } } s; |
| 1146 |
int a = s.f(); |
| 1147 |
int b = s.n; |
| 1148 |
// expected-error@-1 {{member 'n' found in multiple base classes of different types}} |
| 1149 |
// expected-note@#cwg588-k {{in instantiation of function template specialization 'cwg588::f<cwg588::B>' requested here}} |
| 1150 |
// expected-note@#cwg588-A {{member found by ambiguous name lookup}} |
| 1151 |
// expected-note@#cwg588-B {{member found by ambiguous name lookup}} |
| 1152 |
} |
| 1153 |
struct B { int n; }; // #cwg588-B |
| 1154 |
int k = f<B>(); // #cwg588-k |
| 1155 |
} |
| 1156 |
|
| 1157 |
namespace cwg589 { // cwg589: yes |
| 1158 |
struct B { }; |
| 1159 |
struct D : B { }; |
| 1160 |
D f(); |
| 1161 |
extern const B &b; |
| 1162 |
bool a; |
| 1163 |
const B *p = &(a ? f() : b); |
| 1164 |
// expected-error@-1 {{taking the address of a temporary object of type 'const B'}} |
| 1165 |
const B *q = &(a ? D() : b); |
| 1166 |
// expected-error@-1 {{taking the address of a temporary object of type 'const B'}} |
| 1167 |
} |
| 1168 |
|
| 1169 |
namespace cwg590 { // cwg590: yes |
| 1170 |
template<typename T> struct A { |
| 1171 |
struct B { |
| 1172 |
struct C { |
| 1173 |
A<T>::B::C f(A<T>::B::C); // ok, no 'typename' required. |
| 1174 |
}; |
| 1175 |
}; |
| 1176 |
}; |
| 1177 |
template<typename T> typename A<T>::B::C A<T>::B::C::f(A<T>::B::C) {} |
| 1178 |
} |
| 1179 |
|
| 1180 |
namespace cwg591 { // cwg591: no |
| 1181 |
template<typename T> struct A { |
| 1182 |
typedef int M; |
| 1183 |
struct B { |
| 1184 |
typedef void M; |
| 1185 |
struct C; |
| 1186 |
}; |
| 1187 |
}; |
| 1188 |
|
| 1189 |
template<typename T> struct A<T>::B::C : A<T> { |
| 1190 |
// FIXME: Should find member of non-dependent base class A<T>. |
| 1191 |
M m; |
| 1192 |
// expected-error@-1 {{field has incomplete type 'M' (aka 'void'}} |
| 1193 |
}; |
| 1194 |
} |
| 1195 |
|
| 1196 |
// cwg592: na |
| 1197 |
// cwg593 is in cwg593.cpp |
| 1198 |
// cwg594: na |
| 1199 |
|
| 1200 |
namespace cwg595 { // cwg595: dup 1330 |
| 1201 |
template<class T> struct X { |
| 1202 |
void f() throw(T) {} |
| 1203 |
// since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}} |
| 1204 |
// since-cxx17-note@-2 {{use 'noexcept(false)' instead}} |
| 1205 |
}; |
| 1206 |
struct S { |
| 1207 |
X<S> xs; |
| 1208 |
}; |
| 1209 |
} |
| 1210 |
|
| 1211 |
// cwg597: na |
| 1212 |
|
| 1213 |
namespace cwg598 { // cwg598: yes |
| 1214 |
namespace N { |
| 1215 |
void f(int); |
| 1216 |
void f(char); |
| 1217 |
// Not found by ADL. |
| 1218 |
void g(void (*)(int)); |
| 1219 |
void h(void (*)(int)); |
| 1220 |
|
| 1221 |
namespace M { |
| 1222 |
struct S {}; |
| 1223 |
int &h(void (*)(S)); |
| 1224 |
} |
| 1225 |
void i(M::S); |
| 1226 |
void i(); |
| 1227 |
} |
| 1228 |
int &g(void(*)(char)); |
| 1229 |
int &r = g(N::f); |
| 1230 |
int &s = h(N::f); |
| 1231 |
// expected-error@-1 {{use of undeclared identifier 'h'}} |
| 1232 |
int &t = h(N::i); |
| 1233 |
} |
| 1234 |
|
| 1235 |
namespace cwg599 { // cwg599: partial |
| 1236 |
typedef int Fn(); |
| 1237 |
struct S { operator void*(); }; |
| 1238 |
struct T { operator Fn*(); }; |
| 1239 |
struct U { operator int*(); operator void*(); }; // #cwg599-U |
| 1240 |
struct V { operator int*(); operator Fn*(); }; |
| 1241 |
void f(void *p, void (*q)(), S s, T t, U u, V v) { |
| 1242 |
delete p; |
| 1243 |
// cxx98-23-error@-1 {{cannot delete expression with pointer-to-'void' type 'void *'}} |
| 1244 |
// since-cxx26-error@-2 {{cannot delete pointer to incomplete type 'void'}} |
| 1245 |
delete q; |
| 1246 |
// expected-error@-1 {{cannot delete expression of type 'void (*)()'}} |
| 1247 |
delete s; |
| 1248 |
// cxx98-23-error@-1 {{cannot delete expression with pointer-to-'void' type 'void *'}} |
| 1249 |
// since-cxx26-error@-2 {{cannot delete pointer to incomplete type 'void'}} |
| 1250 |
delete t; |
| 1251 |
// expected-error@-1 {{cannot delete expression of type 'T'}} |
| 1252 |
// FIXME: This is valid, but is rejected due to a non-conforming GNU |
| 1253 |
// extension allowing deletion of pointers to void. |
| 1254 |
delete u; |
| 1255 |
// expected-error@-1 {{ambiguous conversion of delete expression of type 'U' to a pointer}} |
| 1256 |
// expected-note@#cwg599-U {{conversion to pointer type 'int *'}} |
| 1257 |
// expected-note@#cwg599-U {{conversion to pointer type 'void *'}} |
| 1258 |
delete v; |
| 1259 |
} |
| 1260 |
} |