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