1 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 3 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 4 // RUN: %clang_cc1 -std=c++1z -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 5 6 namespace dr100 { // dr100: yes 7 template<const char *> struct A {}; // expected-note 0-1{{declared here}} 8 template<const char (&)[4]> struct B {}; // expected-note 0-1{{declared here}} 9 A<"foo"> a; // expected-error {{does not refer to any declaration}} 10 B<"bar"> b; // expected-error {{does not refer to any declaration}} 11 } 12 13 namespace dr101 { // dr101: 3.5 14 extern "C" void dr101_f(); 15 typedef unsigned size_t; 16 namespace X { 17 extern "C" void dr101_f(); 18 typedef unsigned size_t; 19 } 20 using X::dr101_f; 21 using X::size_t; 22 extern "C" void dr101_f(); 23 typedef unsigned size_t; 24 } 25 26 namespace dr102 { // dr102: yes 27 namespace A { f(T a,T b)28 template<typename T> T f(T a, T b) { return a + b; } // expected-error {{neither visible in the template definition nor found by argument-dependent lookup}} 29 } 30 namespace B { 31 struct S {}; 32 } 33 B::S operator+(B::S, B::S); // expected-note {{should be declared prior to the call site or in namespace 'dr102::B'}} 34 template B::S A::f(B::S, B::S); // expected-note {{in instantiation of}} 35 } 36 37 // dr103: na 38 // dr104 FIXME: add codegen test 39 // dr105: na 40 41 namespace dr106 { // dr106: sup 540 42 typedef int &r1; 43 typedef r1 &r1; 44 typedef const r1 r1; // expected-warning {{has no effect}} 45 typedef const r1 &r1; // expected-warning {{has no effect}} 46 47 typedef const int &r2; 48 typedef r2 &r2; 49 typedef const r2 r2; // expected-warning {{has no effect}} 50 typedef const r2 &r2; // expected-warning {{has no effect}} 51 } 52 53 namespace dr107 { // dr107: yes 54 struct S {}; operator +(S,S)55 extern "C" S operator+(S, S) { return S(); } 56 } 57 58 namespace dr108 { // dr108: yes 59 template<typename T> struct A { 60 struct B { typedef int X; }; 61 B::X x; // expected-error {{missing 'typename'}} 62 struct C : B { X x; }; // expected-error {{unknown type name}} 63 }; 64 template<> struct A<int>::B { int X; }; 65 } 66 67 namespace dr109 { // dr109: yes 68 struct A { template<typename T> void f(T); }; 69 template<typename T> struct B : T { 70 using T::template f; // expected-error {{using declaration cannot refer to a template}} gdr109::B71 void g() { this->f<int>(123); } // expected-error {{use 'template'}} 72 }; 73 } 74 75 namespace dr111 { // dr111: dup 535 76 struct A { A(); A(volatile A&, int = 0); A(A&, const char * = "foo"); }; 77 struct B : A { B(); }; // expected-note +{{would lose const qualifier}} expected-note {{requires 0 arguments}} 78 const B b1; 79 B b2(b1); // expected-error {{no matching constructor}} 80 } 81 82 namespace dr112 { // dr112: yes 83 struct T { int n; }; 84 typedef T Arr[1]; 85 86 const T a1[1] = {}; 87 volatile T a2[1] = {}; 88 const Arr a3 = {}; 89 volatile Arr a4 = {}; 90 template<const volatile T*> struct X {}; 91 X<a1> x1; 92 X<a2> x2; 93 X<a3> x3; 94 X<a4> x4; 95 #if __cplusplus < 201103L 96 // expected-error@-5 {{internal linkage}} expected-note@-10 {{here}} 97 // expected-error@-4 {{internal linkage}} expected-note@-9 {{here}} 98 #else 99 // FIXME: Test this somehow. 100 #endif 101 } 102 103 namespace dr113 { // dr113: yes 104 extern void (*p)(); f()105 void f() { 106 no_such_function(); // expected-error {{undeclared}} 107 p(); 108 } 109 void g(); 110 void (*p)() = &g; 111 } 112 113 namespace dr114 { // dr114: yes 114 struct A { 115 virtual void f(int) = 0; // expected-note {{unimplemented}} 116 }; 117 struct B : A { 118 template<typename T> void f(T); gdr114::B119 void g() { f(0); } 120 } b; // expected-error {{abstract}} 121 } 122 123 namespace dr115 { // dr115: yes 124 template<typename T> int f(T); // expected-note +{{}} 125 template<typename T> int g(T); // expected-note +{{}} 126 template<typename T> int g(T, int); // expected-note +{{}} 127 128 int k1 = f(&f); // expected-error {{no match}} 129 int k2 = f(&f<int>); 130 int k3 = f(&g<int>); // expected-error {{no match}} 131 h()132 void h() { 133 (void)&f; // expected-error {{address of overloaded function 'f' cannot be cast to type 'void'}} 134 (void)&f<int>; 135 (void)&g<int>; // expected-error {{address of overloaded function 'g' cannot be cast to type 'void'}} 136 137 &f; // expected-error {{reference to overloaded function could not be resolved}} 138 &f<int>; // expected-warning {{unused}} 139 &g<int>; // expected-error {{reference to overloaded function could not be resolved}} 140 } 141 142 struct S { 143 template<typename T> static int f(T); 144 template<typename T> static int g(T); 145 template<typename T> static int g(T, int); 146 } s; 147 148 int k4 = f(&s.f); // expected-error {{non-constant pointer to member}} 149 int k5 = f(&s.f<int>); 150 int k6 = f(&s.g<int>); // expected-error {{non-constant pointer to member}} 151 i()152 void i() { 153 (void)&s.f; // expected-error {{non-constant pointer to member}} 154 (void)&s.f<int>; 155 (void)&s.g<int>; // expected-error {{non-constant pointer to member}} 156 157 &s.f; // expected-error {{non-constant pointer to member}} 158 &s.f<int>; // expected-warning {{unused}} 159 &s.g<int>; // expected-error {{non-constant pointer to member}} 160 } 161 162 struct T { 163 template<typename T> int f(T); 164 template<typename T> int g(T); 165 template<typename T> int g(T, int); 166 } t; 167 168 int k7 = f(&s.f); // expected-error {{non-constant pointer to member}} 169 int k8 = f(&s.f<int>); 170 int k9 = f(&s.g<int>); // expected-error {{non-constant pointer to member}} 171 j()172 void j() { 173 (void)&s.f; // expected-error {{non-constant pointer to member}} 174 (void)&s.f<int>; 175 (void)&s.g<int>; // expected-error {{non-constant pointer to member}} 176 177 &s.f; // expected-error {{non-constant pointer to member}} 178 &s.f<int>; // expected-warning {{unused}} 179 &s.g<int>; // expected-error {{non-constant pointer to member}} 180 } 181 182 #if __cplusplus >= 201103L 183 // Special case kicks in only if a template argument list is specified. 184 template<typename T=int> void with_default(); // expected-note +{{}} 185 int k10 = f(&with_default); // expected-error {{no matching function}} 186 int k11 = f(&with_default<>); k()187 void k() { 188 (void)&with_default; // expected-error {{overloaded function}} 189 (void)&with_default<>; 190 &with_default; // expected-error {{overloaded function}} 191 &with_default<>; // expected-warning {{unused}} 192 } 193 #endif 194 } 195 196 namespace dr116 { // dr116: yes 197 template<int> struct A {}; f(A<N>)198 template<int N> void f(A<N>) {} // expected-note {{previous}} f(A<M>)199 template<int M> void f(A<M>) {} // expected-error {{redefinition}} f(A<sizeof (T)>)200 template<typename T> void f(A<sizeof(T)>) {} // expected-note {{previous}} f(A<sizeof (U)>)201 template<typename U> void f(A<sizeof(U)>) {} // expected-error {{redefinition}} 202 } 203 204 // dr117: na 205 // dr118 FIXME: add codegen test 206 // dr119: na 207 // dr120: na 208 209 namespace dr121 { // dr121: yes 210 struct X { 211 template<typename T> struct Y {}; 212 }; 213 template<typename T> struct Z { 214 X::Y<T> x; 215 T::Y<T> y; // expected-error +{{}} 216 }; 217 Z<X> z; 218 } 219 220 namespace dr122 { // dr122: yes 221 template<typename T> void f(); g()222 void g() { f<int>(); } 223 } 224 225 // dr123: na 226 // dr124: dup 201 227 228 // dr125: yes 229 struct dr125_A { struct dr125_B {}; }; // expected-note {{here}} 230 dr125_A::dr125_B dr125_C(); 231 namespace dr125_B { dr125_A dr125_C(); } 232 namespace dr125 { 233 struct X { 234 friend dr125_A::dr125_B (::dr125_C)(); // ok 235 friend dr125_A (::dr125_B::dr125_C)(); // ok 236 friend dr125_A::dr125_B::dr125_C(); // expected-error {{did you mean the constructor name 'dr125_B'?}} 237 // expected-warning@-1 {{missing exception specification}} 238 #if __cplusplus >= 201103L 239 // expected-error@-3 {{follows constexpr declaration}} expected-note@-10 {{here}} 240 #endif 241 }; 242 } 243 244 namespace dr126 { // dr126: no 245 struct C {}; 246 struct D : C {}; 247 struct E : private C { friend class A; friend class B; }; 248 struct F : protected C {}; 249 struct G : C {}; 250 struct H : D, G {}; 251 252 struct A { 253 virtual void cp() throw(C*); 254 virtual void dp() throw(C*); 255 virtual void ep() throw(C*); // expected-note {{overridden}} 256 virtual void fp() throw(C*); // expected-note {{overridden}} 257 virtual void gp() throw(C*); 258 virtual void hp() throw(C*); // expected-note {{overridden}} 259 260 virtual void cr() throw(C&); 261 virtual void dr() throw(C&); 262 virtual void er() throw(C&); // expected-note {{overridden}} 263 virtual void fr() throw(C&); // expected-note {{overridden}} 264 virtual void gr() throw(C&); 265 virtual void hr() throw(C&); // expected-note {{overridden}} 266 267 virtual void pv() throw(void*); // expected-note {{overridden}} 268 269 #if __cplusplus >= 201103L 270 virtual void np() throw(C*); // expected-note {{overridden}} 271 virtual void npm() throw(int C::*); // expected-note {{overridden}} 272 virtual void nr() throw(C&); // expected-note {{overridden}} 273 #endif 274 275 virtual void ref1() throw(C *const&); 276 virtual void ref2() throw(C *); 277 278 virtual void v() throw(int); 279 virtual void w() throw(const int); 280 virtual void x() throw(int*); 281 virtual void y() throw(const int*); 282 virtual void z() throw(int); // expected-note {{overridden}} 283 }; 284 struct B : A { 285 virtual void cp() throw(C*); 286 virtual void dp() throw(D*); 287 virtual void ep() throw(E*); // expected-error {{more lax}} 288 virtual void fp() throw(F*); // expected-error {{more lax}} 289 virtual void gp() throw(G*); 290 virtual void hp() throw(H*); // expected-error {{more lax}} 291 292 virtual void cr() throw(C&); 293 virtual void dr() throw(D&); 294 virtual void er() throw(E&); // expected-error {{more lax}} 295 virtual void fr() throw(F&); // expected-error {{more lax}} 296 virtual void gr() throw(G&); 297 virtual void hr() throw(H&); // expected-error {{more lax}} 298 299 virtual void pv() throw(C*); // expected-error {{more lax}} FIXME: This is valid. 300 301 #if __cplusplus >= 201103L 302 using nullptr_t = decltype(nullptr); 303 virtual void np() throw(nullptr_t*); // expected-error {{more lax}} FIXME: This is valid. 304 virtual void npm() throw(nullptr_t*); // expected-error {{more lax}} FIXME: This is valid. 305 virtual void nr() throw(nullptr_t&); // expected-error {{more lax}} This is not. 306 #endif 307 308 virtual void ref1() throw(D *const &); 309 virtual void ref2() throw(D *); 310 311 virtual void v() throw(const int); 312 virtual void w() throw(int); 313 virtual void x() throw(const int*); // FIXME: 'const int*' is not allowed by A::h. 314 virtual void y() throw(int*); // ok 315 virtual void z() throw(long); // expected-error {{more lax}} 316 }; 317 } 318 319 namespace dr127 { // dr127: yes 320 __extension__ typedef __decltype(sizeof(0)) size_t; 321 template<typename T> struct A { 322 A() throw(int); 323 void *operator new(size_t, const char * = 0); operator deletedr127::A324 void operator delete(void *, const char *) { T::error; } // expected-error 2{{no members}} operator deletedr127::A325 void operator delete(void *) { T::error; } 326 }; 327 A<void> *p = new A<void>; // expected-note {{instantiat}} 328 A<int> *q = new ("") A<int>; // expected-note {{instantiat}} 329 } 330 331 namespace dr128 { // dr128: yes 332 enum E1 { e1 } x = e1; 333 enum E2 { e2 } y = static_cast<E2>(x), z = static_cast<E2>(e1); 334 } 335 336 // dr129: dup 616 337 // dr130: na 338 339 namespace dr131 { // dr131: yes 340 const char *a_with_\u0e8c = "\u0e8c"; 341 const char *b_with_\u0e8d = "\u0e8d"; 342 const char *c_with_\u0e8e = "\u0e8e"; 343 #if __cplusplus < 201103L 344 // expected-error@-4 {{expected ';'}} expected-error@-2 {{expected ';'}} 345 #endif 346 } 347 348 namespace dr132 { // dr132: no f()349 void f() { 350 extern struct {} x; // ok 351 extern struct S {} y; // FIXME: This is invalid. 352 } 353 static enum { E } e; 354 } 355 356 // dr133: dup 87 357 // dr134: na 358 359 namespace dr135 { // dr135: yes 360 struct A { fdr135::A361 A f(A a) { return a; } g(A a)362 friend A g(A a) { return a; } hdr135::A363 static A h(A a) { return a; } 364 }; 365 } 366 367 namespace dr136 { // dr136: 3.4 368 void f(int, int, int = 0); // expected-note {{previous declaration is here}} 369 void g(int, int, int); // expected-note {{previous declaration is here}} 370 struct A { 371 friend void f(int, int = 0, int); // expected-error {{friend declaration specifying a default argument must be the only declaration}} 372 friend void g(int, int, int = 0); // expected-error {{friend declaration specifying a default argument must be the only declaration}} 373 friend void h(int, int, int = 0); // expected-error {{friend declaration specifying a default argument must be a definition}} i(int,int,int=0)374 friend void i(int, int, int = 0) {} // expected-note {{previous declaration is here}} j(int,int,int=0)375 friend void j(int, int, int = 0) {} 376 operator int(); 377 }; 378 void i(int, int, int); // expected-error {{friend declaration specifying a default argument must be the only declaration}} q()379 void q() { 380 j(A(), A()); // ok, has default argument 381 } 382 extern "C" void k(int, int, int, int); // expected-note {{previous declaration is here}} 383 namespace NSA { 384 struct A { 385 friend void dr136::k(int, int, int, int = 0); // expected-error {{friend declaration specifying a default argument must be the only declaration}} \ 386 // expected-note {{previous declaration is here}} 387 }; 388 } 389 namespace NSB { 390 struct A { 391 friend void dr136::k(int, int, int = 0, int); // expected-error {{friend declaration specifying a default argument must be the only declaration}} 392 }; 393 } 394 struct B { 395 void f(int); // expected-note {{previous declaration is here}} 396 }; 397 struct C { 398 friend void B::f(int = 0); // expected-error {{friend declaration specifying a default argument must be the only declaration}} 399 }; 400 } 401 402 namespace dr137 { // dr137: yes 403 extern void *p; 404 extern const void *cp; 405 extern volatile void *vp; 406 extern const volatile void *cvp; 407 int *q = static_cast<int*>(p); 408 int *qc = static_cast<int*>(cp); // expected-error {{casts away qualifiers}} 409 int *qv = static_cast<int*>(vp); // expected-error {{casts away qualifiers}} 410 int *qcv = static_cast<int*>(cvp); // expected-error {{casts away qualifiers}} 411 const int *cq = static_cast<const int*>(p); 412 const int *cqc = static_cast<const int*>(cp); 413 const int *cqv = static_cast<const int*>(vp); // expected-error {{casts away qualifiers}} 414 const int *cqcv = static_cast<const int*>(cvp); // expected-error {{casts away qualifiers}} 415 const volatile int *cvq = static_cast<const volatile int*>(p); 416 const volatile int *cvqc = static_cast<const volatile int*>(cp); 417 const volatile int *cvqv = static_cast<const volatile int*>(vp); 418 const volatile int *cvqcv = static_cast<const volatile int*>(cvp); 419 } 420 421 namespace dr139 { // dr139: yes 422 namespace example1 { 423 typedef int f; // expected-note {{previous}} 424 struct A { 425 friend void f(A &); // expected-error {{different kind of symbol}} 426 }; 427 } 428 429 namespace example2 { 430 typedef int f; 431 namespace N { 432 struct A { 433 friend void f(A &); 434 operator int(); gdr139::example2::N::A435 void g(A a) { int i = f(a); } // ok, f is typedef not friend function 436 }; 437 } 438 } 439 } 440 441 namespace dr140 { // dr140: yes f(int * const)442 void f(int *const) {} // expected-note {{previous}} f(int[3])443 void f(int[3]) {} // expected-error {{redefinition}} 444 void g(const int); g(int n)445 void g(int n) { n = 2; } 446 } 447 448 namespace dr141 { // dr141: yes 449 template<typename T> void f(); 450 template<typename T> struct S { int n; }; 451 struct A : S<int> { 452 template<typename T> void f(); 453 template<typename T> struct S {}; 454 } a; 455 struct B : S<int> {} b; g()456 void g() { 457 a.f<int>(); 458 (void)a.S<int>::n; // expected-error {{no member named 'n'}} 459 #if __cplusplus < 201103L 460 // expected-error@-2 {{ambiguous}} 461 // expected-note@-11 {{lookup from the current scope}} 462 // expected-note@-9 {{lookup in the object type}} 463 #endif 464 b.f<int>(); // expected-error {{no member}} expected-error +{{}} 465 (void)b.S<int>::n; 466 } 467 template<typename T> struct C { 468 T t; gdr141::C469 void g() { 470 t.f<int>(); // expected-error {{use 'template'}} 471 } hdr141::C472 void h() { 473 (void)t.S<int>::n; // ok 474 } idr141::C475 void i() { 476 (void)t.S<int>(); // ok! 477 } 478 }; h()479 void h() { C<B>().h(); } // ok 480 struct X { 481 template<typename T> void S(); 482 }; i()483 void i() { C<X>().i(); } // ok!! 484 } 485 486 namespace dr142 { // dr142: yes 487 class B { // expected-note +{{here}} 488 public: 489 int mi; // expected-note +{{here}} 490 static int si; // expected-note +{{here}} 491 }; 492 class D : private B { // expected-note +{{here}} 493 }; 494 class DD : public D { 495 void f(); 496 }; f()497 void DD::f() { 498 mi = 3; // expected-error {{private base class}} expected-error {{private member}} 499 si = 3; // expected-error {{private member}} 500 B b_old; // expected-error {{private member}} 501 dr142::B b; 502 b.mi = 3; 503 b.si = 3; 504 B::si = 3; // expected-error {{private member}} 505 dr142::B::si = 3; 506 B *bp1_old = this; // expected-error {{private member}} expected-error {{private base class}} 507 dr142::B *bp1 = this; // expected-error {{private base class}} 508 B *bp2_old = (B*)this; // expected-error 2{{private member}} 509 dr142::B *bp2 = (dr142::B*)this; 510 bp2->mi = 3; 511 } 512 } 513 514 namespace dr143 { // dr143: yes 515 namespace A { struct X; } 516 namespace B { void f(A::X); } 517 namespace A { 518 struct X { friend void B::f(X); }; 519 } g(A::X x)520 void g(A::X x) { 521 f(x); // expected-error {{undeclared identifier 'f'}} 522 } 523 } 524 525 namespace dr145 { // dr145: yes f(bool b)526 void f(bool b) { 527 ++b; // expected-warning {{deprecated}} 528 b++; // expected-warning {{deprecated}} 529 } 530 } 531 532 namespace dr147 { // dr147: no 533 namespace example1 { 534 template<typename> struct A { 535 template<typename T> A(T); 536 }; 537 // FIXME: This appears to be valid, and EDG and G++ accept. A(int)538 template<> template<> A<int>::A<int>(int) {} // expected-error {{out-of-line constructor for 'A' cannot have template arguments}} 539 } 540 namespace example2 { 541 struct A { A(); }; 542 struct B : A { B(); }; 543 A::A a1; // expected-error {{is a constructor}} 544 B::A a2; 545 } 546 namespace example3 { 547 template<typename> struct A { 548 template<typename T> A(T); 549 static A a; 550 }; 551 template<> A<int>::A<int>(A<int>::a); // expected-error {{is a constructor}} 552 } 553 } 554 555 namespace dr148 { // dr148: yes 556 struct A { int A::*p; }; 557 int check1[__is_pod(int(A::*)) ? 1 : -1]; 558 int check2[__is_pod(A) ? 1 : -1]; 559 } 560 561 // dr149: na 562 563 namespace dr151 { // dr151: yes 564 struct X {}; 565 typedef int X::*p; 566 #if __cplusplus < 201103L 567 #define fold(x) (__builtin_constant_p(0) ? (x) : (x)) 568 #else 569 #define fold 570 #endif 571 int check[fold(p() == 0) ? 1 : -1]; 572 #undef fold 573 } 574 575 namespace dr152 { // dr152: yes 576 struct A { 577 A(); // expected-note {{not viable}} 578 explicit A(const A&); 579 }; 580 A a1 = A(); // expected-error {{no matching constructor}} 581 A a2((A())); 582 } 583 584 // dr153: na 585 586 namespace dr154 { // dr154: yes 587 union { int a; }; // expected-error {{must be declared 'static'}} 588 namespace { 589 union { int b; }; 590 } 591 static union { int c; }; 592 } 593 594 namespace dr155 { // dr155: dup 632 595 struct S { int n; } s = { { 1 } }; // expected-warning {{braces around scalar initializer}} 596 } 597 598 // dr158 FIXME write codegen test 599 600 namespace dr159 { // dr159: 3.5 601 namespace X { void f(); } 602 void f(); f()603 void dr159::f() {} // expected-warning {{extra qualification}} f()604 void dr159::X::f() {} 605 } 606 607 // dr160: na 608 609 namespace dr161 { // dr161: yes 610 class A { 611 protected: 612 struct B { int n; } b; // expected-note 2{{here}} 613 static B bs; 614 void f(); // expected-note {{here}} 615 static void sf(); 616 }; 617 struct C : A {}; 618 struct D : A { gdr161::D619 void g(C c) { 620 (void)b.n; 621 B b1; 622 C::B b2; // ok, accessible as a member of A 623 (void)&C::b; // expected-error {{protected}} 624 (void)&C::bs; 625 (void)c.b; // expected-error {{protected}} 626 (void)c.bs; 627 f(); 628 sf(); 629 c.f(); // expected-error {{protected}} 630 c.sf(); 631 A::f(); 632 D::f(); 633 A::sf(); 634 C::sf(); 635 D::sf(); 636 } 637 }; 638 } 639 640 namespace dr162 { // dr162: no 641 struct A { 642 char &f(char); 643 static int &f(int); 644 gdr162::A645 void g() { 646 int &a = (&A::f)(0); // FIXME: expected-error {{could not be resolved}} 647 char &b = (&A::f)('0'); // expected-error {{could not be resolved}} 648 } 649 }; 650 651 int &c = (&A::f)(0); // FIXME: expected-error {{could not be resolved}} 652 char &d = (&A::f)('0'); // expected-error {{could not be resolved}} 653 } 654 655 // dr163: na 656 657 namespace dr164 { // dr164: yes 658 void f(int); g(T t)659 template <class T> int g(T t) { return f(t); } 660 661 enum E { e }; 662 int f(E); 663 664 int k = g(e); 665 } 666 667 namespace dr165 { // dr165: no 668 namespace N { 669 struct A { friend struct B; }; f()670 void f() { void g(); } 671 } 672 // FIXME: dr1477 says this is ok, dr165 says it's ill-formed 673 struct N::B {}; 674 // FIXME: dr165 says this is ill-formed, but the argument in dr1477 says it's ok g()675 void N::g() {} 676 } 677 678 namespace dr166 { // dr166: yes 679 namespace A { class X; } 680 f(T t)681 template<typename T> int f(T t) { return t.n; } 682 int g(A::X); h(T t)683 template<typename T> int h(T t) { return t.n; } // expected-error {{private}} 684 int i(A::X); 685 686 namespace A { 687 class X { 688 friend int f<X>(X); 689 friend int dr166::g(X); 690 friend int h(X); 691 friend int i(X); 692 int n; // expected-note 2{{here}} 693 }; 694 h(X x)695 int h(X x) { return x.n; } i(X x)696 int i(X x) { return x.n; } 697 } 698 699 template int f(A::X); g(A::X x)700 int g(A::X x) { return x.n; } 701 template int h(A::X); // expected-note {{instantiation}} i(A::X x)702 int i(A::X x) { return x.n; } // expected-error {{private}} 703 } 704 705 // dr167: sup 1012 706 707 namespace dr168 { // dr168: no 708 extern "C" typedef int (*p)(); 709 extern "C++" typedef int (*q)(); 710 struct S { 711 static int f(); 712 }; 713 p a = &S::f; // FIXME: this should fail. 714 q b = &S::f; 715 } 716 717 namespace dr169 { // dr169: yes 718 template<typename> struct A { int n; }; 719 struct B { 720 template<typename> struct C; 721 template<typename> void f(); 722 template<typename> static int n; // expected-error 0-1{{extension}} 723 }; 724 struct D : A<int>, B { 725 using A<int>::n; 726 using B::C<int>; // expected-error {{using declaration cannot refer to a template specialization}} 727 using B::f<int>; // expected-error {{using declaration cannot refer to a template specialization}} 728 using B::n<int>; // expected-error {{using declaration cannot refer to a template specialization}} 729 }; 730 } 731 732 namespace { // dr171: yes 733 int dr171a; 734 } 735 int dr171b; // expected-note {{here}} 736 namespace dr171 { 737 extern "C" void dr171a(); 738 extern "C" void dr171b(); // expected-error {{conflicts}} 739 } 740 741 namespace dr172 { // dr172: yes 742 enum { zero }; 743 int check1[-1 < zero ? 1 : -1]; 744 745 enum { x = -1, y = (unsigned int)-1 }; 746 int check2[sizeof(x) > sizeof(int) ? 1 : -1]; 747 748 enum { a = (unsigned int)-1 / 2 }; 749 int check3a[sizeof(a) == sizeof(int) ? 1 : -1]; 750 int check3b[-a < 0 ? 1 : -1]; 751 752 enum { b = (unsigned int)-1 / 2 + 1 }; 753 int check4a[sizeof(b) == sizeof(unsigned int) ? 1 : -1]; 754 int check4b[-b > 0 ? 1 : -1]; 755 756 enum { c = (unsigned long)-1 / 2 }; 757 int check5a[sizeof(c) == sizeof(long) ? 1 : -1]; 758 int check5b[-c < 0 ? 1 : -1]; 759 760 enum { d = (unsigned long)-1 / 2 + 1 }; 761 int check6a[sizeof(d) == sizeof(unsigned long) ? 1 : -1]; 762 int check6b[-d > 0 ? 1 : -1]; 763 764 enum { e = (unsigned long long)-1 / 2 }; // expected-error 0-1{{extension}} 765 int check7a[sizeof(e) == sizeof(long) ? 1 : -1]; // expected-error 0-1{{extension}} 766 int check7b[-e < 0 ? 1 : -1]; 767 768 enum { f = (unsigned long long)-1 / 2 + 1 }; // expected-error 0-1{{extension}} 769 int check8a[sizeof(f) == sizeof(unsigned long) ? 1 : -1]; // expected-error 0-1{{extension}} 770 int check8b[-f > 0 ? 1 : -1]; 771 } 772 773 namespace dr173 { // dr173: yes 774 int check[('0' + 1 == '1' && '0' + 2 == '2' && '0' + 3 == '3' && 775 '0' + 4 == '4' && '0' + 5 == '5' && '0' + 6 == '6' && 776 '0' + 7 == '7' && '0' + 8 == '8' && '0' + 9 == '9') ? 1 : -1]; 777 } 778 779 // dr174: sup 1012 780 781 namespace dr175 { // dr175: yes 782 struct A {}; // expected-note {{here}} 783 struct B : private A {}; // expected-note {{constrained by private inheritance}} 784 struct C : B { 785 A a; // expected-error {{private}} 786 dr175::A b; 787 }; 788 } 789 790 namespace dr176 { // dr176: yes 791 template<typename T> class Y; 792 template<> class Y<int> { f()793 void f() { 794 typedef Y A; // expected-note {{here}} 795 typedef Y<char> A; // expected-error {{different types ('Y<char>' vs 'Y<int>')}} 796 } 797 }; 798 799 template<typename T> struct Base {}; // expected-note 2{{found}} 800 template<typename T> struct Derived : public Base<T> { fdr176::Derived801 void f() { 802 typedef typename Derived::template Base<T> A; 803 typedef typename Derived::Base A; 804 } 805 }; 806 template struct Derived<int>; 807 808 template<typename T> struct Derived2 : Base<int>, Base<char> { 809 typename Derived2::Base b; // expected-error {{found in multiple base classes}} 810 typename Derived2::Base<double> d; 811 }; 812 813 template<typename T> class X { // expected-note {{here}} 814 X *p1; 815 X<T> *p2; 816 X<int> *p3; 817 dr176::X *p4; // expected-error {{requires template arguments}} 818 }; 819 } 820 821 namespace dr177 { // dr177: yes 822 struct B {}; 823 struct A { 824 A(A &); // expected-note {{not viable: expects an l-value}} 825 A(const B &); 826 }; 827 B b; 828 A a = b; // expected-error {{no viable constructor copying variable}} 829 } 830 831 namespace dr178 { // dr178: yes 832 int check[int() == 0 ? 1 : -1]; 833 #if __cplusplus >= 201103L 834 static_assert(int{} == 0, ""); 835 struct S { int a, b; }; 836 static_assert(S{1}.b == 0, ""); Tdr178::T837 struct T { constexpr T() : n() {} int n; }; 838 static_assert(T().n == 0, ""); Udr178::U839 struct U : S { constexpr U() : S() {} }; 840 static_assert(U().b == 0, ""); 841 #endif 842 } 843 844 namespace dr179 { // dr179: yes 845 void f(); 846 int n = &f - &f; // expected-error {{arithmetic on pointers to the function type 'void ()'}} 847 } 848 849 namespace dr180 { // dr180: yes 850 template<typename T> struct X : T, T::some_base { Xdr180::X851 X() : T::some_type_that_might_be_T(), T::some_base() {} 852 friend class T::some_class; fdr180::X853 void f() { 854 enum T::some_enum e; 855 } 856 }; 857 } 858 859 namespace dr181 { // dr181: yes 860 namespace X { 861 template <template X<class T> > struct A { }; // expected-error +{{}} 862 template <template X<class T> > void f(A<X>) { } // expected-error +{{}} 863 } 864 865 namespace Y { 866 template <template <class T> class X> struct A { }; 867 template <template <class T> class X> void f(A<X>) { } 868 } 869 } 870 871 namespace dr182 { // dr182: yes 872 template <class T> struct C { 873 void f(); 874 void g(); 875 }; 876 877 template <class T> void C<T>::f() {} 878 template <class T> void C<T>::g() {} 879 880 class A { 881 class B {}; // expected-note {{here}} 882 void f(); 883 }; 884 885 template void C<A::B>::f(); 886 template <> void C<A::B>::g(); // expected-error {{private}} 887 888 void A::f() { 889 C<B> cb; 890 cb.f(); 891 } 892 } 893 894 namespace dr183 { // dr183: sup 382 895 template<typename T> struct A {}; 896 template<typename T> struct B { 897 typedef int X; 898 }; 899 template<> struct A<int> { 900 typename B<int>::X x; 901 }; 902 } 903 904 namespace dr184 { // dr184: yes 905 template<typename T = float> struct B {}; 906 907 template<template<typename TT = float> class T> struct A { 908 void f(); 909 void g(); 910 }; 911 912 template<template<typename TT> class T> void A<T>::f() { // expected-note {{here}} 913 T<> t; // expected-error {{too few template arguments}} 914 } 915 916 template<template<typename TT = char> class T> void A<T>::g() { 917 T<> t; 918 typedef T<> X; 919 typedef T<char> X; 920 } 921 922 void h() { A<B>().g(); } 923 } 924 925 // dr185 FIXME: add codegen test 926 927 namespace dr187 { // dr187: sup 481 928 const int Z = 1; 929 template<int X = Z, int Z = X> struct A; 930 typedef A<> T; 931 typedef A<1, 1> T; 932 } 933 934 namespace dr188 { // dr188: yes 935 char c[10]; 936 int check[sizeof(0, c) == 10 ? 1 : -1]; 937 } 938 939 // dr190 FIXME: add codegen test for tbaa 940 941 // dr193 FIXME: add codegen test 942 943 namespace dr194 { // dr194: yes 944 struct A { 945 A(); 946 void A(); // expected-error {{has the same name as its class}} expected-error {{constructor cannot have a return type}} 947 }; 948 struct B { 949 void B(); // expected-error {{has the same name as its class}} expected-error {{constructor cannot have a return type}} 950 B(); 951 }; 952 struct C { 953 inline explicit C(int) {} 954 }; 955 } 956 957 namespace dr195 { // dr195: yes 958 void f(); 959 int *p = (int*)&f; // expected-error 0-1{{extension}} 960 void (*q)() = (void(*)())&p; // expected-error 0-1{{extension}} 961 } 962 963 namespace dr197 { // dr197: yes 964 char &f(char); 965 966 template <class T> void g(T t) { 967 char &a = f(1); 968 char &b = f(T(1)); // expected-error {{unrelated type 'int'}} 969 char &c = f(t); // expected-error {{unrelated type 'int'}} 970 } 971 972 void f(int); 973 974 enum E { e }; 975 int &f(E); 976 977 void h() { 978 g('a'); 979 g(2); 980 g(e); // expected-note {{in instantiation of}} 981 } 982 } 983 984 namespace dr198 { // dr198: yes 985 struct A { 986 int n; 987 struct B { 988 int m[sizeof(n)]; 989 #if __cplusplus < 201103L 990 // expected-error@-2 {{invalid use of non-static data member}} 991 #endif 992 int f() { return n; } 993 // expected-error@-1 {{use of non-static data member 'n' of 'A' from nested type 'B'}} 994 }; 995 struct C; 996 struct D; 997 }; 998 struct A::C { 999 int m[sizeof(n)]; 1000 #if __cplusplus < 201103L 1001 // expected-error@-2 {{invalid use of non-static data member}} 1002 #endif 1003 int f() { return n; } 1004 // expected-error@-1 {{use of non-static data member 'n' of 'A' from nested type 'C'}} 1005 }; 1006 struct A::D : A { 1007 int m[sizeof(n)]; 1008 #if __cplusplus < 201103L 1009 // expected-error@-2 {{invalid use of non-static data member}} 1010 #endif 1011 int f() { return n; } 1012 }; 1013 } 1014 1015 // dr199 FIXME: add codegen test 1016