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