dr0xx.cpp revision 585bee48bac063f31696e308798f9432b5ba4116
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 default 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: no 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 // FIXME: This should be rejected. 642 void (*q)() = &y.f; 643} 644 645namespace dr62 { // dr62: yes 646 struct A { 647 struct { int n; } b; 648 }; 649 template<typename T> struct X {}; 650 template<typename T> T get() { return get<T>(); } 651 template<typename T> int take(T) { return 0; } 652 653 X<A> x1; 654 A a = get<A>(); 655 656 typedef struct { } *NoNameForLinkagePtr; 657#if __cplusplus < 201103L 658 // expected-note@-2 5{{here}} 659#endif 660 NoNameForLinkagePtr noNameForLinkagePtr; 661 662 struct Danger { 663 NoNameForLinkagePtr p; 664 }; 665 666 X<NoNameForLinkagePtr> x2; 667 X<const NoNameForLinkagePtr> x3; 668 NoNameForLinkagePtr p1 = get<NoNameForLinkagePtr>(); 669 NoNameForLinkagePtr p2 = get<const NoNameForLinkagePtr>(); 670 int n1 = take(noNameForLinkagePtr); 671#if __cplusplus < 201103L 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 // expected-error@-6 {{uses unnamed type}} 677#endif 678 679 X<Danger> x4; 680 681 void f() { 682 struct NoLinkage {}; 683 X<NoLinkage> a; 684 X<const NoLinkage> b; 685 get<NoLinkage>(); 686 get<const NoLinkage>(); 687 X<void (*)(NoLinkage A::*)> c; 688 X<int NoLinkage::*> d; 689#if __cplusplus < 201103L 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 // expected-error@-7 {{uses local type}} 696#endif 697 } 698} 699 700namespace dr63 { // dr63: yes 701 template<typename T> struct S { typename T::error e; }; 702 extern S<int> *p; 703 void *q = p; 704} 705 706namespace dr64 { // dr64: yes 707 template<class T> void f(T); 708 template<class T> void f(T*); 709 template<> void f(int*); 710 template<> void f<int>(int*); 711 template<> void f(int); 712} 713 714// dr65: na 715 716namespace dr66 { // dr66: no 717 namespace X { 718 int f(int n); // expected-note 2{{candidate}} 719 } 720 using X::f; 721 namespace X { 722 int f(int n = 0); 723 int f(int, int); 724 } 725 // FIXME: The first two calls here should be accepted. 726 int a = f(); // expected-error {{no matching function}} 727 int b = f(1); 728 int c = f(1, 2); // expected-error {{no matching function}} 729} 730 731// dr67: na 732 733namespace dr68 { // dr68: yes 734 template<typename T> struct X {}; 735 struct ::dr68::X<int> x1; 736 struct ::dr68::template X<int> x2; 737#if __cplusplus < 201103L 738 // expected-error@-2 {{'template' keyword outside of a template}} 739#endif 740 struct Y { 741 friend struct X<int>; 742 friend struct ::dr68::X<char>; 743 friend struct ::dr68::template X<double>; 744#if __cplusplus < 201103L 745 // expected-error@-2 {{'template' keyword outside of a template}} 746#endif 747 }; 748 template<typename> 749 struct Z { 750 friend struct ::dr68::template X<double>; 751 friend typename ::dr68::X<double>; 752#if __cplusplus < 201103L 753 // expected-error@-2 {{C++11 extension}} 754#endif 755 }; 756} 757 758namespace dr69 { // dr69: yes 759 template<typename T> static void f() {} 760 // FIXME: Should we warn here? 761 inline void g() { f<int>(); } 762 // FIXME: This should be rejected, per [temp.explicit]p11. 763 extern template void f<char>(); 764#if __cplusplus < 201103L 765 // expected-error@-2 {{C++11 extension}} 766#endif 767 template<void(*)()> struct Q {}; 768 Q<&f<int> > q; 769#if __cplusplus < 201103L 770 // expected-error@-2 {{internal linkage}} expected-note@-11 {{here}} 771#endif 772} 773 774namespace dr70 { // dr70: yes 775 template<int> struct A {}; 776 template<int I, int J> int f(int (&)[I + J], A<I>, A<J>); 777 int arr[7]; 778 int k = f(arr, A<3>(), A<4>()); 779} 780 781// dr71: na 782// dr72: dup 69 783 784#if __cplusplus >= 201103L 785namespace dr73 { // dr73: no 786 // The resolution to dr73 is unworkable. Consider: 787 int a, b; 788 static_assert(&a + 1 != &b, ""); 789} 790#endif 791 792namespace dr74 { // dr74: yes 793 enum E { k = 5 }; 794 int (*p)[k] = new int[k][k]; 795} 796 797namespace dr75 { // dr75: yes 798 struct S { 799 static int n = 0; // expected-error {{non-const}} 800 }; 801} 802 803namespace dr76 { // dr76: yes 804 const volatile int n = 1; 805 int arr[n]; // expected-error +{{variable length array}} 806} 807 808namespace dr77 { // dr77: yes 809 struct A { 810 struct B {}; 811 friend struct B; 812 }; 813} 814 815namespace dr78 { // dr78: sup ???? 816 // Under DR78, this is valid, because 'k' has static storage duration, so is 817 // zero-initialized. 818 const int k; // expected-error {{default initialization of an object of const}} 819} 820 821// dr79: na 822 823namespace dr80 { // dr80: yes 824 struct A { 825 int A; 826 }; 827 struct B { 828 static int B; // expected-error {{same name as its class}} 829 }; 830 struct C { 831 int C; // expected-note {{hidden by}} 832 // FIXME: These diagnostics aren't very good. 833 C(); // expected-error {{must use 'struct' tag to refer to}} expected-error {{expected member name}} 834 }; 835 struct D { 836 D(); 837 int D; // expected-error {{same name as its class}} 838 }; 839} 840 841// dr81: na 842// dr82: dup 48 843 844namespace dr83 { // dr83: yes 845 int &f(const char*); 846 char &f(char *); 847 int &k = f("foo"); 848} 849 850namespace dr84 { // dr84: yes 851 struct B; 852 struct A { operator B() const; }; 853 struct C {}; 854 struct B { 855 B(B&); // expected-note {{candidate}} 856 B(C); 857 operator C() const; 858 }; 859 A a; 860 // Cannot use B(C) / operator C() pair to construct the B from the B temporary 861 // here. 862 B b = a; // expected-error {{no viable}} 863} 864 865namespace dr85 { // dr85: no 866 struct A { 867 struct B; 868 struct B {}; 869 // FIXME: This redeclaration is invalid. Per [class.mem]p1, 870 // "A member shall not be declared twice in the member-specification, 871 // except that a nested class [...] can be declared then later defined" 872 // This is not that case. 873 struct B; 874 }; 875} 876 877// dr86: dup 446 878 879namespace dr87 { // dr87: no 880 template<typename T> struct X {}; 881 // FIXME: This is invalid. 882 X<void() throw()> x; 883 // ... but this is valid. 884 X<void(void() throw())> y; 885} 886 887namespace dr88 { // dr88: yes 888 template<typename T> struct S { 889 static const int a = 1; 890 static const int b; 891 }; 892 // FIXME: This diagnostic is pretty bad. 893 template<> const int S<int>::a = 4; // expected-error {{redefinition}} expected-note {{previous}} 894 template<> const int S<int>::b = 4; 895} 896 897// dr89: na 898 899namespace dr90 { // dr90: yes 900 struct A { 901 template<typename T> friend void dr90_f(T); 902 }; 903 struct B : A { 904 template<typename T> friend void dr90_g(T); 905 struct C {}; 906 union D {}; 907 }; 908 struct E : B {}; 909 struct F : B::C {}; 910 911 void test() { 912 dr90_f(A()); 913 dr90_f(B()); 914 dr90_f(B::C()); // expected-error {{undeclared identifier}} 915 dr90_f(B::D()); // expected-error {{undeclared identifier}} 916 dr90_f(E()); 917 dr90_f(F()); // expected-error {{undeclared identifier}} 918 919 dr90_g(A()); // expected-error {{undeclared identifier}} 920 dr90_g(B()); 921 dr90_g(B::C()); 922 dr90_g(B::D()); 923 dr90_g(E()); 924 dr90_g(F()); // expected-error {{undeclared identifier}} 925 } 926} 927 928namespace dr91 { // dr91: yes 929 union U { friend int f(U); }; 930 int k = f(U()); 931} 932 933// dr93: na 934 935namespace dr94 { // dr94: yes 936 struct A { static const int n = 5; }; 937 int arr[A::n]; 938} 939 940namespace dr95 { // dr95: yes 941 struct A; 942 struct B; 943 namespace N { 944 class C { 945 friend struct A; 946 friend struct B; 947 static void f(); // expected-note {{here}} 948 }; 949 struct A *p; // dr95::A, not dr95::N::A. 950 } 951 A *q = N::p; // ok, same type 952 struct B { void f() { N::C::f(); } }; // expected-error {{private}} 953} 954 955namespace dr96 { // dr96: no 956 struct A { 957 void f(int); 958 template<typename T> int f(T); 959 template<typename T> struct S {}; 960 } a; 961 template<template<typename> class X> struct B {}; 962 963 template<typename T> 964 void test() { 965 int k1 = a.template f<int>(0); 966 // FIXME: This is ill-formed, because 'f' is not a template-id and does not 967 // name a class template. 968 // FIXME: What about alias templates? 969 int k2 = a.template f(1); 970 A::template S<int> s; 971 B<A::template S> b; 972 } 973} 974 975namespace dr97 { // dr97: yes 976 struct A { 977 static const int a = false; 978 static const int b = !a; 979 }; 980} 981 982namespace dr98 { // dr98: yes 983 void test(int n) { 984 switch (n) { 985 try { // expected-note 2{{bypasses}} 986 case 0: // expected-error {{protected}} 987 x: 988 throw n; 989 } catch (...) { // expected-note 2{{bypasses}} 990 case 1: // expected-error {{protected}} 991 y: 992 throw n; 993 } 994 case 2: 995 goto x; // expected-error {{protected}} 996 case 3: 997 goto y; // expected-error {{protected}} 998 } 999 } 1000} 1001 1002namespace dr99 { // dr99: sup 214 1003 template<typename T> void f(T&); 1004 template<typename T> int &f(const T&); 1005 const int n = 0; 1006 int &r = f(n); 1007} 1008