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