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