dr0xx.cpp revision 87b12b2e92c1670e551d66938a4c0a055b18b03a
1// RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -Wno-bind-to-temporary-copy 2// RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 3// RUN: %clang_cc1 -std=c++1y %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 4 5namespace dr1 { // dr1: no 6 namespace X { extern "C" void dr1_f(int a = 1); } 7 namespace Y { extern "C" void dr1_f(int a = 2); } 8 using X::dr1_f; using Y::dr1_f; 9 void g() { 10 dr1_f(0); 11 // FIXME: This should be rejected, due to the ambiguous default argument. 12 dr1_f(); 13 } 14 namespace X { 15 using Y::dr1_f; 16 void h() { 17 dr1_f(0); 18 // FIXME: This should be rejected, due to the ambiguous default argument. 19 dr1_f(); 20 } 21 } 22 23 namespace X { 24 void z(int); 25 } 26 void X::z(int = 1) {} // expected-note {{previous}} 27 namespace X { 28 void z(int = 2); // expected-error {{redefinition of default argument}} 29 } 30} 31 32namespace dr3 { // dr3: yes 33 template<typename T> struct A {}; 34 template<typename T> void f(T) { A<T> a; } // expected-note {{implicit instantiation}} 35 template void f(int); 36 template<> struct A<int> {}; // expected-error {{explicit specialization of 'dr3::A<int>' after instantiation}} 37} 38 39namespace dr4 { // dr4: yes 40 extern "C" { 41 static void dr4_f(int) {} 42 static void dr4_f(float) {} 43 void dr4_g(int) {} // expected-note {{previous}} 44 void dr4_g(float) {} // expected-error {{conflicting types}} 45 } 46} 47 48namespace dr5 { // dr5: yes 49 struct A {} a; 50 struct B { 51 B(const A&); 52 B(const B&); 53 }; 54 const volatile B b = a; 55 56 struct C { C(C&); }; 57 struct D : C {}; 58 struct E { operator D&(); } e; 59 const C c = e; 60} 61 62namespace dr7 { // dr7: yes 63 class A { public: ~A(); }; 64 class B : virtual private A {}; // expected-note 2 {{declared private here}} 65 class C : public B {} c; // expected-error 2 {{inherited virtual base class 'dr7::A' has private destructor}} \ 66 // expected-note {{implicit default constructor for 'dr7::C' first required here}} \ 67 // expected-note {{implicit destructor for 'dr7::C' first required here}} 68 class VeryDerivedC : public B, virtual public A {} vdc; 69 70 class X { ~X(); }; // expected-note {{here}} 71 class Y : X { ~Y() {} }; // expected-error {{private destructor}} 72 73 namespace PR16370 { // This regressed the first time DR7 was fixed. 74 struct S1 { virtual ~S1(); }; 75 struct S2 : S1 {}; 76 struct S3 : S2 {}; 77 struct S4 : virtual S2 {}; 78 struct S5 : S3, S4 { 79 S5(); 80 ~S5(); 81 }; 82 S5::S5() {} 83 } 84} 85 86namespace dr8 { // dr8: dup 45 87 class A { 88 struct U; 89 static const int k = 5; 90 void f(); 91 template<typename, int, void (A::*)()> struct T; 92 93 T<U, k, &A::f> *g(); 94 }; 95 A::T<A::U, A::k, &A::f> *A::g() { return 0; } 96} 97 98namespace dr9 { // dr9: yes 99 struct B { 100 protected: 101 int m; // expected-note {{here}} 102 friend int R1(); 103 }; 104 struct N : protected B { // expected-note 2{{protected}} 105 friend int R2(); 106 } n; 107 int R1() { return n.m; } // expected-error {{protected base class}} expected-error {{protected member}} 108 int R2() { return n.m; } 109} 110 111namespace dr10 { // dr10: dup 45 112 class A { 113 struct B { 114 A::B *p; 115 }; 116 }; 117} 118 119namespace dr11 { // dr11: yes 120 template<typename T> struct A : T { 121 using typename T::U; 122 U u; 123 }; 124 template<typename T> struct B : T { 125 using T::V; 126 V v; // expected-error {{unknown type name}} 127 }; 128 struct X { typedef int U; }; 129 A<X> ax; 130} 131 132namespace dr12 { // dr12: sup 239 133 enum E { e }; 134 E &f(E, E = e); 135 void g() { 136 int &f(int, E = e); 137 // Under DR12, these call two different functions. 138 // Under DR239, they call the same function. 139 int &b = f(e); 140 int &c = f(1); 141 } 142} 143 144namespace dr14 { // dr14: yes 145 namespace X { extern "C" int dr14_f(); } 146 namespace Y { extern "C" int dr14_f(); } 147 using namespace X; 148 using namespace Y; 149 int k = dr14_f(); 150 151 class C { 152 int k; 153 friend int Y::dr14_f(); 154 } c; 155 namespace Z { 156 extern "C" int dr14_f() { return c.k; } 157 } 158 159 namespace X { typedef int T; typedef int U; } // expected-note {{candidate}} 160 namespace Y { typedef int T; typedef long U; } // expected-note {{candidate}} 161 T t; // ok, same type both times 162 U u; // expected-error {{ambiguous}} 163} 164 165namespace dr15 { // dr15: yes 166 template<typename T> void f(int); // expected-note {{previous}} 167 template<typename T> void f(int = 0); // expected-error {{default arguments cannot be added}} 168} 169 170namespace dr16 { // dr16: yes 171 class A { // expected-note {{here}} 172 void f(); // expected-note {{here}} 173 friend class C; 174 }; 175 class B : A {}; // expected-note 4{{here}} 176 class C : B { 177 void g() { 178 f(); // expected-error {{private member}} expected-error {{private base}} 179 A::f(); // expected-error {{private member}} expected-error {{private base}} 180 } 181 }; 182} 183 184namespace dr17 { // dr17: yes 185 class A { 186 int n; 187 int f(); 188 struct C; 189 }; 190 struct B : A {} b; 191 int A::f() { return b.n; } 192 struct A::C : A { 193 int g() { return n; } 194 }; 195} 196 197namespace dr18 { // dr18: yes 198 typedef void Void; 199 void f(Void); // expected-error {{empty parameter list defined with a typedef of 'void'}} 200} 201 202namespace dr19 { // dr19: yes 203 struct A { 204 int n; // expected-note {{here}} 205 }; 206 struct B : protected A { // expected-note {{here}} 207 }; 208 struct C : B {} c; 209 struct D : B { 210 int get1() { return c.n; } // expected-error {{protected member}} 211 int get2() { return ((A&)c).n; } // ok, A is an accessible base of B from here 212 }; 213} 214 215namespace dr20 { // dr20: yes 216 class X { 217 public: 218 X(); 219 private: 220 X(const X&); // expected-note {{here}} 221 }; 222 X f(); 223 X x = f(); // expected-error {{private}} 224} 225 226namespace dr21 { // dr21: yes 227 template<typename T> struct A; 228 struct X { 229 template<typename T = int> friend struct A; // expected-error {{default template argument not permitted on a friend template}} 230 template<typename T = int> friend struct B; // expected-error {{default template argument not permitted on a friend template}} 231 }; 232} 233 234namespace dr22 { // dr22: sup 481 235 template<typename dr22_T = dr22_T> struct X; // expected-error {{unknown type name 'dr22_T'}} 236 typedef int T; 237 template<typename T = T> struct Y; 238} 239 240namespace dr23 { // dr23: yes 241 template<typename T> void f(T, T); // expected-note {{candidate}} 242 template<typename T> void f(T, int); // expected-note {{candidate}} 243 void g() { f(0, 0); } // expected-error {{ambiguous}} 244} 245 246// dr24: na 247 248namespace dr25 { // dr25: yes 249 struct A { 250 void f() throw(int); 251 }; 252 void (A::*f)() throw (int); 253 void (A::*g)() throw () = f; // expected-error {{is not superset of source}} 254 void (A::*g2)() throw () = 0; 255 void (A::*h)() throw (int, char) = f; 256 void (A::*i)() throw () = &A::f; // expected-error {{is not superset of source}} 257 void (A::*i2)() throw () = 0; 258 void (A::*j)() throw (int, char) = &A::f; 259 void x() { 260 // FIXME: Don't produce the second error here. 261 g2 = f; // expected-error {{is not superset}} expected-error {{incompatible}} 262 h = f; 263 i2 = &A::f; // expected-error {{is not superset}} expected-error {{incompatible}} 264 j = &A::f; 265 } 266} 267 268namespace dr26 { // dr26: yes 269 struct A { A(A, const A & = A()); }; // expected-error {{must pass its first argument by reference}} 270 struct B { 271 B(); // expected-note {{candidate}} 272 B(const B &, B = B()); // expected-error {{no matching constructor}} expected-note {{candidate}} expected-note {{here}} 273 }; 274} 275 276namespace dr27 { // dr27: yes 277 enum E { e } n; 278 E &m = true ? n : n; 279} 280 281// dr28: na 282 283namespace dr29 { // dr29: no 284 void dr29_f0(); // expected-note {{here}} 285 void g0() { void dr29_f0(); } 286 extern "C++" void g0_cxx() { void dr29_f0(); } 287 extern "C" void g0_c() { void dr29_f0(); } // expected-error {{different language linkage}} 288 289 extern "C" void dr29_f1(); // expected-note {{here}} 290 void g1() { void dr29_f1(); } 291 extern "C" void g1_c() { void dr29_f1(); } 292 extern "C++" void g1_cxx() { void dr29_f1(); } // expected-error {{different language linkage}} 293 294 // FIXME: We should reject this. 295 void g2() { void dr29_f2(); } 296 extern "C" void dr29_f2(); 297 298 // FIXME: We should reject this. 299 extern "C" void g3() { void dr29_f3(); } 300 extern "C++" void dr29_f3(); 301 302 // FIXME: We should reject this. 303 extern "C++" void g4() { void dr29_f4(); } 304 extern "C" void dr29_f4(); 305 306 extern "C" void g5(); 307 extern "C++" void dr29_f5(); 308 void g5() { 309 void dr29_f5(); // ok, g5 is extern "C" but we're not inside the linkage-specification here. 310 } 311 312 extern "C++" void g6(); 313 extern "C" void dr29_f6(); 314 void g6() { 315 void dr29_f6(); // ok, g6 is extern "C" but we're not inside the linkage-specification here. 316 } 317 318 extern "C" void g7(); 319 extern "C++" void dr29_f7(); // expected-note {{here}} 320 extern "C" void g7() { 321 void dr29_f7(); // expected-error {{different language linkage}} 322 } 323 324 extern "C++" void g8(); 325 extern "C" void dr29_f8(); // expected-note {{here}} 326 extern "C++" void g8() { 327 void dr29_f8(); // expected-error {{different language linkage}} 328 } 329} 330 331namespace dr30 { // dr30: sup 468 332 struct A { 333 template<int> static int f(); 334 } a, *p = &a; 335 int x = A::template f<0>(); 336 int y = a.template f<0>(); 337 int z = p->template f<0>(); 338#if __cplusplus < 201103L 339 // FIXME: It's not clear whether DR468 applies to C++98 too. 340 // expected-error@-5 {{'template' keyword outside of a template}} 341 // expected-error@-5 {{'template' keyword outside of a template}} 342 // expected-error@-5 {{'template' keyword outside of a template}} 343#endif 344} 345 346namespace dr31 { // dr31: yes 347 class X { 348 private: 349 void operator delete(void*); // expected-note {{here}} 350 }; 351 // We would call X::operator delete if X() threw (even though it can't, 352 // and even though we allocated the X using ::operator delete). 353 X *p = new X; // expected-error {{private}} 354} 355 356// dr32: na 357 358namespace dr33 { // dr33: yes 359 namespace X { struct S; void f(void (*)(S)); } // expected-note {{candidate}} 360 namespace Y { struct T; void f(void (*)(T)); } // expected-note {{candidate}} 361 void g(X::S); 362 template<typename Z> Z g(Y::T); 363 void h() { f(&g); } // expected-error {{ambiguous}} 364} 365 366// dr34: na 367// dr35: dup 178 368// dr37: sup 475 369 370namespace dr38 { // dr38: yes 371 template<typename T> struct X {}; 372 template<typename T> X<T> operator+(X<T> a, X<T> b) { return a; } 373 template X<int> operator+<int>(X<int>, X<int>); 374} 375 376namespace dr39 { // dr39: no 377 namespace example1 { 378 struct A { int &f(int); }; 379 struct B : A { 380 using A::f; 381 float &f(float); 382 } b; 383 int &r = b.f(0); 384 } 385 386 namespace example2 { 387 struct A { 388 int &x(int); // expected-note {{found}} 389 static int &y(int); // expected-note {{found}} 390 }; 391 struct V { 392 int &z(int); 393 }; 394 struct B : A, virtual V { 395 using A::x; // expected-note {{found}} 396 float &x(float); 397 using A::y; // expected-note {{found}} 398 static float &y(float); 399 using V::z; 400 float &z(float); 401 }; 402 struct C : A, B, virtual V {} c; 403 int &x = c.x(0); // expected-error {{found in multiple base classes}} 404 // FIXME: This is valid, because we find the same static data member either way. 405 int &y = c.y(0); // expected-error {{found in multiple base classes}} 406 int &z = c.z(0); 407 } 408 409 namespace example3 { 410 struct A { static int f(); }; 411 struct B : virtual A { using A::f; }; 412 struct C : virtual A { using A::f; }; 413 struct D : B, C {} d; 414 int k = d.f(); 415 } 416 417 namespace example4 { 418 struct A { int n; }; // expected-note {{found}} 419 struct B : A {}; 420 struct C : A {}; 421 struct D : B, C { int f() { return n; } }; // expected-error {{found in multiple base-class}} 422 } 423 424 namespace PR5916 { 425 // FIXME: This is valid. 426 struct A { int n; }; // expected-note +{{found}} 427 struct B : A {}; 428 struct C : A {}; 429 struct D : B, C {}; 430 int k = sizeof(D::n); // expected-error {{found in multiple base}} expected-error {{unknown type name}} 431#if __cplusplus >= 201103L 432 decltype(D::n) n; // expected-error {{found in multiple base}} 433#endif 434 } 435} 436 437// dr40: na 438 439namespace dr41 { // dr41: yes 440 struct S f(S); 441} 442 443namespace dr42 { // dr42: yes 444 struct A { static const int k = 0; }; 445 struct B : A { static const int k = A::k; }; 446} 447 448// dr43: na 449 450namespace dr44 { // dr44: yes 451 struct A { 452 template<int> void f(); 453 template<> void f<0>(); // expected-error {{explicit specialization of 'f' in class scope}} 454 }; 455} 456 457namespace dr45 { // dr45: yes 458 class A { 459 class B {}; 460 class C : B {}; 461 C c; 462 }; 463} 464 465namespace dr46 { // dr46: yes 466 template<typename> struct A { template<typename> struct B {}; }; 467 template template struct A<int>::B<int>; // expected-error {{expected unqualified-id}} 468} 469 470namespace dr47 { // dr47: no 471 template<typename T> struct A { 472 friend void f() { T t; } 473 }; 474 A<int> a; 475 A<float> b; 476#if __cplusplus < 201103L 477 // expected-error@-5 {{redefinition}} expected-note@-5 {{previous}} 478 // expected-note@-3 {{instantiation of}} 479#else 480 void f(); 481 // FIXME: We should produce some kind of error here. C++11 [temp.friend]p4 482 // says we instantiate 'f' when it's odr-used, but that doesn't imply that 483 // this is valid; we still have multiple definitions of 'f' even if we never 484 // instantiate any of them. 485 void g() { f(); } 486#endif 487} 488 489namespace dr48 { // dr48: yes 490 namespace { 491 struct S { 492 static const int m = 0; 493 static const int n = 0; 494 static const int o = 0; 495 }; 496 } 497 int a = S::m; 498 // FIXME: We should produce a 'has internal linkage but is not defined' 499 // diagnostic for 'S::n'. 500 const int &b = S::n; 501 const int S::o; 502 const int &c = S::o; 503} 504 505namespace dr49 { // dr49: yes 506 template<int*> struct A {}; // expected-note {{here}} 507 int k; 508#if __has_feature(cxx_constexpr) 509 constexpr 510#endif 511 int *const p = &k; 512 A<&k> a; 513 A<p> b; // expected-error {{must have its address taken}} 514#if __cplusplus < 201103L 515 // expected-error@-2 {{internal linkage}} 516 // expected-note@-5 {{here}} 517#endif 518} 519 520namespace dr50 { // dr50: yes 521 struct X; // expected-note {{forward}} 522 extern X *p; 523 X *q = (X*)p; 524 X *r = static_cast<X*>(p); 525 X *s = const_cast<X*>(p); 526 X *t = reinterpret_cast<X*>(p); 527 X *u = dynamic_cast<X*>(p); // expected-error {{incomplete}} 528} 529 530namespace dr51 { // dr51: yes 531 struct A {}; 532 struct B : A {}; 533 struct S { 534 operator A&(); 535 operator B&(); 536 } s; 537 A &a = s; 538} 539 540namespace dr52 { // dr52: yes 541 struct A { int n; }; // expected-note {{here}} 542 struct B : private A {} b; // expected-note 2{{private}} 543 // FIXME: This first diagnostic is very strangely worded, and seems to be bogus. 544 int k = b.A::n; // expected-error {{'A' is a private member of 'dr52::A'}} 545 // expected-error@-1 {{cannot cast 'struct B' to its private base}} 546} 547 548namespace dr53 { // dr53: yes 549 int n = 0; 550 enum E { e } x = static_cast<E>(n); 551} 552 553namespace dr54 { // dr54: yes 554 struct A { int a; } a; 555 struct V { int v; } v; 556 struct B : private A, virtual V { int b; } b; // expected-note 6{{private here}} 557 558 A &sab = static_cast<A&>(b); // expected-error {{private base}} 559 A *spab = static_cast<A*>(&b); // expected-error {{private base}} 560 int A::*smab = static_cast<int A::*>(&B::b); // expected-error {{private base}} 561 B &sba = static_cast<B&>(a); // expected-error {{private base}} 562 B *spba = static_cast<B*>(&a); // expected-error {{private base}} 563 int B::*smba = static_cast<int B::*>(&A::a); // expected-error {{private base}} 564 565 V &svb = static_cast<V&>(b); 566 V *spvb = static_cast<V*>(&b); 567 int V::*smvb = static_cast<int V::*>(&B::b); // expected-error {{virtual base}} 568 B &sbv = static_cast<B&>(v); // expected-error {{virtual base}} 569 B *spbv = static_cast<B*>(&v); // expected-error {{virtual base}} 570 int B::*smbv = static_cast<int B::*>(&V::v); // expected-error {{virtual base}} 571 572 A &cab = (A&)(b); 573 A *cpab = (A*)(&b); 574 int A::*cmab = (int A::*)(&B::b); 575 B &cba = (B&)(a); 576 B *cpba = (B*)(&a); 577 int B::*cmba = (int B::*)(&A::a); 578 579 V &cvb = (V&)(b); 580 V *cpvb = (V*)(&b); 581 int V::*cmvb = (int V::*)(&B::b); // expected-error {{virtual base}} 582 B &cbv = (B&)(v); // expected-error {{virtual base}} 583 B *cpbv = (B*)(&v); // expected-error {{virtual base}} 584 int B::*cmbv = (int B::*)(&V::v); // expected-error {{virtual base}} 585} 586 587namespace dr55 { // dr55: yes 588 enum E { e = 5 }; 589 int test[(e + 1 == 6) ? 1 : -1]; 590} 591 592namespace dr56 { // dr56: yes 593 struct A { 594 typedef int T; // expected-note {{previous}} 595 typedef int T; // expected-error {{redefinition}} 596 }; 597 struct B { 598 struct X; 599 typedef X X; // expected-note {{previous}} 600 typedef X X; // expected-error {{redefinition}} 601 }; 602} 603 604namespace dr58 { // dr58: yes 605 // FIXME: Ideally, we should have a CodeGen test for this. 606#if __cplusplus >= 201103L 607 enum E1 { E1_0 = 0, E1_1 = 1 }; 608 enum E2 { E2_0 = 0, E2_m1 = -1 }; 609 struct X { E1 e1 : 1; E2 e2 : 1; }; 610 static_assert(X{E1_1, E2_m1}.e1 == 1, ""); 611 static_assert(X{E1_1, E2_m1}.e2 == -1, ""); 612#endif 613} 614 615namespace dr59 { // dr59: yes 616 template<typename T> struct convert_to { operator T() const; }; 617 struct A {}; // expected-note 2{{volatile qualifier}} 618 struct B : A {}; // expected-note 2{{volatile qualifier}} 619#if __cplusplus >= 201103L // move constructors 620 // expected-note@-3 2{{volatile qualifier}} 621 // expected-note@-3 2{{volatile qualifier}} 622#endif 623 624 A a1 = convert_to<A>(); 625 A a2 = convert_to<A&>(); 626 A a3 = convert_to<const A>(); 627 A a4 = convert_to<const volatile A>(); // expected-error {{no viable}} 628 A a5 = convert_to<const volatile A&>(); // expected-error {{no viable}} 629 630 B b1 = convert_to<B>(); 631 B b2 = convert_to<B&>(); 632 B b3 = convert_to<const B>(); 633 B b4 = convert_to<const volatile B>(); // expected-error {{no viable}} 634 B b5 = convert_to<const volatile B&>(); // expected-error {{no viable}} 635 636 int n1 = convert_to<int>(); 637 int n2 = convert_to<int&>(); 638 int n3 = convert_to<const int>(); 639 int n4 = convert_to<const volatile int>(); 640 int n5 = convert_to<const volatile int&>(); 641} 642 643namespace dr60 { // dr60: yes 644 void f(int &); 645 int &f(...); 646 const int k = 0; 647 int &n = f(k); 648} 649 650namespace dr61 { // dr61: yes 651 struct X { 652 static void f(); 653 } x; 654 struct Y { 655 static void f(); 656 static void f(int); 657 } y; 658 // This is (presumably) valid, because x.f does not refer to an overloaded 659 // function name. 660 void (*p)() = &x.f; 661 void (*q)() = &y.f; // expected-error {{cannot create a non-constant pointer to member function}} 662} 663 664namespace dr62 { // dr62: yes 665 struct A { 666 struct { int n; } b; 667 }; 668 template<typename T> struct X {}; 669 template<typename T> T get() { return get<T>(); } 670 template<typename T> int take(T) { return 0; } 671 672 X<A> x1; 673 A a = get<A>(); 674 675 typedef struct { } *NoNameForLinkagePtr; 676#if __cplusplus < 201103L 677 // expected-note@-2 5{{here}} 678#endif 679 NoNameForLinkagePtr noNameForLinkagePtr; 680 681 struct Danger { 682 NoNameForLinkagePtr p; 683 }; 684 685 X<NoNameForLinkagePtr> x2; 686 X<const NoNameForLinkagePtr> x3; 687 NoNameForLinkagePtr p1 = get<NoNameForLinkagePtr>(); 688 NoNameForLinkagePtr p2 = get<const NoNameForLinkagePtr>(); 689 int n1 = take(noNameForLinkagePtr); 690#if __cplusplus < 201103L 691 // expected-error@-6 {{uses unnamed type}} 692 // expected-error@-6 {{uses unnamed type}} 693 // expected-error@-6 {{uses unnamed type}} 694 // expected-error@-6 {{uses unnamed type}} 695 // expected-error@-6 {{uses unnamed type}} 696#endif 697 698 X<Danger> x4; 699 700 void f() { 701 struct NoLinkage {}; 702 X<NoLinkage> a; 703 X<const NoLinkage> b; 704 get<NoLinkage>(); 705 get<const NoLinkage>(); 706 X<void (*)(NoLinkage A::*)> c; 707 X<int NoLinkage::*> d; 708#if __cplusplus < 201103L 709 // expected-error@-7 {{uses local type}} 710 // expected-error@-7 {{uses local type}} 711 // expected-error@-7 {{uses local type}} 712 // expected-error@-7 {{uses local type}} 713 // expected-error@-7 {{uses local type}} 714 // expected-error@-7 {{uses local type}} 715#endif 716 } 717} 718 719namespace dr63 { // dr63: yes 720 template<typename T> struct S { typename T::error e; }; 721 extern S<int> *p; 722 void *q = p; 723} 724 725namespace dr64 { // dr64: yes 726 template<class T> void f(T); 727 template<class T> void f(T*); 728 template<> void f(int*); 729 template<> void f<int>(int*); 730 template<> void f(int); 731} 732 733// dr65: na 734 735namespace dr66 { // dr66: no 736 namespace X { 737 int f(int n); // expected-note 2{{candidate}} 738 } 739 using X::f; 740 namespace X { 741 int f(int n = 0); 742 int f(int, int); 743 } 744 // FIXME: The first two calls here should be accepted. 745 int a = f(); // expected-error {{no matching function}} 746 int b = f(1); 747 int c = f(1, 2); // expected-error {{no matching function}} 748} 749 750// dr67: na 751 752namespace dr68 { // dr68: yes 753 template<typename T> struct X {}; 754 struct ::dr68::X<int> x1; 755 struct ::dr68::template X<int> x2; 756#if __cplusplus < 201103L 757 // expected-error@-2 {{'template' keyword outside of a template}} 758#endif 759 struct Y { 760 friend struct X<int>; 761 friend struct ::dr68::X<char>; 762 friend struct ::dr68::template X<double>; 763#if __cplusplus < 201103L 764 // expected-error@-2 {{'template' keyword outside of a template}} 765#endif 766 }; 767 template<typename> 768 struct Z { 769 friend struct ::dr68::template X<double>; 770 friend typename ::dr68::X<double>; 771#if __cplusplus < 201103L 772 // expected-error@-2 {{C++11 extension}} 773#endif 774 }; 775} 776 777namespace dr69 { // dr69: yes 778 template<typename T> static void f() {} 779 // FIXME: Should we warn here? 780 inline void g() { f<int>(); } 781 // FIXME: This should be rejected, per [temp.explicit]p11. 782 extern template void f<char>(); 783#if __cplusplus < 201103L 784 // expected-error@-2 {{C++11 extension}} 785#endif 786 template<void(*)()> struct Q {}; 787 Q<&f<int> > q; 788#if __cplusplus < 201103L 789 // expected-error@-2 {{internal linkage}} expected-note@-11 {{here}} 790#endif 791} 792 793namespace dr70 { // dr70: yes 794 template<int> struct A {}; 795 template<int I, int J> int f(int (&)[I + J], A<I>, A<J>); 796 int arr[7]; 797 int k = f(arr, A<3>(), A<4>()); 798} 799 800// dr71: na 801// dr72: dup 69 802 803#if __cplusplus >= 201103L 804namespace dr73 { // dr73: no 805 // The resolution to dr73 is unworkable. Consider: 806 int a, b; 807 static_assert(&a + 1 != &b, ""); 808} 809#endif 810 811namespace dr74 { // dr74: yes 812 enum E { k = 5 }; 813 int (*p)[k] = new int[k][k]; 814} 815 816namespace dr75 { // dr75: yes 817 struct S { 818 static int n = 0; // expected-error {{non-const}} 819 }; 820} 821 822namespace dr76 { // dr76: yes 823 const volatile int n = 1; 824 int arr[n]; // expected-error +{{variable length array}} 825} 826 827namespace dr77 { // dr77: yes 828 struct A { 829 struct B {}; 830 friend struct B; 831 }; 832} 833 834namespace dr78 { // dr78: sup ???? 835 // Under DR78, this is valid, because 'k' has static storage duration, so is 836 // zero-initialized. 837 const int k; // expected-error {{default initialization of an object of const}} 838} 839 840// dr79: na 841 842namespace dr80 { // dr80: yes 843 struct A { 844 int A; 845 }; 846 struct B { 847 static int B; // expected-error {{same name as its class}} 848 }; 849 struct C { 850 int C; // expected-note {{hidden by}} 851 // FIXME: These diagnostics aren't very good. 852 C(); // expected-error {{must use 'struct' tag to refer to}} expected-error {{expected member name}} 853 }; 854 struct D { 855 D(); 856 int D; // expected-error {{same name as its class}} 857 }; 858} 859 860// dr81: na 861// dr82: dup 48 862 863namespace dr83 { // dr83: yes 864 int &f(const char*); 865 char &f(char *); 866 int &k = f("foo"); 867} 868 869namespace dr84 { // dr84: yes 870 struct B; 871 struct A { operator B() const; }; 872 struct C {}; 873 struct B { 874 B(B&); // expected-note {{candidate}} 875 B(C); 876 operator C() const; 877 }; 878 A a; 879 // Cannot use B(C) / operator C() pair to construct the B from the B temporary 880 // here. 881 B b = a; // expected-error {{no viable}} 882} 883 884namespace dr85 { // dr85: yes 885 struct A { 886 struct B; 887 struct B {}; // expected-note{{previous declaration is here}} 888 struct B; // expected-error{{class member cannot be redeclared}} 889 890 union U; 891 union U {}; // expected-note{{previous declaration is here}} 892 union U; // expected-error{{class member cannot be redeclared}} 893 894#if __cplusplus >= 201103L 895 enum E1 : int; 896 enum E1 : int { e1 }; // expected-note{{previous declaration is here}} 897 enum E1 : int; // expected-error{{class member cannot be redeclared}} 898 899 enum class E2; 900 enum class E2 { e2 }; // expected-note{{previous declaration is here}} 901 enum class E2; // expected-error{{class member cannot be redeclared}} 902#endif 903 }; 904 905 template <typename T> 906 struct C { 907 struct B {}; // expected-note{{previous declaration is here}} 908 struct B; // expected-error{{class member cannot be redeclared}} 909 }; 910} 911 912// dr86: dup 446 913 914namespace dr87 { // dr87: no 915 template<typename T> struct X {}; 916 // FIXME: This is invalid. 917 X<void() throw()> x; 918 // ... but this is valid. 919 X<void(void() throw())> y; 920} 921 922namespace dr88 { // dr88: yes 923 template<typename T> struct S { 924 static const int a = 1; 925 static const int b; 926 }; 927 // FIXME: This diagnostic is pretty bad. 928 template<> const int S<int>::a = 4; // expected-error {{redefinition}} expected-note {{previous}} 929 template<> const int S<int>::b = 4; 930} 931 932// dr89: na 933 934namespace dr90 { // dr90: yes 935 struct A { 936 template<typename T> friend void dr90_f(T); 937 }; 938 struct B : A { 939 template<typename T> friend void dr90_g(T); 940 struct C {}; 941 union D {}; 942 }; 943 struct E : B {}; 944 struct F : B::C {}; 945 946 void test() { 947 dr90_f(A()); 948 dr90_f(B()); 949 dr90_f(B::C()); // expected-error {{undeclared identifier}} 950 dr90_f(B::D()); // expected-error {{undeclared identifier}} 951 dr90_f(E()); 952 dr90_f(F()); // expected-error {{undeclared identifier}} 953 954 dr90_g(A()); // expected-error {{undeclared identifier}} 955 dr90_g(B()); 956 dr90_g(B::C()); 957 dr90_g(B::D()); 958 dr90_g(E()); 959 dr90_g(F()); // expected-error {{undeclared identifier}} 960 } 961} 962 963namespace dr91 { // dr91: yes 964 union U { friend int f(U); }; 965 int k = f(U()); 966} 967 968// dr93: na 969 970namespace dr94 { // dr94: yes 971 struct A { static const int n = 5; }; 972 int arr[A::n]; 973} 974 975namespace dr95 { // dr95: yes 976 struct A; 977 struct B; 978 namespace N { 979 class C { 980 friend struct A; 981 friend struct B; 982 static void f(); // expected-note {{here}} 983 }; 984 struct A *p; // dr95::A, not dr95::N::A. 985 } 986 A *q = N::p; // ok, same type 987 struct B { void f() { N::C::f(); } }; // expected-error {{private}} 988} 989 990namespace dr96 { // dr96: no 991 struct A { 992 void f(int); 993 template<typename T> int f(T); 994 template<typename T> struct S {}; 995 } a; 996 template<template<typename> class X> struct B {}; 997 998 template<typename T> 999 void test() { 1000 int k1 = a.template f<int>(0); 1001 // FIXME: This is ill-formed, because 'f' is not a template-id and does not 1002 // name a class template. 1003 // FIXME: What about alias templates? 1004 int k2 = a.template f(1); 1005 A::template S<int> s; 1006 B<A::template S> b; 1007 } 1008} 1009 1010namespace dr97 { // dr97: yes 1011 struct A { 1012 static const int a = false; 1013 static const int b = !a; 1014 }; 1015} 1016 1017namespace dr98 { // dr98: yes 1018 void test(int n) { 1019 switch (n) { 1020 try { // expected-note 2{{bypasses}} 1021 case 0: // expected-error {{protected}} 1022 x: 1023 throw n; 1024 } catch (...) { // expected-note 2{{bypasses}} 1025 case 1: // expected-error {{protected}} 1026 y: 1027 throw n; 1028 } 1029 case 2: 1030 goto x; // expected-error {{protected}} 1031 case 3: 1032 goto y; // expected-error {{protected}} 1033 } 1034 } 1035} 1036 1037namespace dr99 { // dr99: sup 214 1038 template<typename T> void f(T&); 1039 template<typename T> int &f(const T&); 1040 const int n = 0; 1041 int &r = f(n); 1042} 1043