1 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify=expected,cxx98,cxx98-11,cxx98-14,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors 2 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,cxx98-11,cxx98-14,cxx98-17,cxx11-14 -fexceptions -fcxx-exceptions -pedantic-errors 3 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,cxx98-14,cxx98-17,cxx11-14 -fexceptions -fcxx-exceptions -pedantic-errors 4 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors 5 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors 6 // RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors 7 // RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17 -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 #if __cplusplus == 199711L 15 #define __enable_constant_folding(x) (__builtin_constant_p(x) ? (x) : (x)) 16 #else 17 #define __enable_constant_folding 18 #endif 19 20 namespace cwg100 { // cwg100: 2.7 21 template<const char (*)[4]> struct A {}; // #cwg100-A 22 template<const char (&)[4]> struct B {}; // #cwg100-B 23 template<const char *> struct C {}; // #cwg100-C 24 template<const char &> struct D {}; // #cwg100-D 25 A<&"foo"> a; // #cwg100-a 26 // cxx98-14-error@#cwg100-a {{non-type template argument does not refer to any declaration}} 27 // cxx98-14-note@#cwg100-A {{template parameter is declared here}} 28 // since-cxx17-error@#cwg100-a {{pointer to string literal is not allowed in a template argument}} 29 B<"bar"> b; // #cwg100-b 30 // cxx98-14-error@#cwg100-b {{non-type template argument does not refer to any declaration}} 31 // cxx98-14-note@#cwg100-B {{template parameter is declared here}} 32 // since-cxx17-error@#cwg100-b {{reference to string literal is not allowed in a template argument}} 33 C<"baz"> c; // #cwg100-c 34 // cxx98-14-error@#cwg100-c {{non-type template argument does not refer to any declaration}} 35 // cxx98-14-note@#cwg100-C {{template parameter is declared here}} 36 // since-cxx17-error@#cwg100-c {{pointer to subobject of string literal is not allowed in a template argument}} 37 D<*"quux"> d; // #cwg100-d 38 // cxx98-14-error@#cwg100-d {{non-type template argument does not refer to any declaration}} 39 // cxx98-14-note@#cwg100-D {{template parameter is declared here}} 40 // since-cxx17-error@#cwg100-d {{reference to subobject of string literal is not allowed in a template argument}} 41 } // namespace cwg100 42 43 namespace cwg101 { // cwg101: 3.5 44 extern "C" void cwg101_f(); 45 typedef unsigned size_t; 46 namespace X { 47 extern "C" void cwg101_f(); 48 typedef unsigned size_t; 49 } 50 using X::cwg101_f; 51 using X::size_t; 52 extern "C" void cwg101_f(); 53 typedef unsigned size_t; 54 } // namespace cwg101 55 56 namespace cwg102 { // cwg102: 2.7 57 namespace A { 58 template<typename T> T f(T a, T b) { return a + b; } 59 // expected-error@-1 {{call to function 'operator+' that is neither visible in the template definition nor found by argument-dependent lookup}} 60 // expected-note@#cwg102-instantiation {{in instantiation of function template specialization 'cwg102::A::f<cwg102::B::S>' requested here}} 61 // expected-note@#cwg102-operator-plus {{'operator+' should be declared prior to the call site or in namespace 'cwg102::B'}} 62 } 63 namespace B { 64 struct S {}; 65 } 66 B::S operator+(B::S, B::S); // #cwg102-operator-plus 67 template B::S A::f(B::S, B::S); // #cwg102-instantiation 68 } // namespace cwg102 69 70 // cwg103: na 71 // cwg104: na lib 72 // cwg105: na 73 74 namespace cwg106 { // cwg106: sup 540 75 typedef int &r1; 76 typedef r1 &r1; 77 typedef const r1 r1; 78 // expected-warning@-1 {{'const' qualifier on reference type 'r1' (aka 'int &') has no effect}} 79 typedef const r1 &r1; 80 // expected-warning@-1 {{'const' qualifier on reference type 'r1' (aka 'int &') has no effect}} 81 82 typedef const int &r2; 83 typedef r2 &r2; 84 typedef const r2 r2; 85 // expected-warning@-1 {{'const' qualifier on reference type 'r2' (aka 'const int &') has no effect}} 86 typedef const r2 &r2; 87 // expected-warning@-1 {{'const' qualifier on reference type 'r2' (aka 'const int &') has no effect}} 88 } // namespace cwg106 89 90 namespace cwg107 { // cwg107: 2.7 91 struct S {}; 92 extern "C" S operator+(S, S) { return S(); } 93 } // namespace cwg107 94 95 namespace cwg108 { // cwg108: 2.9 96 template<typename T> struct A { 97 struct B { typedef int X; }; 98 B::X x; 99 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name B::X; implicit 'typename' is a C++20 extension}} 100 struct C : B { X x; }; 101 // expected-error@-1 {{unknown type name 'X'}} 102 }; 103 template<> struct A<int>::B { int X; }; 104 } // namespace cwg108 105 106 namespace cwg109 { // cwg109: 2.8 107 struct A { template<typename T> void f(T); }; 108 template<typename T> struct B : T { 109 using T::template f; 110 // expected-error@-1 {{'template' keyword not permitted here}} 111 using T::template f<int>; 112 // expected-error@-1 {{'template' keyword not permitted here}} 113 // expected-error@-2 {{using declaration cannot refer to a template specialization}} 114 // FIXME: We shouldn't suggest using the 'template' keyword in a location where it's not valid. 115 using T::f<int>; 116 // expected-error@-1 {{use 'template' keyword to treat 'f' as a dependent template name}} 117 // expected-error@-2 {{using declaration cannot refer to a template specialization}} 118 void g() { this->f<int>(123); } 119 // expected-error@-1 {{use 'template' keyword to treat 'f' as a dependent template name}} 120 }; 121 } // namespace cwg109 122 123 namespace cwg110 { // cwg110: 2.8 124 template <typename T> 125 void f(T); 126 127 class f {}; 128 129 template <typename T> 130 void f(T, T); 131 132 class f g; 133 void (*h)(int) = static_cast<void(*)(int)>(f); 134 void (*i)(int, int) = static_cast<void(*)(int, int)>(f); 135 } // namespace cwg110 136 137 namespace cwg111 { // cwg111: dup 535 138 struct A { A(); A(volatile A&, int = 0); A(A&, const char * = "foo"); }; 139 struct B : A { B(); }; // #cwg111-B 140 const B b1; 141 B b2(b1); 142 // expected-error@-1 {{no matching constructor for initialization of 'B'}} 143 // expected-note@#cwg111-B {{candidate constructor (the implicit copy constructor) not viable: 1st argument ('const B') would lose const qualifier}} 144 // expected-note@#cwg111-B {{candidate constructor not viable: requires 0 arguments, but 1 was provided}} 145 } // namespace cwg111 146 147 namespace cwg112 { // cwg112: 3.1 148 struct T { int n; }; 149 typedef T Arr[1]; 150 151 const T a1[1] = {}; // #cwg112-a1 152 volatile T a2[1] = {}; 153 const Arr a3 = {}; // #cwg112-a3 154 volatile Arr a4 = {}; 155 template<const volatile T*> struct X {}; 156 // FIXME: Test this somehow in C++11 and on. 157 X<a1> x1; 158 // cxx98-error@-1 {{non-type template argument referring to object 'a1' with internal linkage is a C++11 extension}} 159 // cxx98-note@#cwg112-a1 {{non-type template argument refers to object here}} 160 X<a2> x2; 161 X<a3> x3; 162 // cxx98-error@-1 {{non-type template argument referring to object 'a3' with internal linkage is a C++11 extension}} 163 // cxx98-note@#cwg112-a3 {{non-type template argument refers to object here}} 164 X<a4> x4; 165 } // namespace cwg112 166 167 namespace cwg113 { // cwg113: 2.7 168 extern void (*p)(); 169 void f() { 170 no_such_function(); 171 // expected-error@-1 {{use of undeclared identifier 'no_such_function'}} 172 p(); 173 } 174 void g(); 175 void (*p)() = &g; 176 } // namespace cwg113 177 178 namespace cwg114 { // cwg114: 2.7 179 struct A { 180 virtual void f(int) = 0; // #cwg114-A-f 181 }; 182 struct B : A { 183 template<typename T> void f(T); 184 void g() { f(0); } 185 } b; 186 // expected-error@-1 {{variable type 'struct B' is an abstract class}} 187 // expected-note@#cwg114-A-f {{unimplemented pure virtual method 'f' in 'B'}} 188 } // namespace cwg114 189 190 namespace cwg115 { // cwg115: 3.0 191 template<typename T> int f(T); // #cwg115-f 192 template<typename T> int g(T); // #cwg115-g 193 template<typename T> int g(T, int); // #cwg115-g-int 194 195 int k1 = f(&f); 196 // expected-error@-1 {{no matching function for call to 'f'}} 197 // expected-note@#cwg115-f {{candidate template ignored: couldn't infer template argument 'T'}} 198 int k2 = f(&f<int>); 199 int k3 = f(&g<int>); 200 // expected-error@-1 {{no matching function for call to 'f'}} 201 // expected-note@#cwg115-f {{candidate template ignored: couldn't infer template argument 'T'}} 202 203 void h() { 204 (void)&f; 205 // expected-error@-1 {{address of overloaded function 'f' cannot be cast to type 'void'}} 206 // expected-note@#cwg115-f {{candidate function template}} 207 (void)&f<int>; 208 (void)&g<int>; 209 // expected-error@-1 {{address of overloaded function 'g' cannot be cast to type 'void'}} 210 // expected-note@#cwg115-g-int {{candidate function template}} 211 // expected-note@#cwg115-g {{candidate function template}} 212 213 &f; 214 // expected-error@-1 {{reference to overloaded function could not be resolved; did you mean to call it?}} 215 // expected-note@#cwg115-f {{possible target for call}} 216 &f<int>; 217 // expected-warning@-1 {{expression result unused}} 218 &g<int>; 219 // expected-error@-1 {{reference to overloaded function could not be resolved; did you mean to call it?}} 220 // expected-note@#cwg115-g-int {{possible target for call}} 221 // expected-note@#cwg115-g {{possible target for call}} 222 } 223 224 struct S { 225 template<typename T> static int f(T); 226 template<typename T> static int g(T); 227 template<typename T> static int g(T, int); 228 } s; 229 230 int k4 = f(&s.f); 231 // expected-error@-1 {{cannot create a non-constant pointer to member function}} 232 int k5 = f(&s.f<int>); 233 int k6 = f(&s.g<int>); 234 // expected-error@-1 {{cannot create a non-constant pointer to member function}} 235 236 void i() { 237 (void)&s.f; 238 // expected-error@-1 {{cannot create a non-constant pointer to member function}} 239 (void)&s.f<int>; 240 (void)&s.g<int>; 241 // expected-error@-1 {{cannot create a non-constant pointer to member function}} 242 243 &s.f; 244 // expected-error@-1 {{cannot create a non-constant pointer to member function}} 245 &s.f<int>; 246 // expected-warning@-1 {{expression result unused}} 247 &s.g<int>; 248 // expected-error@-1 {{cannot create a non-constant pointer to member function}} 249 } 250 251 struct T { 252 template<typename T> int f(T); 253 template<typename T> int g(T); 254 template<typename T> int g(T, int); 255 } t; 256 257 int k7 = f(&s.f); 258 // expected-error@-1 {{cannot create a non-constant pointer to member function}} 259 int k8 = f(&s.f<int>); 260 int k9 = f(&s.g<int>); 261 // expected-error@-1 {{cannot create a non-constant pointer to member function}} 262 263 void j() { 264 (void)&s.f; 265 // expected-error@-1 {{cannot create a non-constant pointer to member function}} 266 (void)&s.f<int>; 267 (void)&s.g<int>; 268 // expected-error@-1 {{cannot create a non-constant pointer to member function}} 269 270 &s.f; 271 // expected-error@-1 {{cannot create a non-constant pointer to member function}} 272 &s.f<int>; 273 // expected-warning@-1 {{expression result unused}} 274 &s.g<int>; 275 // expected-error@-1 {{cannot create a non-constant pointer to member function}} 276 } 277 278 #if __cplusplus >= 201103L 279 // Special case kicks in only if a template argument list is specified. 280 template<typename T=int> void with_default(); // #cwg115-with-default 281 int k10 = f(&with_default); 282 // since-cxx11-error@-1 {{no matching function for call to 'f'}} 283 // since-cxx11-note@#cwg115-f {{candidate template ignored: couldn't infer template argument 'T'}} 284 int k11 = f(&with_default<>); 285 void k() { 286 (void)&with_default; 287 // since-cxx11-error@-1 {{address of overloaded function 'with_default' cannot be cast to type 'void'}} 288 // since-cxx11-note@#cwg115-with-default {{candidate function template}} 289 (void)&with_default<>; 290 &with_default; 291 // since-cxx11-error@-1 {{reference to overloaded function could not be resolved; did you mean to call it?}} 292 // since-cxx11-note@#cwg115-with-default {{possible target for call}} 293 &with_default<>; 294 // since-cxx11-warning@-1 {{expression result unused}} 295 } 296 #endif 297 } // namespace cwg115 298 299 namespace cwg116 { // cwg116: 2.7 300 template<int> struct A {}; 301 template<int N> void f(A<N>) {} // #cwg116-f-N 302 template<int M> void f(A<M>) {} 303 // expected-error@-1 {{redefinition of 'f'}} 304 // expected-note@#cwg116-f-N {{previous definition is here}} 305 template<typename T> void f(A<sizeof(T)>) {} // #cwg116-f-T 306 template<typename U> void f(A<sizeof(U)>) {} 307 // expected-error@-1 {{redefinition of 'f'}} 308 // expected-note@#cwg116-f-T {{previous definition is here}} 309 } // namespace cwg116 310 311 // cwg117: na 312 // cwg118 is in cwg118.cpp 313 // cwg119: na 314 // cwg120: na 315 316 namespace cwg121 { // cwg121: 2.7 317 struct X { 318 template<typename T> struct Y {}; 319 }; 320 template<typename T> struct Z { 321 X::Y<T> x; 322 T::Y<T> y; 323 // expected-error@-1 {{use 'template' keyword to treat 'Y' as a dependent template name}} 324 // cxx98-17-error@-2 {{missing 'typename' prior to dependent type name T::Y; implicit 'typename' is a C++20 extension}} 325 }; 326 Z<X> z; 327 } // namespace cwg121 328 329 namespace cwg122 { // cwg122: 2.7 330 template<typename T> void f(); 331 void g() { f<int>(); } 332 } // namespace cwg122 333 334 // cwg123: na 335 // cwg124 is in cwg124.cpp 336 337 // cwg125: 2.7 338 struct cwg125_A { struct cwg125_B {}; }; // #cwg125_B 339 cwg125_A::cwg125_B cwg125_C(); 340 namespace cwg125_B { cwg125_A cwg125_C(); } 341 namespace cwg125 { 342 struct X { 343 friend cwg125_A::cwg125_B (::cwg125_C)(); // ok 344 friend cwg125_A (::cwg125_B::cwg125_C)(); // ok 345 friend cwg125_A::cwg125_B::cwg125_C(); // #cwg125_C 346 // expected-error@#cwg125_C {{missing return type for function 'cwg125_C'; did you mean the constructor name 'cwg125_B'?}} 347 // cxx98-error@#cwg125_C {{'cwg125_B' is missing exception specification 'throw()'}} 348 // cxx98-note@#cwg125_B {{previous declaration is here}} 349 // since-cxx11-error@#cwg125_C {{'cwg125_B' is missing exception specification 'noexcept'}} 350 // since-cxx11-note@#cwg125_B {{previous declaration is here}} 351 }; 352 } // namespace cwg125 353 354 namespace cwg126 { // cwg126: partial 355 // FIXME: We do not yet generate correct code for this change: 356 // eg: 357 // catch (void*&) should catch void* but not int* 358 // catch (void*) and catch (void*const&) should catch both 359 // Likewise: 360 // catch (Base *&) should catch Base* but not Derived* 361 // catch (Base *) should catch both 362 // In each case, we emit the same code for both catches. 363 // 364 // The ABI does not let us represent the language rule in the unwind tables. 365 // So, when catching by non-const (or volatile) reference to pointer, we 366 // should compare the exception type to the caught type and only accept an 367 // exact match. 368 struct C {}; 369 struct D : C {}; 370 struct E : private C { friend class A; friend class B; }; 371 struct F : protected C {}; 372 struct G : C {}; 373 struct H : D, G {}; 374 375 #if __cplusplus <= 201402L 376 struct A { 377 virtual void cp() throw(C*); 378 virtual void dp() throw(C*); 379 virtual void ep() throw(C*); // #cwg126-ep 380 virtual void fp() throw(C*); // #cwg126-fp 381 virtual void gp() throw(C*); 382 virtual void hp() throw(C*); // #cwg126-hp 383 384 virtual void cr() throw(C&); 385 virtual void dr() throw(C&); 386 virtual void er() throw(C&); // #cwg126-er 387 virtual void fr() throw(C&); // #cwg126-fr 388 virtual void gr() throw(C&); 389 virtual void hr() throw(C&); // #cwg126-hr 390 391 virtual void pv() throw(void*); 392 393 virtual void np() throw(C*); 394 virtual void npm() throw(int C::*); 395 virtual void nr() throw(C*&); // #cwg126-nr 396 virtual void ncr() throw(C*const&); 397 398 virtual void ref1() throw(C *const&); 399 virtual void ref2() throw(C *); 400 401 virtual void v() throw(int); 402 virtual void w() throw(const int); 403 virtual void x() throw(int*); // #cwg126-x 404 virtual void y() throw(const int*); 405 virtual void z() throw(int); // #cwg126-z 406 }; 407 struct B : A { 408 virtual void cp() throw(C*); 409 virtual void dp() throw(D*); 410 virtual void ep() throw(E*); 411 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}} 412 // cxx98-14-note@#cwg126-ep {{overridden virtual function is here}} 413 virtual void fp() throw(F*); 414 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}} 415 // cxx98-14-note@#cwg126-fp {{overridden virtual function is here}} 416 virtual void gp() throw(G*); 417 virtual void hp() throw(H*); 418 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}} 419 // cxx98-14-note@#cwg126-hp {{overridden virtual function is here}} 420 421 virtual void cr() throw(C&); 422 virtual void dr() throw(D&); 423 virtual void er() throw(E&); 424 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}} 425 // cxx98-14-note@#cwg126-er {{overridden virtual function is here}} 426 virtual void fr() throw(F&); 427 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}} 428 // cxx98-14-note@#cwg126-fr {{overridden virtual function is here}} 429 virtual void gr() throw(G&); 430 virtual void hr() throw(H&); 431 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}} 432 // cxx98-14-note@#cwg126-hr {{overridden virtual function is here}} 433 434 virtual void pv() throw(C*); 435 436 #if __cplusplus >= 201103L 437 using nullptr_t = decltype(nullptr); 438 virtual void np() throw(nullptr_t); 439 virtual void npm() throw(nullptr_t&); 440 virtual void nr() throw(nullptr_t); 441 // cxx11-14-error@-1 {{exception specification of overriding function is more lax than base version}} 442 // cxx11-14-note@#cwg126-nr {{overridden virtual function is here}} 443 virtual void ncr() throw(nullptr_t); 444 #endif // __cplusplus >= 201103L 445 446 virtual void ref1() throw(D *const &); 447 virtual void ref2() throw(D *); 448 449 virtual void v() throw(const int); 450 virtual void w() throw(int); 451 virtual void x() throw(const int*); 452 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}} 453 // cxx98-14-note@#cwg126-x {{overridden virtual function is here}} 454 virtual void y() throw(int*); // ok 455 virtual void z() throw(long); 456 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}} 457 // cxx98-14-note@#cwg126-z {{overridden virtual function is here}} 458 }; 459 #endif // __cplusplus <= 201402L 460 void f() throw(int); 461 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}} 462 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}} 463 } // namespace cwg126 464 465 namespace cwg127 { // cwg127: 2.9 466 __extension__ typedef __decltype(sizeof(0)) size_t; 467 template<typename T> struct A { 468 A() { throw 0; } 469 void *operator new(size_t, const char * = 0); 470 void operator delete(void *, const char *) { T::error; } // #cwg127-delete-const-char 471 // expected-error@#cwg127-delete-const-char {{type 'void' cannot be used prior to '::' because it has no members}} 472 // expected-note@#cwg127-p {{in instantiation of member function 'cwg127::A<void>::operator delete' requested here}} 473 // expected-error@#cwg127-delete-const-char {{type 'int' cannot be used prior to '::' because it has no members}} 474 // expected-note@#cwg127-q {{in instantiation of member function 'cwg127::A<int>::operator delete' requested here}} 475 void operator delete(void *) { T::error; } 476 }; 477 A<void> *p = new A<void>; // #cwg127-p 478 A<int> *q = new ("") A<int>; // #cwg127-q 479 } // namespace cwg127 480 481 namespace cwg128 { // cwg128: 2.7 482 enum E1 { e1 } x = e1; 483 enum E2 { e2 } y = static_cast<E2>(x), z = static_cast<E2>(e1); 484 } // namespace cwg128 485 486 // cwg129: dup 616 487 // cwg130: na 488 489 namespace cwg131 { // cwg131: sup P1949 490 const char *a_with_\u0e8c = "\u0e8c"; 491 const char *b_with_\u0e8d = "\u0e8d"; 492 const char *c_with_\u0e8e = "\u0e8e"; 493 } // namespace cwg131 494 495 namespace cwg132 { // cwg132: no 496 void f() { 497 extern struct {} x; // ok 498 extern struct S {} y; // FIXME: This is invalid. 499 } 500 static enum { E } e; 501 } // namespace cwg132 502 503 // cwg133: dup 87 504 // cwg134: na 505 506 namespace cwg135 { // cwg135: 2.7 507 struct A { 508 A f(A a) { return a; } 509 friend A g(A a) { return a; } 510 static A h(A a) { return a; } 511 }; 512 } // namespace cwg135 513 514 namespace cwg136 { // cwg136: 3.4 515 void f(int, int, int = 0); // #cwg136-f 516 void g(int, int, int); // #cwg136-g 517 struct A { 518 friend void f(int, int = 0, int); 519 // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}} 520 // expected-note@#cwg136-f {{previous declaration is here}} 521 friend void g(int, int, int = 0); 522 // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}} 523 // expected-note@#cwg136-g {{previous declaration is here}} 524 friend void h(int, int, int = 0); 525 // expected-error@-1 {{friend declaration specifying a default argument must be a definition}} 526 friend void i(int, int, int = 0) {} // #cwg136-A-i 527 friend void j(int, int, int = 0) {} 528 operator int(); 529 }; 530 void i(int, int, int); 531 // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}} 532 // expected-note@#cwg136-A-i {{previous declaration is here}} 533 void q() { 534 j(A(), A()); // ok, has default argument 535 } 536 extern "C" void k(int, int, int, int); // #cwg136-k 537 namespace NSA { 538 struct A { 539 friend void cwg136::k(int, int, int, int = 0); 540 // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}} 541 // expected-note@#cwg136-k {{previous declaration is here}} 542 }; 543 } 544 namespace NSB { 545 struct A { 546 friend void cwg136::k(int, int, int = 0, int); // #cwg136-friend-k 547 // expected-error@#cwg136-friend-k {{friend declaration specifying a default argument must be the only declaration}} 548 // expected-note@#cwg136-k {{previous declaration is here}} 549 // expected-error@#cwg136-friend-k {{missing default argument on parameter}} 550 }; 551 } 552 struct B { 553 void f(int); // #cwg136-B-f 554 }; 555 struct C { 556 friend void B::f(int = 0); 557 // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}} 558 // expected-note@#cwg136-B-f {{previous declaration is here}} 559 }; 560 } // namespace cwg136 561 562 namespace cwg137 { // cwg137: 2.7 563 extern void *p; 564 extern const void *cp; 565 extern volatile void *vp; 566 extern const volatile void *cvp; 567 int *q = static_cast<int*>(p); 568 int *qc = static_cast<int*>(cp); 569 // expected-error@-1 {{static_cast from 'const void *' to 'int *' casts away qualifiers}} 570 int *qv = static_cast<int*>(vp); 571 // expected-error@-1 {{static_cast from 'volatile void *' to 'int *' casts away qualifiers}} 572 int *qcv = static_cast<int*>(cvp); 573 // expected-error@-1 {{static_cast from 'const volatile void *' to 'int *' casts away qualifiers}} 574 const int *cq = static_cast<const int*>(p); 575 const int *cqc = static_cast<const int*>(cp); 576 const int *cqv = static_cast<const int*>(vp); 577 // expected-error@-1 {{static_cast from 'volatile void *' to 'const int *' casts away qualifiers}} 578 const int *cqcv = static_cast<const int*>(cvp); 579 // expected-error@-1 {{static_cast from 'const volatile void *' to 'const int *' casts away qualifiers}} 580 const volatile int *cvq = static_cast<const volatile int*>(p); 581 const volatile int *cvqc = static_cast<const volatile int*>(cp); 582 const volatile int *cvqv = static_cast<const volatile int*>(vp); 583 const volatile int *cvqcv = static_cast<const volatile int*>(cvp); 584 } // namespace cwg137 585 586 namespace cwg138 { // cwg138: partial 587 namespace example1 { 588 void foo(); // #cwg138-ex1-foo 589 namespace A { 590 using example1::foo; // #cwg138-ex1-using 591 class X { 592 static const int i = 10; 593 // This friend declaration is using neither qualified-id nor template-id, 594 // so name 'foo' is not looked up, which means the using-declaration has no effect. 595 // Target scope of this declaration is A, so this is grating friendship to 596 // (hypothetical) A::foo instead of 'example1::foo' using declaration refers to. 597 // A::foo corresponds to example1::foo named by the using declaration, 598 // and since A::foo is a different entity, they potentially conflict. 599 // FIXME: This is ill-formed, but not for the reason diagnostic says. 600 friend void foo(); 601 // expected-error@-1 {{cannot befriend target of using declaration}} 602 // expected-note@#cwg138-ex1-foo {{target of using declaration}} 603 // expected-note@#cwg138-ex1-using {{using declaration}} 604 }; 605 } 606 } // namespace example1 607 608 namespace example2 { 609 void f(); 610 void g(); 611 class B { 612 void g(); 613 }; 614 class A : public B { 615 static const int i = 10; 616 void f(); 617 // Both friend declaration are not using qualified-ids or template-ids, 618 // so 'f' and 'g' are not looked up, which means that presence of A::f 619 // and base B have no effect. 620 // Both target scope of namespace 'example2', and grant friendship to 621 // example2::f and example2::g respectively. 622 friend void f(); 623 friend void g(); 624 }; 625 void f() { 626 int i2 = A::i; 627 } 628 void g() { 629 int i3 = A::i; 630 } 631 } // namespace example2 632 633 namespace example3 { 634 struct Base { 635 private: 636 static const int i = 10; // #cwg138-ex3-Base-i 637 638 public: 639 struct Data; 640 // Elaborated type specifier is not the sole constituent of declaration, 641 // so 'Data' undergoes unqualified type-only lookup, which finds Base::Data. 642 friend class Data; 643 644 struct Data { 645 void f() { 646 int i2 = Base::i; 647 } 648 }; 649 }; 650 struct Data { 651 void f() { 652 int i2 = Base::i; 653 // expected-error@-1 {{'i' is a private member of 'cwg138::example3::Base'}} 654 // expected-note@#cwg138-ex3-Base-i {{declared private here}} 655 } 656 }; 657 } // namespace example3 658 } // namespace cwg138 659 660 namespace cwg139 { // cwg139: 2.7 661 namespace example1 { 662 typedef int f; // #cwg139-typedef-f 663 struct A { 664 friend void f(A &); 665 // expected-error@-1 {{redefinition of 'f' as different kind of symbol}} 666 // expected-note@#cwg139-typedef-f {{previous definition is here}} 667 }; 668 } 669 670 namespace example2 { 671 typedef int f; 672 namespace N { 673 struct A { 674 friend void f(A &); 675 operator int(); 676 void g(A a) { int i = f(a); } // ok, f is typedef not friend function 677 }; 678 } 679 } 680 } // namespace cwg139 681 682 namespace cwg140 { // cwg140: 2.7 683 void f(int *const) {} // #cwg140-f-first 684 void f(int[3]) {} 685 // expected-error@-1 {{redefinition of 'f'}} 686 // expected-note@#cwg140-f-first {{previous definition is here}} 687 void g(const int); 688 void g(int n) { n = 2; } 689 } // namespace cwg140 690 691 namespace cwg141 { // cwg141: 3.1 692 template<typename T> void f(); 693 template<typename T> struct S { int n; }; // #cwg141-S 694 struct A : S<int> { 695 template<typename T> void f(); 696 template<typename T> struct S {}; // #cwg141-A-S 697 } a; 698 struct B : S<int> {} b; 699 void g() { 700 a.f<int>(); 701 (void)a.S<int>::n; // #cwg141-a 702 // cxx98-error@#cwg141-a {{lookup of 'S' in member access expression is ambiguous; using member of 'struct A'}} 703 // cxx98-note@#cwg141-A-S {{lookup in the object type 'struct A' refers here}} 704 // cxx98-note@#cwg141-S {{lookup from the current scope refers here}} 705 // expected-error@#cwg141-a {{no member named 'n' in 'cwg141::A::S<int>'; did you mean '::cwg141::S<int>::n'?}} 706 // expected-note@#cwg141-S {{'::cwg141::S<int>::n' declared here}} 707 // FIXME: we issue a useful diagnostic first, then some bogus ones. 708 b.f<int>(); 709 // expected-error@-1 {{no member named 'f' in 'cwg141::B'}} 710 // expected-error@-2 +{{}} 711 (void)b.S<int>::n; 712 } 713 template<typename T> struct C { 714 T t; 715 void g() { 716 t.f<int>(); 717 // expected-error@-1 {{use 'template' keyword to treat 'f' as a dependent template name}} 718 } 719 void h() { 720 (void)t.S<int>::n; // ok 721 } 722 void i() { 723 (void)t.S<int>(); // ok! 724 } 725 }; 726 void h() { C<B>().h(); } // ok 727 struct X { 728 template<typename T> void S(); 729 }; 730 void i() { C<X>().i(); } // ok!! 731 } // namespace cwg141 732 733 namespace cwg142 { // cwg142: 2.8 734 class B { // #cwg142-B 735 public: 736 int mi; // #cwg142-B-mi 737 static int si; // #cwg142-B-si 738 }; 739 class D : private B { // #cwg142-D 740 }; 741 class DD : public D { 742 void f(); 743 }; 744 void DD::f() { 745 mi = 3; 746 // expected-error@-1 {{'mi' is a private member of 'cwg142::B'}} 747 // expected-note@#cwg142-D {{constrained by private inheritance here}} 748 // expected-note@#cwg142-B-mi {{member is declared here}} 749 si = 3; 750 // expected-error@-1 {{'si' is a private member of 'cwg142::B'}} 751 // expected-note@#cwg142-D {{constrained by private inheritance here}} 752 // expected-note@#cwg142-B-si {{member is declared here}} 753 B b_old; 754 // expected-error@-1 {{'B' is a private member of 'cwg142::B'}} 755 // expected-note@#cwg142-D {{constrained by private inheritance here}} 756 // expected-note@#cwg142-B {{member is declared here}} 757 cwg142::B b; 758 b.mi = 3; 759 b.si = 3; 760 B::si = 3; 761 // expected-error@-1 {{'B' is a private member of 'cwg142::B'}} 762 // expected-note@#cwg142-D {{constrained by private inheritance here}} 763 // expected-note@#cwg142-B {{member is declared here}} 764 cwg142::B::si = 3; 765 B *bp1_old = this; // #cwg142-bp1_old 766 // expected-error@#cwg142-bp1_old {{'B' is a private member of 'cwg142::B'}} 767 // expected-note@#cwg142-D {{constrained by private inheritance here}} 768 // expected-note@#cwg142-B {{member is declared here}} 769 // expected-error@#cwg142-bp1_old {{cannot cast 'cwg142::DD' to its private base class 'B'}} 770 // expected-note@#cwg142-D {{declared private here}} 771 cwg142::B *bp1 = this; 772 // expected-error@-1 {{cannot cast 'cwg142::DD' to its private base class 'cwg142::B'}} 773 // expected-note@#cwg142-D {{declared private here}} 774 B *bp2_old = (B*)this; // #cwg142-bp2_old 775 // expected-error@#cwg142-bp2_old {{'B' is a private member of 'cwg142::B'}} 776 // expected-note@#cwg142-D {{constrained by private inheritance here}} 777 // expected-note@#cwg142-B {{member is declared here}} 778 // expected-error@#cwg142-bp2_old {{'B' is a private member of 'cwg142::B'}} 779 // expected-note@#cwg142-D {{constrained by private inheritance here}} 780 // expected-note@#cwg142-B {{member is declared here}} 781 cwg142::B *bp2 = (cwg142::B*)this; 782 bp2->mi = 3; 783 } 784 } // namespace cwg142 785 786 namespace cwg143 { // cwg143: 2.7 787 namespace A { struct X; } 788 namespace B { void f(A::X); } 789 namespace A { 790 struct X { friend void B::f(X); }; 791 } 792 void g(A::X x) { 793 f(x); 794 // expected-error@-1 {{use of undeclared identifier 'f'}} 795 } 796 } // namespace cwg143 797 798 namespace cwg145 { // cwg145: 2.7 799 void f(bool b) { 800 ++b; 801 // cxx98-14-warning@-1 {{incrementing expression of type bool is deprecated and incompatible with C++17}} 802 // since-cxx17-error@-2 {{ISO C++17 does not allow incrementing expression of type bool}} 803 b++; 804 // cxx98-14-warning@-1 {{incrementing expression of type bool is deprecated and incompatible with C++17}} 805 // since-cxx17-error@-2 {{ISO C++17 does not allow incrementing expression of type bool}} 806 } 807 } // namespace cwg145 808 809 namespace cwg147 { // cwg147: 2.7 810 namespace example1 { 811 template<typename> struct A { 812 template<typename T> A(T); 813 }; 814 // Per core issue 1435, this is ill-formed because A<int>::A<int> does not 815 // name the injected-class-name. (A<int>::A does, though.) 816 template<> template<> A<int>::A<int>(int) {} 817 // expected-error@-1 {{out-of-line constructor for 'A' cannot have template arguments}} 818 template<> template<> A<float>::A(float) {} 819 } 820 namespace example2 { 821 struct A { A(); }; 822 struct B : A { B(); }; 823 A::A a1; 824 // expected-error@-1 {{qualified reference to 'A' is a constructor name rather than a type in this context}} 825 B::A a2; 826 } 827 namespace example3 { 828 template<typename> struct A { 829 template<typename T> A(T); 830 static A a; 831 }; 832 template<> A<int>::A<int>(A<int>::a); 833 // expected-error@-1 {{qualified reference to 'A' is a constructor name rather than a template name in this context}} 834 } 835 } // namespace cwg147 836 837 namespace cwg148 { // cwg148: 2.7 838 struct A { int A::*p; }; 839 static_assert(__is_pod(int(A::*)), ""); 840 static_assert(__is_pod(A), ""); 841 } // namespace cwg148 842 843 // cwg149: na 844 845 namespace cwg150 { // cwg150: 19 846 namespace p1 { 847 template <class T, class U = int> 848 class ARG { }; 849 850 template <class X, template <class Y> class PARM> 851 void f(PARM<X>) { } 852 853 void g() { 854 ARG<int> x; 855 f(x); 856 } 857 } // namespace p1 858 859 namespace p2 { 860 template <template <class T, class U = int> class PARM> 861 class C { 862 PARM<int> pi; 863 }; 864 } // namespace p2 865 866 namespace n1 { 867 struct Dense { static const unsigned int dim = 1; }; 868 869 template <template <typename> class View, 870 typename Block> 871 void operator+(float, View<Block> const&); 872 873 template <typename Block, 874 unsigned int Dim = Block::dim> 875 class Lvalue_proxy { operator float() const; }; 876 877 void test_1d (void) { 878 Lvalue_proxy<Dense> p; 879 float b; 880 b + p; 881 } 882 } // namespace n1 883 } // namespace cwg150 884 885 namespace cwg151 { // cwg151: 3.1 886 struct X {}; 887 typedef int X::*p; 888 static_assert(__enable_constant_folding(p() == 0), ""); 889 } // namespace cwg151 890 891 namespace cwg152 { // cwg152: 2.7 892 struct A { 893 A(); // #cwg152-A-ctor 894 explicit A(const A&); // #cwg152-A-explicit-ctor 895 }; 896 A a1 = A(); 897 // cxx98-14-error@-1 {{no matching constructor for initialization of 'A'}} 898 // cxx98-14-note@#cwg152-A-explicit-ctor {{explicit constructor is not a candidate}} 899 // cxx98-14-note@#cwg152-A-ctor {{candidate constructor not viable: requires 0 arguments, but 1 was provided}} 900 A a2((A())); 901 902 A &f(); 903 A a3 = f(); 904 // expected-error@-1 {{no matching constructor for initialization of 'A'}} 905 // expected-note@#cwg152-A-explicit-ctor {{explicit constructor is not a candidate}} 906 // expected-note@#cwg152-A-ctor {{candidate constructor not viable: requires 0 arguments, but 1 was provided}} 907 A a4(f()); 908 } // namespace cwg152 909 910 // cwg153: na 911 912 namespace cwg154 { // cwg154: 2.7 913 union { int a; }; 914 // expected-error@-1 {{nonymous unions at namespace or global scope must be declared 'static'}} 915 namespace { 916 union { int b; }; 917 } 918 static union { int c; }; 919 } // namespace cwg154 920 921 namespace cwg155 { // cwg155: dup 632 922 struct S { int n; } s = { { 1 } }; 923 // expected-warning@-1 {{braces around scalar initializer}} 924 } // namespace cwg155 925 926 // cwg156: sup 1111 927 // cwg158 is in cwg158.cpp 928 929 namespace cwg159 { // cwg159: 3.5 930 namespace X { void f(); } 931 void f(); 932 void cwg159::f() {} 933 // expected-warning@-1 {{extra qualification on member 'f'}} 934 void cwg159::X::f() {} 935 } // namespace cwg159 936 937 // cwg160: na 938 939 namespace cwg161 { // cwg161: 3.1 940 class A { 941 protected: 942 struct B { int n; } b; // #cwg161-B 943 static B bs; 944 void f(); // #cwg161-f 945 static void sf(); 946 }; 947 struct C : A {}; 948 struct D : A { 949 void g(C c) { 950 (void)b.n; 951 B b1; 952 C::B b2; // ok, accessible as a member of A 953 (void)&C::b; 954 // expected-error@-1 {{'b' is a protected member of 'cwg161::A'}} 955 // expected-note@#cwg161-B {{declared protected here}} 956 (void)&C::bs; 957 (void)c.b; 958 // expected-error@-1 {{'b' is a protected member of 'cwg161::A'}} 959 // expected-note@#cwg161-B {{declared protected here}} 960 (void)c.bs; 961 f(); 962 sf(); 963 c.f(); 964 // expected-error@-1 {{protected}} 965 // expected-note@#cwg161-f {{declared protected here}} 966 c.sf(); 967 A::f(); 968 D::f(); 969 A::sf(); 970 C::sf(); 971 D::sf(); 972 } 973 }; 974 } // namespace cwg161 975 976 namespace cwg162 { // cwg162: 19 977 struct A { 978 char &f(char); 979 static int &f(int); 980 981 void g() { 982 int &a = (&A::f)(0); 983 char &b = (&A::f)('0'); 984 // expected-error@-1 {{non-const lvalue reference to type 'char' cannot bind to a value of unrelated type 'int'}} 985 } 986 }; 987 988 int &c = (&A::f)(0); 989 char &d = (&A::f)('0'); 990 // expected-error@-1 {{non-const lvalue reference to type 'char' cannot bind to a value of unrelated type 'int'}} 991 } // namespace cwg162 992 993 // cwg163: na 994 995 namespace cwg164 { // cwg164: 2.7 996 void f(int); 997 template <class T> int g(T t) { return f(t); } 998 999 enum E { e }; 1000 int f(E); 1001 1002 int k = g(e); 1003 } // namespace cwg164 1004 1005 namespace cwg165 { // cwg165: no 1006 namespace N { 1007 struct A { friend struct B; }; 1008 void f() { void g(); } 1009 } 1010 // FIXME: cwg1477 says this is ok, cwg165 says it's ill-formed 1011 struct N::B {}; 1012 // FIXME: cwg165 says this is ill-formed, but the argument in cwg1477 says it's ok 1013 void N::g() {} 1014 } // namespace cwg165 1015 1016 namespace cwg166 { // cwg166: 2.9 1017 namespace A { class X; } 1018 1019 template<typename T> int f(T t) { return t.n; } 1020 int g(A::X); 1021 template<typename T> int h(T t) { return t.n; } 1022 // expected-error@-1 {{'n' is a private member of 'cwg166::A::X'}} 1023 // expected-note@#cwg166-h-instantiation {{in instantiation of function template specialization 'cwg166::h<cwg166::A::X>' requested here}} 1024 // expected-note@#cwg166-X-n {{implicitly declared private here}} 1025 int i(A::X); 1026 1027 namespace A { 1028 class X { 1029 friend int f<X>(X); 1030 friend int cwg166::g(X); 1031 friend int h(X); 1032 friend int i(X); 1033 int n; // #cwg166-X-n 1034 }; 1035 1036 int h(X x) { return x.n; } 1037 int i(X x) { return x.n; } 1038 } 1039 1040 template int f(A::X); 1041 int g(A::X x) { return x.n; } 1042 template int h(A::X); // #cwg166-h-instantiation 1043 int i(A::X x) { return x.n; } 1044 // expected-error@-1 {{'n' is a private member of 'cwg166::A::X'}} 1045 // expected-note@#cwg166-X-n {{implicitly declared private here}} 1046 } // namespace cwg166 1047 1048 // cwg167: sup 1012 1049 1050 namespace cwg168 { // cwg168: no 1051 extern "C" typedef int (*p)(); 1052 extern "C++" typedef int (*q)(); 1053 struct S { 1054 static int f(); 1055 }; 1056 p a = &S::f; // FIXME: this should fail. 1057 q b = &S::f; 1058 } // namespace cwg168 1059 1060 namespace cwg169 { // cwg169: 3.4 1061 template<typename> struct A { int n; }; 1062 struct B { 1063 template<typename> struct C; 1064 template<typename> void f(); 1065 template<typename> static int n; 1066 // cxx98-11-error@-1 {{variable templates are a C++14 extension}} 1067 }; 1068 struct D : A<int>, B { 1069 using A<int>::n; 1070 using B::C<int>; 1071 // expected-error@-1 {{using declaration cannot refer to a template specialization}} 1072 using B::f<int>; 1073 // expected-error@-1 {{using declaration cannot refer to a template specialization}} 1074 using B::n<int>; 1075 // expected-error@-1 {{using declaration cannot refer to a template specialization}} 1076 }; 1077 } // namespace cwg169 1078 1079 namespace cwg170 { // cwg170: 3.1 1080 #if __cplusplus >= 201103L 1081 struct A {}; 1082 struct B : A { int i; }; 1083 struct C : A {}; 1084 struct D : C {}; 1085 1086 constexpr int f(int A::*) { return 0; } 1087 constexpr int g(int C::*) { return 0; } 1088 constexpr int h(int D::*) { return 0; } 1089 1090 constexpr auto p = static_cast<int A::*>(&B::i); 1091 constexpr auto q = f(p); 1092 constexpr auto r = g(p); 1093 // since-cxx11-error@-1 {{constexpr variable 'r' must be initialized by a constant expression}} 1094 constexpr auto s = h(p); 1095 // since-cxx11-error@-1 {{constexpr variable 's' must be initialized by a constant expression}} 1096 #endif 1097 } // namespace cwg170 1098 1099 namespace { // cwg171: 3.4 1100 int cwg171a; 1101 } 1102 int cwg171b; // #cwg171b-int 1103 namespace cwg171 { 1104 extern "C" void cwg171a(); 1105 extern "C" void cwg171b(); 1106 // expected-error@-1 {{declaration of 'cwg171b' with C language linkage conflicts with declaration in global scope}} 1107 // expected-note@#cwg171b-int {{declared in global scope here}} 1108 } // namespace cwg171 1109 1110 namespace cwg172 { // cwg172: 2.7 1111 enum { zero }; 1112 static_assert(-1 < zero, ""); 1113 1114 enum { x = -1, y = (unsigned int)-1 }; 1115 static_assert(sizeof(x) > sizeof(int), ""); 1116 1117 enum { a = (unsigned int)-1 / 2 }; 1118 static_assert(sizeof(a) == sizeof(int), ""); 1119 static_assert(-a < 0, ""); 1120 1121 enum { b = (unsigned int)-1 / 2 + 1 }; 1122 static_assert(sizeof(b) == sizeof(unsigned int), ""); 1123 static_assert(-b > 0, ""); 1124 1125 enum { c = (unsigned long)-1 / 2 }; 1126 static_assert(sizeof(c) == sizeof(long), ""); 1127 static_assert(-c < 0, ""); 1128 1129 enum { d = (unsigned long)-1 / 2 + 1 }; 1130 static_assert(sizeof(d) == sizeof(unsigned long), ""); 1131 static_assert(-d > 0, ""); 1132 1133 enum { e = (unsigned long long)-1 / 2 }; 1134 // cxx98-error@-1 {{'long long' is a C++11 extension}} 1135 static_assert(sizeof(e) == sizeof(long), ""); 1136 static_assert(-e < 0, ""); 1137 1138 enum { f = (unsigned long long)-1 / 2 + 1 }; 1139 // cxx98-error@-1 {{'long long' is a C++11 extension}} 1140 static_assert(sizeof(f) == sizeof(unsigned long), ""); 1141 static_assert(-f > 0, ""); 1142 } // namespace cwg172 1143 1144 namespace cwg173 { // cwg173: 2.7 1145 static_assert('0' + 1 == '1' && '0' + 2 == '2' && '0' + 3 == '3' && 1146 '0' + 4 == '4' && '0' + 5 == '5' && '0' + 6 == '6' && 1147 '0' + 7 == '7' && '0' + 8 == '8' && '0' + 9 == '9', ""); 1148 } // namespace cwg173 1149 1150 // cwg174: sup 1012 1151 1152 namespace cwg175 { // cwg175: 2.8 1153 struct A {}; // #cwg175-A 1154 struct B : private A {}; // #cwg175-B 1155 struct C : B { 1156 A a; 1157 // expected-error@-1 {{'A' is a private member of 'cwg175::A'}} 1158 // expected-note@#cwg175-B {{constrained by private inheritance here}} 1159 // expected-note@#cwg175-A {{member is declared here}} 1160 cwg175::A b; 1161 }; 1162 } // namespace cwg175 1163 1164 namespace cwg176 { // cwg176: 3.1 1165 template<typename T> class Y; 1166 template<> class Y<int> { 1167 void f() { 1168 typedef Y A; // #cwg176-A-first 1169 typedef Y<char> A; 1170 // expected-error@-1 {{typedef redefinition with different types ('Y<char>' vs 'Y<int>')}} 1171 // expected-note@#cwg176-A-first {{previous definition is here}} 1172 } 1173 }; 1174 1175 template<typename T> struct Base {}; // #cwg176-Base 1176 template<typename T> struct Derived : public Base<T> { 1177 void f() { 1178 typedef typename Derived::template Base<T> A; 1179 typedef typename Derived::Base A; 1180 } 1181 }; 1182 template struct Derived<int>; 1183 1184 template<typename T> struct Derived2 : Base<int>, Base<char> { 1185 typename Derived2::Base b; 1186 // expected-error@-1 {{member 'Base' found in multiple base classes of different types}} 1187 // expected-note@#cwg176-Base {{member type 'cwg176::Base<int>' found by ambiguous name lookup}} 1188 // expected-note@#cwg176-Base {{member type 'cwg176::Base<char>' found by ambiguous name lookup}} 1189 typename Derived2::Base<double> d; 1190 }; 1191 1192 template<typename T> class X { // #cwg176-X 1193 X *p1; 1194 X<T> *p2; 1195 X<int> *p3; 1196 cwg176::X *p4; // #cwg176-p4 1197 // cxx98-14-error@#cwg176-p4 {{use of class template 'cwg176::X' requires template arguments}} 1198 // cxx98-14-note@#cwg176-X {{template is declared here}} 1199 // since-cxx17-error@#cwg176-p4 {{use of class template 'cwg176::X' requires template arguments; argument deduction not allowed in non-static class member}} 1200 // since-cxx17-note@#cwg176-X {{template is declared here}} 1201 }; 1202 } // namespace cwg176 1203 1204 namespace cwg177 { // cwg177: 2.7 1205 struct B {}; 1206 struct A { 1207 A(A &); // #cwg177-A-copy-ctor 1208 A(const B &); // #cwg177-A-ctor-from-B 1209 }; 1210 B b; 1211 A a = b; 1212 // cxx98-14-error@-1 {{no viable constructor copying variable of type 'A'}} 1213 // cxx98-14-note@#cwg177-A-copy-ctor {{candidate constructor not viable: expects an lvalue for 1st argument}} 1214 // cxx98-14-note@#cwg177-A-ctor-from-B {{candidate constructor not viable: no known conversion from 'A' to 'const B &' for 1st argument}} 1215 1216 struct C { C(C&); }; // #cwg177-C-copy-ctor 1217 struct D : C {}; 1218 struct E { operator D(); }; 1219 E e; 1220 C c = e; 1221 // expected-error@-1 {{no viable constructor copying variable of type 'D'}} 1222 // expected-note@#cwg177-C-copy-ctor {{candidate constructor not viable: expects an lvalue for 1st argument}} 1223 } // namespace cwg177 1224 1225 namespace cwg178 { // cwg178: 3.1 1226 static_assert(int() == 0, ""); 1227 #if __cplusplus >= 201103L 1228 static_assert(int{} == 0, ""); 1229 struct S { int a, b; }; 1230 static_assert(S{1}.b == 0, ""); 1231 struct T { constexpr T() : n() {} int n; }; 1232 static_assert(T().n == 0, ""); 1233 struct U : S { constexpr U() : S() {} }; 1234 static_assert(U().b == 0, ""); 1235 #endif 1236 } // namespace cwg178 1237 1238 namespace cwg179 { // cwg179: 2.7 1239 void f(); 1240 int n = &f - &f; 1241 // expected-error@-1 {{arithmetic on pointers to the function type 'void ()'}} 1242 } // namespace cwg179 1243 1244 namespace cwg180 { // cwg180: 2.8 1245 template<typename T> struct X : T, T::some_base { 1246 X() : T::some_type_that_might_be_T(), T::some_base() {} 1247 friend class T::some_class; 1248 void f() { 1249 enum T::some_enum e; 1250 } 1251 }; 1252 } // namespace cwg180 1253 1254 namespace cwg181 { // cwg181: 2.7 1255 namespace X { 1256 template <template X<class T> > struct A { }; 1257 // expected-error@-1 +{{}} 1258 template <template X<class T> > void f(A<X>) { } 1259 // expected-error@-1 +{{}} 1260 } 1261 1262 namespace Y { 1263 template <template <class T> class X> struct A { }; 1264 template <template <class T> class X> void f(A<X>) { } 1265 } 1266 } // namespace cwg181 1267 1268 namespace cwg182 { // cwg182: 14 1269 template <class T> struct C { 1270 void f(); 1271 void g(); 1272 }; 1273 1274 template <class T> void C<T>::f() {} 1275 template <class T> void C<T>::g() {} 1276 1277 class A { 1278 class B {}; 1279 void f(); 1280 }; 1281 1282 template void C<A::B>::f(); 1283 template <> void C<A::B>::g(); 1284 1285 void A::f() { 1286 C<B> cb; 1287 cb.f(); 1288 } 1289 } // namespace cwg182 1290 1291 namespace cwg183 { // cwg183: sup 382 1292 template<typename T> struct A {}; 1293 template<typename T> struct B { 1294 typedef int X; 1295 }; 1296 template<> struct A<int> { 1297 typename B<int>::X x; 1298 // cxx98-error@-1 {{'typename' occurs outside of a template}} 1299 }; 1300 } // namespace cwg183 1301 1302 namespace cwg184 { // cwg184: 2.7 1303 template<typename T = float> struct B {}; 1304 1305 template<template<typename TT = float> class T> struct A { 1306 void f(); 1307 void g(); 1308 }; 1309 1310 template<template<typename TT> class T> void A<T>::f() { // #cwg184-T 1311 T<> t; 1312 // expected-error@-1 {{too few template arguments for template template parameter 'T'}} 1313 // expected-note@#cwg184-T {{template is declared here}} 1314 } 1315 1316 template<template<typename TT = char> class T> void A<T>::g() { 1317 T<> t; 1318 typedef T<> X; 1319 typedef T<char> X; 1320 } 1321 1322 void h() { A<B>().g(); } 1323 } // namespace cwg184 1324 1325 // cwg185 is in cwg185.cpp 1326 1327 namespace cwg187 { // cwg187: sup 481 1328 const int Z = 1; 1329 template<int X = Z, int Z = X> struct A; 1330 typedef A<> T; 1331 typedef A<1, 1> T; 1332 } // namespace cwg187 1333 1334 namespace cwg188 { // cwg188: 2.7 1335 char c[10]; 1336 static_assert(sizeof(0, c) == 10, ""); 1337 } // namespace cwg188 1338 1339 namespace cwg190 { // cwg190: 19 1340 struct A { 1341 int a; 1342 static double x; 1343 int b; 1344 void y(); 1345 int c; 1346 }; 1347 1348 struct B { 1349 int a; 1350 void y(); 1351 int b; 1352 static double x; 1353 int c; 1354 }; 1355 1356 static_assert(__is_layout_compatible(A, B), ""); 1357 } // namespace cwg190 1358 1359 int cwg191_j; 1360 namespace cwg191 { // cwg191: 2.7 1361 namespace example1 { 1362 struct outer { 1363 static int i; 1364 struct inner { 1365 void f() { 1366 struct local { 1367 void g() { 1368 i = 5; 1369 } 1370 }; 1371 } 1372 }; 1373 }; 1374 } 1375 1376 namespace example2 { 1377 struct S { 1378 void f() { 1379 struct local2 { 1380 void g() { 1381 cwg191_j = 5; 1382 } 1383 }; 1384 } 1385 }; 1386 } 1387 } // namespace cwg191 1388 1389 namespace cwg192 { // cwg192: 2.7 1390 struct S { 1391 void f(I i) { } 1392 // expected-error@-1 {{unknown type name 'I'}} 1393 typedef int I; 1394 }; 1395 } // namespace cwg192 1396 1397 // cwg193 is in cwg193.cpp 1398 1399 namespace cwg194 { // cwg194: 2.7 1400 struct A { 1401 A(); 1402 void A(); 1403 // expected-error@-1 {{constructor cannot have a return type}} 1404 }; 1405 struct B { 1406 void B(); 1407 // expected-error@-1 {{constructor cannot have a return type}} 1408 B(); 1409 }; 1410 struct C { 1411 inline explicit C(int) {} 1412 }; 1413 } // namespace cwg194 1414 1415 namespace cwg195 { // cwg195: 2.7 1416 void f(); 1417 int *p = (int*)&f; 1418 // cxx98-error@-1 {{cast between pointer-to-function and pointer-to-object is an extension}} 1419 void (*q)() = (void(*)())&p; 1420 // cxx98-error@-1 {{cast between pointer-to-function and pointer-to-object is an extension}} 1421 } // namespace cwg195 1422 1423 namespace cwg197 { // cwg197: 2.7 1424 char &f(char); 1425 1426 template <class T> void g(T t) { 1427 char &a = f(1); 1428 char &b = f(T(1)); 1429 // expected-error@-1 {{non-const lvalue reference to type 'char' cannot bind to a value of unrelated type 'int'}} 1430 // expected-note@#cwg197-g-e-call {{in instantiation of function template specialization 'cwg197::g<cwg197::E>' requested here}} 1431 char &c = f(t); 1432 // expected-error@-1 {{non-const lvalue reference to type 'char' cannot bind to a value of unrelated type 'int'}} 1433 } 1434 1435 void f(int); 1436 1437 enum E { e }; 1438 int &f(E); 1439 1440 void h() { 1441 g('a'); 1442 g(2); 1443 g(e); // #cwg197-g-e-call 1444 } 1445 } // namespace cwg197 1446 1447 namespace cwg198 { // cwg198: 2.9 1448 struct A { 1449 int n; 1450 struct B { 1451 int m[sizeof(n)]; 1452 // cxx98-error@-1 {{invalid use of non-static data member 'n'}} 1453 int f() { return n; } 1454 // expected-error@-1 {{use of non-static data member 'n' of 'A' from nested type 'B'}} 1455 }; 1456 struct C; 1457 struct D; 1458 }; 1459 struct A::C { 1460 int m[sizeof(n)]; 1461 // cxx98-error@-1 {{invalid use of non-static data member 'n'}} 1462 int f() { return n; } 1463 // expected-error@-1 {{use of non-static data member 'n' of 'A' from nested type 'C'}} 1464 }; 1465 struct A::D : A { 1466 int m[sizeof(n)]; 1467 // cxx98-error@-1 {{invalid use of non-static data member 'n'}} 1468 int f() { return n; } 1469 }; 1470 } // namespace cwg198 1471 1472 // cwg199 is in cwg199.cpp 1473