| 1 | // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking |
| 2 | // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking |
| 3 | // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking |
| 4 | // RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking |
| 5 | // RUN: %clang_cc1 -std=c++2a %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking |
| 6 | |
| 7 | namespace std { |
| 8 | struct type_info {}; |
| 9 | __extension__ typedef __SIZE_TYPE__ size_t; |
| 10 | } // namespace std |
| 11 | |
| 12 | namespace dr601 { // dr601: yes |
| 13 | #if __cplusplus >= 201103L |
| 14 | #define MAX __LLONG_MAX__ |
| 15 | #else |
| 16 | #define MAX __LONG_MAX__ |
| 17 | #endif |
| 18 | |
| 19 | #if 0x8000 < -1 |
| 20 | #error 0x8000 should be signed |
| 21 | #endif |
| 22 | |
| 23 | #if MAX > 0xFFFFFFFF && 0x80000000 < -1 |
| 24 | #error 0x80000000 should be signed |
| 25 | #endif |
| 26 | |
| 27 | #if __INT_MAX__ == 0x7FFFFFFF |
| 28 | _Static_assert(0x80000000 < -1, "0x80000000 should be unsigned"); // expected-error {{C11}} |
| 29 | #endif |
| 30 | |
| 31 | #if MAX > 0xFFFFFFFFFFFFFFFF && 0x8000000000000000 < -1 |
| 32 | #error 0x8000000000000000 should be signed |
| 33 | #endif |
| 34 | |
| 35 | #if __cplusplus >= 201103L && __LLONG_MAX__ == 0x7FFFFFFFFFFFFFFF |
| 36 | static_assert(0x8000000000000000 < -1, "0x8000000000000000 should be unsigned"); // expected-error {{C11}} |
| 37 | #endif |
| 38 | |
| 39 | #undef MAX |
| 40 | } |
| 41 | |
| 42 | namespace dr602 { // dr602: yes |
| 43 | template<class T> struct A { |
| 44 | template<class U> friend struct A; |
| 45 | }; |
| 46 | |
| 47 | template<class T> struct B { |
| 48 | class C { |
| 49 | template<class U> friend struct B; |
| 50 | typedef int type; |
| 51 | }; |
| 52 | typename C::type ct; // ok, befriended |
| 53 | }; |
| 54 | B<int> b; |
| 55 | } |
| 56 | |
| 57 | namespace dr603 { // dr603: yes |
| 58 | template<unsigned char> struct S {}; |
| 59 | typedef S<'\001'> S1; |
| 60 | typedef S<(1ul << __CHAR_BIT__) + 1> S1; |
| 61 | #if __cplusplus >= 201103L |
| 62 | // expected-error@-2 {{cannot be narrowed}} |
| 63 | #endif |
| 64 | } |
| 65 | |
| 66 | // dr604: na |
| 67 | // dr605 needs IRGen test |
| 68 | |
| 69 | namespace dr606 { // dr606: yes |
| 70 | #if __cplusplus >= 201103L |
| 71 | template<typename T> struct S {}; |
| 72 | template<typename T> void f(S<T> &&); // expected-note {{no known conversion from 'S<int>' to 'S<int> &&'}} |
| 73 | template<typename T> void g(T &&); |
| 74 | template<typename T> void h(const T &&); // expected-note {{no known conversion from 'S<int>' to 'const dr606::S<int> &&'}} |
| 75 | |
| 76 | void test(S<int> s) { |
| 77 | f(s); // expected-error {{no match}} |
| 78 | g(s); |
| 79 | h(s); // expected-error {{no match}} |
| 80 | |
| 81 | g(test); |
| 82 | h(test); // ok, an rvalue reference can bind to a function lvalue |
| 83 | } |
| 84 | #endif |
| 85 | } |
| 86 | |
| 87 | namespace dr608 { // dr608: yes |
| 88 | struct A { virtual void f(); }; |
| 89 | struct B : A {}; |
| 90 | struct C : A { void f(); }; |
| 91 | struct D : B, C {}; |
| 92 | } |
| 93 | |
| 94 | int dr610[-0u == 0u ? 1 : -1]; // dr610: yes |
| 95 | |
| 96 | namespace dr611 { // dr611: yes |
| 97 | int k; |
| 98 | struct S { int &r; } s = { k ? k : k }; |
| 99 | } |
| 100 | |
| 101 | // dr612: na |
| 102 | |
| 103 | namespace dr613 { // dr613: yes c++11 |
| 104 | // see also n2253 |
| 105 | struct A { int n; static void f(); }; |
| 106 | int f(int); |
| 107 | struct B { virtual void f(); }; |
| 108 | B &g(int); |
| 109 | |
| 110 | int an1 = sizeof(A::n); |
| 111 | int an2 = sizeof(A::n + 1); // valid per dr850 |
| 112 | int an3 = sizeof A::n; |
| 113 | int an4 = sizeof(f(A::n)); |
| 114 | int an5 = sizeof(g(A::n)); |
| 115 | const std::type_info &an6 = typeid(A::n); |
| 116 | const std::type_info &an7 = typeid(A::n + 1); |
| 117 | const std::type_info &an8 = typeid(f(A::n)); |
| 118 | const std::type_info &an9 = typeid(g(A::n)); // expected-error {{non-static}} |
| 119 | #if __cplusplus < 201103L |
| 120 | // expected-error@-10 {{non-static}} |
| 121 | // expected-error@-10 {{non-static}} |
| 122 | // expected-error@-10 {{non-static}} |
| 123 | // expected-error@-10 {{non-static}} |
| 124 | // expected-error@-10 {{non-static}} |
| 125 | // expected-error@-10 {{non-static}} |
| 126 | // expected-error@-10 {{non-static}} |
| 127 | // expected-error@-10 {{non-static}} |
| 128 | #endif |
| 129 | |
| 130 | void A::f() { |
| 131 | int an1 = sizeof n; |
| 132 | const std::type_info &an2 = typeid(n + 1); |
| 133 | #if __cplusplus < 201103L |
| 134 | // expected-error@-3 {{static}} |
| 135 | // expected-error@-3 {{static}} |
| 136 | #endif |
| 137 | const std::type_info &an3 = typeid(g(n)); // expected-error {{static}} |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | int dr614_a[(-1) / 2 == 0 ? 1 : -1]; // dr614: yes |
| 142 | int dr614_b[(-1) % 2 == -1 ? 1 : -1]; |
| 143 | |
| 144 | namespace dr615 { // dr615: yes |
| 145 | int f(); |
| 146 | static int n = f(); |
| 147 | } |
| 148 | |
| 149 | namespace dr616 { // dr616: 4 |
| 150 | #if __cplusplus >= 201103L |
| 151 | struct S { int n; } s; |
| 152 | S f(); |
| 153 | using T = decltype((S().n)); |
| 154 | using T = decltype((static_cast<S&&>(s).n)); |
| 155 | using T = decltype((f().n)); |
| 156 | using T = decltype(S().*&S::n); |
| 157 | using T = decltype(static_cast<S&&>(s).*&S::n); |
| 158 | using T = decltype(f().*&S::n); |
| 159 | using T = int&&; |
| 160 | |
| 161 | using U = decltype(S().n); |
| 162 | using U = decltype(static_cast<S&&>(s).n); |
| 163 | using U = int; |
| 164 | #endif |
| 165 | } |
| 166 | |
| 167 | namespace dr618 { // dr618: yes |
| 168 | #if (unsigned)-1 > 0 |
| 169 | #error wrong |
| 170 | #endif |
| 171 | } |
| 172 | |
| 173 | namespace dr619 { // dr619: yes |
| 174 | extern int x[10]; |
| 175 | struct S { static int x[10]; }; |
| 176 | |
| 177 | int x[]; |
| 178 | _Static_assert(sizeof(x) == sizeof(int) * 10, ""); // expected-error {{C11}} |
| 179 | extern int x[]; |
| 180 | _Static_assert(sizeof(x) == sizeof(int) * 10, ""); // expected-error {{C11}} |
| 181 | |
| 182 | int S::x[]; |
| 183 | _Static_assert(sizeof(S::x) == sizeof(int) * 10, ""); // expected-error {{C11}} |
| 184 | |
| 185 | void f() { |
| 186 | extern int x[]; |
| 187 | sizeof(x); // expected-error {{incomplete}} |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | // dr620: dup 568 |
| 192 | |
| 193 | namespace dr621 { |
| 194 | template<typename T> T f(); |
| 195 | template<> int f() {} // expected-note {{previous}} |
| 196 | template<> int f<int>() {} // expected-error {{redefinition}} |
| 197 | } |
| 198 | |
| 199 | // dr623: na |
| 200 | // FIXME: Add documentation saying we allow invalid pointer values. |
| 201 | |
| 202 | // dr624 needs an IRGen check. |
| 203 | |
| 204 | namespace dr625 { // dr625: yes |
| 205 | template<typename T> struct A {}; |
| 206 | A<auto> x = A<int>(); // expected-error {{'auto' not allowed in template argument}} expected-error 0-1{{extension}} |
| 207 | void f(int); |
| 208 | void (*p)(auto) = f; // expected-error {{'auto' not allowed in function prototype}} expected-error 0-1{{extension}} |
| 209 | } |
| 210 | |
| 211 | namespace dr626 { // dr626: yes |
| 212 | #define STR(x) #x |
| 213 | char c[2] = STR(c); // ok, type matches |
| 214 | wchar_t w[2] = STR(w); // expected-error {{initializing wide char array with non-wide string literal}} |
| 215 | } |
| 216 | |
| 217 | namespace dr627 { // dr627: yes |
| 218 | void f() { |
| 219 | true a = 0; // expected-error +{{}} expected-warning {{unused}} |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | // dr628: na |
| 224 | |
| 225 | namespace dr629 { // dr629: yes |
| 226 | typedef int T; |
| 227 | int n = 1; |
| 228 | void f() { |
| 229 | auto T = 2; |
| 230 | #if __cplusplus < 201103L |
| 231 | // expected-error@-2 {{expected unqualified-id}} |
| 232 | #else |
| 233 | // expected-note@-4 {{previous}} |
| 234 | #endif |
| 235 | |
| 236 | auto T(n); |
| 237 | #if __cplusplus >= 201103L |
| 238 | // expected-error@-2 {{redefinition of 'T'}} |
| 239 | #endif |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | namespace dr630 { // dr630: yes |
| 244 | const bool MB_EQ_WC = |
| 245 | ' ' == L' ' && '\t' == L'\t' && '\v' == L'\v' && '\r' == L'\r' && |
| 246 | '\n' == L'\n' && // |
| 247 | 'a' == L'a' && 'b' == L'b' && 'c' == L'c' && 'd' == L'd' && 'e' == L'e' && |
| 248 | 'f' == L'f' && 'g' == L'g' && 'h' == L'h' && 'i' == L'i' && 'j' == L'j' && |
| 249 | 'k' == L'k' && 'l' == L'l' && 'm' == L'm' && 'n' == L'n' && 'o' == L'o' && |
| 250 | 'p' == L'p' && 'q' == L'q' && 'r' == L'r' && 's' == L's' && 't' == L't' && |
| 251 | 'u' == L'u' && 'v' == L'v' && 'w' == L'w' && 'x' == L'x' && 'y' == L'y' && |
| 252 | 'z' == L'z' && // |
| 253 | 'A' == L'A' && 'B' == L'B' && 'C' == L'C' && 'D' == L'D' && 'E' == L'E' && |
| 254 | 'F' == L'F' && 'G' == L'G' && 'H' == L'H' && 'I' == L'I' && 'J' == L'J' && |
| 255 | 'K' == L'K' && 'L' == L'L' && 'M' == L'M' && 'N' == L'N' && 'O' == L'O' && |
| 256 | 'P' == L'P' && 'Q' == L'Q' && 'R' == L'R' && 'S' == L'S' && 'T' == L'T' && |
| 257 | 'U' == L'U' && 'V' == L'V' && 'W' == L'W' && 'X' == L'X' && 'Y' == L'Y' && |
| 258 | 'Z' == L'Z' && // |
| 259 | '0' == L'0' && '1' == L'1' && '2' == L'2' && '3' == L'3' && '4' == L'4' && |
| 260 | '5' == L'5' && '6' == L'6' && '7' == L'7' && '8' == L'8' && |
| 261 | '9' == L'9' && // |
| 262 | '_' == L'_' && '{' == L'{' && '}' == L'}' && '[' == L'[' && ']' == L']' && |
| 263 | '#' == L'#' && '(' == L'(' && ')' == L')' && '<' == L'<' && '>' == L'>' && |
| 264 | '%' == L'%' && ':' == L':' && ';' == L';' && '.' == L'.' && '?' == L'?' && |
| 265 | '*' == L'*' && '+' == L'+' && '-' == L'-' && '/' == L'/' && '^' == L'^' && |
| 266 | '&' == L'&' && '|' == L'|' && '~' == L'~' && '!' == L'!' && '=' == L'=' && |
| 267 | ',' == L',' && '\\' == L'\\' && '"' == L'"' && '\'' == L'\''; |
| 268 | #if __STDC_MB_MIGHT_NEQ_WC__ |
| 269 | #ifndef __FreeBSD__ // PR22208, FreeBSD expects us to give a bad (but conforming) answer here. |
| 270 | _Static_assert(!MB_EQ_WC, "__STDC_MB_MIGHT_NEQ_WC__ but all basic source characters have same representation"); // expected-error {{C11}} |
| 271 | #endif |
| 272 | #else |
| 273 | _Static_assert(MB_EQ_WC, "!__STDC_MB_MIGHT_NEQ_WC__ but some character differs"); // expected-error {{C11}} |
| 274 | #endif |
| 275 | } |
| 276 | |
| 277 | // dr631: na |
| 278 | |
| 279 | namespace dr632 { // dr632: yes |
| 280 | struct S { int n; } s = {{5}}; // expected-warning {{braces}} |
| 281 | } |
| 282 | |
| 283 | // dr633: na |
| 284 | // see also n2993 |
| 285 | |
| 286 | namespace dr634 { // dr634: yes |
| 287 | struct S { S(); S(const S&); virtual void f(); ~S(); }; |
| 288 | int f(...); |
| 289 | char f(int); |
| 290 | template<typename T> int (&g(T))[sizeof f(T())]; |
| 291 | int (&a)[sizeof(int)] = g(S()); |
| 292 | int (&b)[1] = g(0); |
| 293 | int k = f(S()); // expected-error {{cannot pass}} |
| 294 | } |
| 295 | |
| 296 | namespace dr635 { // dr635: yes |
| 297 | template<typename T> struct A { A(); ~A(); }; |
| 298 | template<typename T> A<T>::A<T>() {} // expected-error {{cannot have template arguments}} |
| 299 | template<typename T> A<T>::~A<T>() {} |
| 300 | |
| 301 | template<typename T> struct B { B(); ~B(); }; |
| 302 | template<typename T> B<T>::B() {} |
| 303 | template<typename T> B<T>::~B() {} |
| 304 | |
| 305 | struct C { template<typename T> C(); C(); }; |
| 306 | template<typename T> C::C() {} |
| 307 | C::C() {} |
| 308 | template<> C::C<int>() {} // expected-error {{constructor name}} expected-error {{unqualified-id}} |
| 309 | /*FIXME: needed for error recovery:*/; |
| 310 | |
| 311 | template<typename T> struct D { template<typename U> D(); D(); }; |
| 312 | template<typename T> D<T>::D() {} // expected-note {{previous}} |
| 313 | template<typename T> template<typename U> D<T>::D() {} |
| 314 | template<typename T> D<T>::D<T>() {} // expected-error {{redefinition}} expected-error {{cannot have template arg}} |
| 315 | } |
| 316 | |
| 317 | namespace dr637 { // dr637: yes |
| 318 | void f(int i) { |
| 319 | i = ++i + 1; |
| 320 | i = i++ + 1; // expected-warning {{unsequenced}} |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | namespace dr638 { // dr638: no |
| 325 | template<typename T> struct A { |
| 326 | struct B; |
| 327 | void f(); |
| 328 | void g(); |
| 329 | struct C { |
| 330 | void h(); |
| 331 | }; |
| 332 | }; |
| 333 | |
| 334 | class X { |
| 335 | typedef int type; |
| 336 | template<class T> friend struct A<T>::B; // expected-warning {{not supported}} |
| 337 | template<class T> friend void A<T>::f(); // expected-warning {{not supported}} |
| 338 | template<class T> friend void A<T>::g(); // expected-warning {{not supported}} |
| 339 | template<class T> friend void A<T>::C::h(); // expected-warning {{not supported}} |
| 340 | }; |
| 341 | |
| 342 | template<> struct A<int> { |
| 343 | X::type a; // FIXME: private |
| 344 | struct B { |
| 345 | X::type b; // ok |
| 346 | }; |
| 347 | int f() { X::type c; } // FIXME: private |
| 348 | void g() { X::type d; } // ok |
| 349 | struct D { |
| 350 | void h() { X::type e; } // FIXME: private |
| 351 | }; |
| 352 | }; |
| 353 | } |
| 354 | |
| 355 | namespace dr639 { // dr639: yes |
| 356 | void f(int i) { |
| 357 | void((i = 0) + (i = 0)); // expected-warning {{unsequenced}} |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | namespace dr641 { // dr641: yes |
| 362 | namespace std_example { |
| 363 | struct abc; |
| 364 | |
| 365 | struct xyz { |
| 366 | xyz(); // expected-note 0-1{{candidate}} |
| 367 | xyz(xyz &); // expected-note 0-1{{candidate}} |
| 368 | |
| 369 | operator xyz &() = delete; // expected-error 0-1{{extension}} expected-warning {{will never be used}} |
| 370 | operator abc &() = delete; // expected-error 0-1{{extension}} |
| 371 | }; |
| 372 | |
| 373 | struct abc : xyz {}; |
| 374 | |
| 375 | template<typename T> |
| 376 | void use(T &); // expected-note {{expects an l-value}} |
| 377 | void test() { |
| 378 | use<xyz>(xyz()); // expected-error {{no match}} |
| 379 | use<const xyz>(xyz()); |
| 380 | #if __cplusplus < 201103L |
| 381 | // expected-error-re@-2 {{no viable constructor copying parameter of type '{{.*}}xyz'}} |
| 382 | #endif |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | template<typename T> struct error { typedef typename T::error type; }; |
| 387 | |
| 388 | struct A { |
| 389 | template<typename T, typename error<T>::type = 0> operator T() const; // expected-error 0-1{{extension}} |
| 390 | }; |
| 391 | A a; |
| 392 | void f(A&); // expected-note 2{{candidate}} |
| 393 | void g(const A ca) { |
| 394 | f(A()); // expected-error {{no match}} |
| 395 | f(ca); // expected-error {{no match}} |
| 396 | (void)A(); |
| 397 | (void)ca; |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | namespace dr642 { // dr642: yes |
| 402 | void f() { |
| 403 | const int i = 2; |
| 404 | { |
| 405 | char i[i]; |
| 406 | _Static_assert(sizeof(i) == 2, ""); // expected-error {{C11}} |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | struct s { int a; }; |
| 411 | void g(int s) { |
| 412 | struct s *p = new struct s; |
| 413 | p->a = s; |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | #if __cplusplus >= 201103L |
| 418 | namespace dr643 { // dr643: yes |
| 419 | struct A { |
| 420 | int x; |
| 421 | auto f() -> decltype(this->x); |
| 422 | auto f(A &a) -> decltype(a.x); |
| 423 | auto g() -> decltype(x); |
| 424 | auto h() -> decltype(this->y); // expected-error {{no member named 'y'}} |
| 425 | auto h(A &a) -> decltype(a.y); // expected-error {{no member named 'y'}} |
| 426 | auto i() -> decltype(y); // expected-error {{undeclared identifier 'y'}} |
| 427 | int y; |
| 428 | }; |
| 429 | } |
| 430 | #endif |
| 431 | |
| 432 | #if __cplusplus >= 201103L |
| 433 | namespace dr644 { // dr644: partial |
| 434 | struct A { |
| 435 | A() = default; |
| 436 | int x, y; |
| 437 | }; |
| 438 | static_assert(__is_literal_type(A), ""); |
| 439 | |
| 440 | struct B : A {}; |
| 441 | static_assert(__is_literal_type(B), ""); |
| 442 | |
| 443 | struct C : virtual A {}; |
| 444 | static_assert(!__is_literal_type(C), ""); |
| 445 | |
| 446 | struct D { C c; }; |
| 447 | static_assert(!__is_literal_type(D), ""); |
| 448 | |
| 449 | // FIXME: According to DR644, E<C> is a literal type despite having virtual |
| 450 | // base classes. This appears to be a wording defect. |
| 451 | template<typename T> |
| 452 | struct E : T { |
| 453 | constexpr E() = default; |
| 454 | }; |
| 455 | static_assert(!__is_literal_type(E<C>), ""); |
| 456 | } |
| 457 | #endif |
| 458 | |
| 459 | // dr645 increases permission to optimize; it's not clear that it's possible to |
| 460 | // test for this. |
| 461 | // dr645: na |
| 462 | |
| 463 | #if __cplusplus >= 201103L |
| 464 | namespace dr646 { // dr646: sup 981 |
| 465 | struct A { |
| 466 | constexpr A(const A&) = default; // ok |
| 467 | }; |
| 468 | |
| 469 | struct B { |
| 470 | constexpr B() {} |
| 471 | B(B&); |
| 472 | }; |
| 473 | constexpr B b = {}; // ok |
| 474 | } |
| 475 | #endif |
| 476 | |
| 477 | #if __cplusplus >= 201103L |
| 478 | namespace dr647 { // dr647: yes |
| 479 | // This is partially superseded by dr1358. |
| 480 | struct A { |
| 481 | constexpr virtual void f() const; |
| 482 | constexpr virtual void g() const {} // expected-error {{virtual function cannot be constexpr}} |
| 483 | }; |
| 484 | |
| 485 | struct X { virtual void f() const; }; // expected-note {{overridden}} |
| 486 | struct B : X { |
| 487 | constexpr void f() const {} // expected-error {{virtual function cannot be constexpr}} |
| 488 | }; |
| 489 | |
| 490 | struct NonLiteral { NonLiteral() {} }; // expected-note {{not an aggregate and has no constexpr constructors}} |
| 491 | |
| 492 | struct C { |
| 493 | constexpr C(NonLiteral); |
| 494 | constexpr C(NonLiteral, int) {} // expected-error {{not a literal type}} |
| 495 | constexpr C() try {} catch (...) {} |
| 496 | #if __cplusplus <= 201703L |
| 497 | // expected-error@-2 {{function try block in constexpr constructor is a C++2a extension}} |
| 498 | #endif |
| 499 | #if __cplusplus < 201402L |
| 500 | // expected-error@-5 {{use of this statement in a constexpr constructor is a C++14 extension}} |
| 501 | #endif |
| 502 | }; |
| 503 | |
| 504 | struct D { |
| 505 | operator int() const; |
| 506 | constexpr D(int) {} |
| 507 | D(float); // expected-note 2{{declared here}} |
| 508 | }; |
| 509 | constexpr int get(); |
| 510 | struct E { |
| 511 | int n; |
| 512 | D d; |
| 513 | |
| 514 | // FIXME: We should diagnose this, as the conversion function is not |
| 515 | // constexpr. However, that part of this issue is supreseded by dr1364 and |
| 516 | // others; no diagnostic is required for this any more. |
| 517 | constexpr E() |
| 518 | : n(D(0)), |
| 519 | d(0) {} |
| 520 | |
| 521 | constexpr E(int) // expected-error {{never produces a constant expression}} |
| 522 | : n(0), |
| 523 | d(0.0f) {} // expected-note {{non-constexpr constructor}} |
| 524 | constexpr E(float f) // expected-error {{never produces a constant expression}} |
| 525 | : n(get()), |
| 526 | d(D(0) + f) {} // expected-note {{non-constexpr constructor}} |
| 527 | }; |
| 528 | } |
| 529 | #endif |
| 530 | |
| 531 | #if __cplusplus >= 201103L |
| 532 | namespace dr648 { // dr648: yes |
| 533 | int f(); |
| 534 | constexpr int a = (true ? 1 : f()); |
| 535 | constexpr int b = false && f(); |
| 536 | constexpr int c = true || f(); |
| 537 | } |
| 538 | #endif |
| 539 | |
| 540 | #if __cplusplus >= 201103L |
| 541 | namespace dr649 { // dr649: yes |
| 542 | alignas(0x20000000) int n; // expected-error {{requested alignment}} |
| 543 | struct alignas(0x20000000) X {}; // expected-error {{requested alignment}} |
| 544 | struct Y { int n alignas(0x20000000); }; // expected-error {{requested alignment}} |
| 545 | struct alignas(256) Z {}; |
| 546 | // This part is superseded by dr2130 and eventually by aligned allocation support. |
| 547 | auto *p = new Z; |
| 548 | } |
| 549 | #endif |
| 550 | |
| 551 | // dr650 FIXME: add codegen test |
| 552 | |
| 553 | #if __cplusplus >= 201103L |
| 554 | namespace dr651 { // dr651: yes |
| 555 | struct X { |
| 556 | virtual X &f(); |
| 557 | }; |
| 558 | struct Y : X { |
| 559 | Y &f(); |
| 560 | }; |
| 561 | using T = decltype(((X&&)Y()).f()); |
| 562 | using T = X &; |
| 563 | } |
| 564 | #endif |
| 565 | |
| 566 | #if __cplusplus >= 201103L |
| 567 | namespace dr652 { // dr652: yes |
| 568 | constexpr int n = 1.2 * 3.4; |
| 569 | static_assert(n == 4, ""); |
| 570 | } |
| 571 | #endif |
| 572 | |
| 573 | // dr653 FIXME: add codegen test |
| 574 | |
| 575 | #if __cplusplus >= 201103L |
| 576 | namespace dr654 { // dr654: yes |
| 577 | void f() { |
| 578 | if (nullptr) {} // expected-warning {{implicit conversion of nullptr constant to 'bool'}} |
| 579 | bool b = nullptr; // expected-warning {{implicit conversion of nullptr constant to 'bool'}} |
| 580 | if (nullptr == 0) {} |
| 581 | if (nullptr != 0) {} |
| 582 | if (nullptr <= 0) {} // expected-error {{invalid operands}} |
| 583 | if (nullptr == 1) {} // expected-error {{invalid operands}} |
| 584 | if (!nullptr) {} // expected-warning {{implicit conversion of nullptr constant to 'bool'}} |
| 585 | decltype(nullptr) n = 0; |
| 586 | static_cast<int>(nullptr); // expected-error {{not allowed}} |
| 587 | (void)static_cast<decltype(nullptr)>(0); |
| 588 | static_cast<decltype(nullptr)>(1); // expected-error {{not allowed}} |
| 589 | void(true ? nullptr : 0); |
| 590 | void(true ? 0 : nullptr); |
| 591 | } |
| 592 | } |
| 593 | #endif |
| 594 | |
| 595 | namespace dr655 { // dr655: yes |
| 596 | struct A { A(int); }; // expected-note 2-3{{not viable}} |
| 597 | struct B : A { |
| 598 | A a; |
| 599 | B(); |
| 600 | B(int) : B() {} // expected-error 0-1 {{C++11}} |
| 601 | B(int*) : A() {} // expected-error {{no matching constructor}} |
| 602 | }; |
| 603 | } |
| 604 | |
| 605 | namespace dr656 { // dr656: yes |
| 606 | struct A { A(const A&) = delete; }; // expected-error 0-1 {{C++11}} |
| 607 | struct B : A {}; |
| 608 | struct X { operator B(); } x; |
| 609 | const A &r = x; |
| 610 | struct Y : private A { // expected-note 2{{here}} expected-note 2{{candidate}} |
| 611 | operator B() volatile; |
| 612 | }; |
| 613 | extern Y y; |
| 614 | extern volatile Y vy; |
| 615 | // Conversion not considered due to reference-related types. |
| 616 | const A &s = y; // expected-error {{private base class}} |
| 617 | const A &t = vy; // expected-error {{drops 'volatile'}} |
| 618 | |
| 619 | struct C { operator struct D(); } c; |
| 620 | struct D : C {}; |
| 621 | const D &d = c; // ok, D not reference-related to C |
| 622 | |
| 623 | template<typename T> void accept(T); // expected-note {{candidate}} |
| 624 | template<typename T> void accept(...) = delete; // expected-error 0-1 {{C++11}} expected-note {{candidate}} |
| 625 | void f() { |
| 626 | accept<const A&>(x); |
| 627 | accept<const A&>(y); // expected-error {{private base class}} |
| 628 | accept<const A&>(vy); // expected-error {{call to deleted}} expected-error {{no matching constructor}} |
| 629 | accept<const D&>(c); |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | namespace dr657 { // dr657: partial |
| 634 | struct Abs { virtual void x() = 0; }; |
| 635 | struct Der : public Abs { virtual void x(); }; |
| 636 | |
| 637 | struct Cnvt { template<typename F> Cnvt(F); }; |
| 638 | |
| 639 | void foo(Cnvt a); |
| 640 | void foo(Abs &a); |
| 641 | void f(Abs *a) { foo(*a); } |
| 642 | |
| 643 | void bar(Abs &a); |
| 644 | template<typename T> void bar(T); |
| 645 | void g(Abs *a) { bar(*a); } |
| 646 | |
| 647 | // FIXME: The following examples demonstrate that we might be accepting the |
| 648 | // above cases for the wrong reason. |
| 649 | |
| 650 | // FIXME: We should reject this. |
| 651 | struct C { C(Abs) {} }; |
| 652 | // FIXME: We should reject this. |
| 653 | struct Q { operator Abs() { __builtin_unreachable(); } } q; |
| 654 | #if __cplusplus >= 201703L |
| 655 | // FIXME: We should *definitely* reject this. |
| 656 | C c = Q().operator Abs(); |
| 657 | #endif |
| 658 | |
| 659 | template<typename F> struct Cnvt2 { Cnvt2(F); typedef int type; }; |
| 660 | |
| 661 | // FIXME: We should reject this. |
| 662 | void baz(Abs &a); |
| 663 | template<typename T> typename Cnvt2<T>::type baz(T); |
| 664 | void h(Abs *a) { baz(*a); } |
| 665 | |
| 666 | // FIXME: We should reject this too. |
| 667 | Cnvt2<Abs>::type err; |
| 668 | } |
| 669 | |
| 670 | // dr658 FIXME: add codegen test |
| 671 | |
| 672 | #if __cplusplus >= 201103L |
| 673 | namespace dr659 { // dr659: yes |
| 674 | static_assert(alignof(char) == alignof(char&), ""); |
| 675 | static_assert(alignof(int) == alignof(int&), ""); |
| 676 | int n = alignof(int(&)()); // expected-error {{application of 'alignof' to a function type}} |
| 677 | struct A; // expected-note {{forward}} |
| 678 | int m = alignof(A&); // expected-error {{application of 'alignof' to an incomplete type}} |
| 679 | } |
| 680 | #endif |
| 681 | |
| 682 | #if __cplusplus >= 201103L |
| 683 | namespace dr660 { // dr660: yes |
| 684 | enum : int { a }; |
| 685 | enum class { b }; // expected-error {{requires a name}} |
| 686 | auto x = a; |
| 687 | |
| 688 | struct X { |
| 689 | enum : int { a }; |
| 690 | enum class { b }; // expected-error {{requires a name}} |
| 691 | }; |
| 692 | auto y = X::a; |
| 693 | } |
| 694 | #endif |
| 695 | |
| 696 | // dr661 FIXME: add codegen test |
| 697 | |
| 698 | namespace dr662 { // dr662: yes |
| 699 | template <typename T> void f(T t) { |
| 700 | T &tr = t; |
| 701 | T *tp = &t; // expected-error {{pointer to a reference}} |
| 702 | #if __cplusplus >= 201103L |
| 703 | auto *ap = &t; |
| 704 | #endif |
| 705 | } |
| 706 | void g(int n) { f<int&>(n); } // expected-note {{instantiation of}} |
| 707 | } |
| 708 | |
| 709 | namespace dr663 { // dr663: yes c++11 |
| 710 | int ЍЎ = 123; |
| 711 | #if __cplusplus < 201103L |
| 712 | // expected-error@-2 {{non-ASCII}} |
| 713 | #endif |
| 714 | } |
| 715 | |
| 716 | #if __cplusplus >= 201103L |
| 717 | namespace dr664 { // dr664: yes |
| 718 | struct A { A(const A&) = delete; }; |
| 719 | A &&f(A &&a, int n) { |
| 720 | if (n) |
| 721 | return f(static_cast<A&&>(a), n - 1); |
| 722 | return static_cast<A&&>(a); |
| 723 | } |
| 724 | } |
| 725 | #endif |
| 726 | |
| 727 | namespace dr665 { // dr665: yes |
| 728 | struct A { virtual ~A(); }; |
| 729 | struct B : A {} *b; |
| 730 | struct C : private A {} *c; // expected-note {{here}} |
| 731 | struct D : B, C {} *d; |
| 732 | |
| 733 | struct VB : virtual A {} *vb; |
| 734 | struct VC : private virtual A {} *vc; // expected-note {{here}} |
| 735 | struct VD : VB, VC {} *vd; |
| 736 | |
| 737 | void f() { |
| 738 | (void)dynamic_cast<A*>(b); |
| 739 | (void)dynamic_cast<A*>(c); // expected-error {{private}} |
| 740 | (void)dynamic_cast<A*>(d); // expected-error {{ambiguous}} |
| 741 | (void)dynamic_cast<A*>(vb); |
| 742 | (void)dynamic_cast<A*>(vc); // expected-error {{private}}, even though it could be valid at runtime |
| 743 | (void)dynamic_cast<A*>(vd); |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | namespace dr666 { // dr666: yes |
| 748 | struct P { friend P operator*(P, P); P(int); } p(0); |
| 749 | |
| 750 | template<int> int f(); |
| 751 | template<typename T> int f() { |
| 752 | T::type *p = 0; // expected-error {{missing 'typename'}} |
| 753 | int a(T::type); // expected-error {{missing 'typename'}} |
| 754 | return f<T::type>(); // expected-error {{missing 'typename'}} |
| 755 | } |
| 756 | struct X { static const int type = 0; }; |
| 757 | struct Y { typedef int type; }; |
| 758 | int a = f<X>(); |
| 759 | int b = f<Y>(); // expected-note {{instantiation of}} |
| 760 | } |
| 761 | |
| 762 | // Triviality is entirely different in C++98. |
| 763 | #if __cplusplus >= 201103L |
| 764 | namespace dr667 { // dr667: yes |
| 765 | struct A { |
| 766 | A() = default; // expected-warning {{explicitly defaulted default constructor is implicitly deleted}} |
| 767 | int &r; // expected-note {{because field 'r' of reference type 'int &' would not be initialized}} |
| 768 | }; |
| 769 | static_assert(!__is_trivially_constructible(A), ""); |
| 770 | |
| 771 | struct B { ~B() = delete; }; |
| 772 | union C { B b; }; |
| 773 | static_assert(!__is_trivially_destructible(C), ""); |
| 774 | |
| 775 | struct D { D(const D&) = delete; }; |
| 776 | struct E : D {}; |
| 777 | static_assert(!__is_trivially_constructible(E, const E&), ""); |
| 778 | |
| 779 | struct F { F &operator=(F&&) = delete; }; |
| 780 | struct G : F {}; |
| 781 | static_assert(!__is_trivially_assignable(G, G&&), ""); |
| 782 | } |
| 783 | #endif |
| 784 | |
| 785 | // dr668 FIXME: add codegen test |
| 786 | |
| 787 | #if __cplusplus >= 201103L |
| 788 | namespace dr669 { // dr669: yes |
| 789 | void f() { |
| 790 | int n; |
| 791 | using T = decltype(n); |
| 792 | using T = int; |
| 793 | using U = decltype((n)); |
| 794 | using U = int &; |
| 795 | |
| 796 | [=] { |
| 797 | using V = decltype(n); |
| 798 | using V = int; |
| 799 | using W = decltype((n)); |
| 800 | using W = const int&; |
| 801 | } (); |
| 802 | |
| 803 | struct X { |
| 804 | int n; |
| 805 | void f() const { |
| 806 | using X = decltype(n); |
| 807 | using X = int; |
| 808 | using Y = decltype((n)); |
| 809 | using Y = const int&; |
| 810 | } |
| 811 | }; |
| 812 | } |
| 813 | } |
| 814 | #endif |
| 815 | |
| 816 | namespace dr671 { // dr671: yes |
| 817 | enum class E { e }; // expected-error 0-1 {{C++11}} |
| 818 | E e = static_cast<E>(0); |
| 819 | int n = static_cast<int>(E::e); // expected-error 0-1 {{C++11}} |
| 820 | int m = static_cast<int>(e); // expected-error 0-1 {{C++11}} |
| 821 | } |
| 822 | |
| 823 | // dr672 FIXME: add codegen test |
| 824 | |
| 825 | namespace dr673 { // dr673: yes |
| 826 | template<typename> struct X { static const int n = 0; }; |
| 827 | |
| 828 | class A { |
| 829 | friend class B *f(); |
| 830 | class C *f(); |
| 831 | void f(class D *); |
| 832 | enum { e = X<struct E>::n }; |
| 833 | void g() { extern struct F *p; } |
| 834 | }; |
| 835 | B *b; |
| 836 | C *c; |
| 837 | D *d; |
| 838 | E *e; |
| 839 | F *f; // expected-error {{unknown type name}} |
| 840 | } |
| 841 | |
| 842 | namespace dr674 { // dr674: 8 |
| 843 | template<typename T> int f(T); |
| 844 | |
| 845 | int g(int); |
| 846 | template<typename T> int g(T); |
| 847 | |
| 848 | int h(int); |
| 849 | template<typename T> int h(T); |
| 850 | |
| 851 | class X { |
| 852 | friend int dr674::f(int); |
| 853 | friend int dr674::g(int); |
| 854 | friend int dr674::h<>(int); |
| 855 | int n; // expected-note 2{{private}} |
| 856 | }; |
| 857 | |
| 858 | template<typename T> int f(T) { return X().n; } |
| 859 | int g(int) { return X().n; } |
| 860 | template<typename T> int g(T) { return X().n; } // expected-error {{private}} |
| 861 | int h(int) { return X().n; } // expected-error {{private}} |
| 862 | template<typename T> int h(T) { return X().n; } |
| 863 | |
| 864 | template int f(int); |
| 865 | template int g(int); // expected-note {{in instantiation of}} |
| 866 | template int h(int); |
| 867 | |
| 868 | |
| 869 | struct Y { |
| 870 | template<typename T> int f(T); |
| 871 | |
| 872 | int g(int); |
| 873 | template<typename T> int g(T); |
| 874 | |
| 875 | int h(int); |
| 876 | template<typename T> int h(T); |
| 877 | }; |
| 878 | |
| 879 | class Z { |
| 880 | friend int Y::f(int); |
| 881 | friend int Y::g(int); |
| 882 | friend int Y::h<>(int); |
| 883 | int n; // expected-note 2{{private}} |
| 884 | }; |
| 885 | |
| 886 | template<typename T> int Y::f(T) { return Z().n; } |
| 887 | int Y::g(int) { return Z().n; } |
| 888 | template<typename T> int Y::g(T) { return Z().n; } // expected-error {{private}} |
| 889 | int Y::h(int) { return Z().n; } // expected-error {{private}} |
| 890 | template<typename T> int Y::h(T) { return Z().n; } |
| 891 | |
| 892 | // FIXME: Should the <> be required here? |
| 893 | template int Y::f<>(int); |
| 894 | template int Y::g<>(int); // expected-note {{in instantiation of}} |
| 895 | template int Y::h<>(int); |
| 896 | } |
| 897 | |
| 898 | namespace dr675 { // dr675: dup 739 |
| 899 | template<typename T> struct A { T n : 1; }; |
| 900 | #if __cplusplus >= 201103L |
| 901 | static_assert(A<char>{1}.n < 0, ""); |
| 902 | static_assert(A<int>{1}.n < 0, ""); |
| 903 | static_assert(A<long long>{1}.n < 0, ""); |
| 904 | #endif |
| 905 | } |
| 906 | |
| 907 | // dr676: na |
| 908 | |
| 909 | namespace dr677 { // dr677: no |
| 910 | struct A { |
| 911 | void *operator new(std::size_t); |
| 912 | void operator delete(void*) = delete; // expected-error 0-1{{C++11}} expected-note {{deleted}} |
| 913 | }; |
| 914 | struct B { |
| 915 | void *operator new(std::size_t); |
| 916 | void operator delete(void*) = delete; // expected-error 0-1{{C++11}} expected-note 2{{deleted}} |
| 917 | virtual ~B(); |
| 918 | }; |
| 919 | void f(A *p) { delete p; } // expected-error {{deleted}} |
| 920 | // FIXME: This appears to be valid; we shouldn't even be looking up the 'operator delete' here. |
| 921 | void f(B *p) { delete p; } // expected-error {{deleted}} |
| 922 | B::~B() {} // expected-error {{deleted}} |
| 923 | } |
| 924 | |
| 925 | // dr678 FIXME: check that the modules ODR check catches this |
| 926 | |
| 927 | namespace dr679 { // dr679: yes |
| 928 | struct X {}; |
| 929 | template<int> void operator+(X, X); |
| 930 | template<> void operator+<0>(X, X) {} // expected-note {{previous}} |
| 931 | template<> void operator+<0>(X, X) {} // expected-error {{redefinition}} |
| 932 | } |
| 933 | |
| 934 | // dr680: na |
| 935 | |
| 936 | #if __cplusplus >= 201103L |
| 937 | namespace dr681 { // dr681: partial |
| 938 | auto *a() -> int; // expected-error {{must specify return type 'auto', not 'auto *'}} |
| 939 | auto (*b)() -> int; |
| 940 | // FIXME: The errors here aren't great. |
| 941 | auto (*c()) -> int; // expected-error {{expected function body}} |
| 942 | auto ((*d)()) -> int; // expected-error {{expected ';'}} expected-error {{requires an initializer}} |
| 943 | |
| 944 | // FIXME: This is definitely wrong. This should be |
| 945 | // "function of () returning pointer to function of () returning int" |
| 946 | // not a function with a deduced return type. |
| 947 | auto (*e())() -> int; // expected-error 0-1{{C++14}} |
| 948 | |
| 949 | auto f() -> int (*)(); |
| 950 | auto g() -> auto (*)() -> int; |
| 951 | } |
| 952 | #endif |
| 953 | |
| 954 | #if __cplusplus >= 201103L |
| 955 | namespace dr683 { // dr683: yes |
| 956 | struct A { |
| 957 | A() = default; |
| 958 | A(const A&) = default; |
| 959 | A(A&); |
| 960 | }; |
| 961 | static_assert(__is_trivially_constructible(A, const A&), ""); |
| 962 | static_assert(!__is_trivially_constructible(A, A&), ""); |
| 963 | static_assert(!__is_trivial(A), ""); |
| 964 | |
| 965 | struct B : A {}; |
| 966 | static_assert(__is_trivially_constructible(B, const B&), ""); |
| 967 | static_assert(__is_trivially_constructible(B, B&), ""); |
| 968 | static_assert(__is_trivial(B), ""); |
| 969 | } |
| 970 | #endif |
| 971 | |
| 972 | #if __cplusplus >= 201103L |
| 973 | namespace dr684 { // dr684: sup 1454 |
| 974 | void f() { |
| 975 | int a; // expected-note {{here}} |
| 976 | constexpr int *p = &a; // expected-error {{constant expression}} expected-note {{pointer to 'a'}} |
| 977 | } |
| 978 | } |
| 979 | #endif |
| 980 | |
| 981 | #if __cplusplus >= 201103L |
| 982 | namespace dr685 { // dr685: yes |
| 983 | enum E : long { e }; |
| 984 | void f(int); |
| 985 | int f(long); |
| 986 | int a = f(e); |
| 987 | |
| 988 | enum G : short { g }; |
| 989 | int h(short); |
| 990 | void h(long); |
| 991 | int b = h(g); |
| 992 | |
| 993 | int i(int); |
| 994 | void i(long); |
| 995 | int c = i(g); |
| 996 | |
| 997 | int j(unsigned int); // expected-note {{candidate}} |
| 998 | void j(long); // expected-note {{candidate}} |
| 999 | int d = j(g); // expected-error {{ambiguous}} |
| 1000 | |
| 1001 | int k(short); // expected-note {{candidate}} |
| 1002 | void k(int); // expected-note {{candidate}} |
| 1003 | int x = k(g); // expected-error {{ambiguous}} |
| 1004 | } |
| 1005 | #endif |
| 1006 | |
| 1007 | namespace dr686 { // dr686: yes |
| 1008 | void f() { |
| 1009 | (void)dynamic_cast<struct A*>(0); // expected-error {{incomplete}} expected-note {{forward}} |
| 1010 | (void)dynamic_cast<struct A{}*>(0); // expected-error {{cannot be defined in a type specifier}} |
| 1011 | (void)typeid(struct B*); |
| 1012 | (void)typeid(struct B{}*); // expected-error {{cannot be defined in a type specifier}} |
| 1013 | (void)static_cast<struct C*>(0); |
| 1014 | (void)static_cast<struct C{}*>(0); // expected-error {{cannot be defined in a type specifier}} |
| 1015 | (void)reinterpret_cast<struct D*>(0); |
| 1016 | (void)reinterpret_cast<struct D{}*>(0); // expected-error {{cannot be defined in a type specifier}} |
| 1017 | (void)const_cast<struct E*>(0); // expected-error {{not allowed}} |
| 1018 | (void)const_cast<struct E{}*>(0); // expected-error {{cannot be defined in a type specifier}} |
| 1019 | (void)sizeof(struct F*); |
| 1020 | (void)sizeof(struct F{}*); // expected-error {{cannot be defined in a type specifier}} |
| 1021 | (void)new struct G*; |
| 1022 | (void)new struct G{}*; // expected-error {{cannot be defined in a type specifier}} |
| 1023 | #if __cplusplus >= 201103L |
| 1024 | (void)alignof(struct H*); |
| 1025 | (void)alignof(struct H{}*); // expected-error {{cannot be defined in a type specifier}} |
| 1026 | #endif |
| 1027 | (void)(struct I*)0; |
| 1028 | (void)(struct I{}*)0; // expected-error {{cannot be defined in a type specifier}} |
| 1029 | if (struct J *p = 0) {} |
| 1030 | if (struct J {} *p = 0) {} // expected-error {{cannot be defined in a condition}} |
| 1031 | for (struct K *p = 0; struct L *q = 0; ) {} |
| 1032 | for (struct K {} *p = 0; struct L {} *q = 0; ) {} // expected-error {{'L' cannot be defined in a condition}} |
| 1033 | #if __cplusplus >= 201103L |
| 1034 | using M = struct {}; |
| 1035 | #endif |
| 1036 | struct N { |
| 1037 | operator struct O{}(){}; // expected-error {{cannot be defined in a type specifier}} |
| 1038 | }; |
| 1039 | try {} |
| 1040 | catch (struct P *) {} // expected-error {{incomplete}} expected-note {{forward}} |
| 1041 | catch (struct P {} *) {} // expected-error {{cannot be defined in a type specifier}} |
| 1042 | #if __cplusplus < 201703L |
| 1043 | void g() throw(struct Q); // expected-error {{incomplete}} expected-note {{forward}} |
| 1044 | void h() throw(struct Q {}); // expected-error {{cannot be defined in a type specifier}} |
| 1045 | #endif |
| 1046 | } |
| 1047 | template<struct R *> struct X; |
| 1048 | template<struct R {} *> struct Y; // expected-error {{cannot be defined in a type specifier}} |
| 1049 | } |
| 1050 | |
| 1051 | namespace dr687 { // dr687 still open |
| 1052 | template<typename T> void f(T a) { |
| 1053 | // FIXME: This is valid in C++20. |
| 1054 | g<int>(a); // expected-error {{undeclared}} expected-error {{'('}} |
| 1055 | |
| 1056 | // This is not. |
| 1057 | template g<int>(a); // expected-error {{expected expression}} |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | namespace dr692 { // dr692: no |
| 1062 | namespace temp_func_order_example2 { |
| 1063 | template <typename T, typename U> struct A {}; |
| 1064 | template <typename T, typename U> void f(U, A<U, T> *p = 0); // expected-note {{candidate}} |
| 1065 | template <typename U> int &f(U, A<U, U> *p = 0); // expected-note {{candidate}} |
| 1066 | template <typename T> void g(T, T = T()); |
| 1067 | template <typename T, typename... U> void g(T, U...); // expected-error 0-1{{C++11}} |
| 1068 | void h() { |
| 1069 | int &r = f<int>(42, (A<int, int> *)0); |
| 1070 | f<int>(42); // expected-error {{ambiguous}} |
| 1071 | // FIXME: We should reject this due to ambiguity between the pack and the |
| 1072 | // default argument. Only parameters with arguments are considered during |
| 1073 | // partial ordering of function templates. |
| 1074 | g(42); |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | namespace temp_func_order_example3 { |
| 1079 | template <typename T, typename... U> void f(T, U...); // expected-error 0-1{{C++11}} |
| 1080 | template <typename T> void f(T); |
| 1081 | template <typename T, typename... U> int &g(T *, U...); // expected-error 0-1{{C++11}} |
| 1082 | template <typename T> void g(T); |
| 1083 | void h(int i) { |
| 1084 | // This is made ambiguous by dr692, but made valid again by dr1395. |
| 1085 | f(&i); |
| 1086 | int &r = g(&i); |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | namespace temp_deduct_partial_example { |
| 1091 | template <typename... Args> char &f(Args... args); // expected-error 0-1{{C++11}} |
| 1092 | template <typename T1, typename... Args> short &f(T1 a1, Args... args); // expected-error 0-1{{C++11}} |
| 1093 | template <typename T1, typename T2> int &f(T1 a1, T2 a2); |
| 1094 | void g() { |
| 1095 | char &a = f(); |
| 1096 | short &b = f(1, 2, 3); |
| 1097 | int &c = f(1, 2); |
| 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | namespace temp_deduct_type_example1 { |
| 1102 | template <class T1, class ...Z> class S; // expected-error 0-1{{C++11}} |
| 1103 | template <class T1, class ...Z> class S<T1, const Z&...>; // expected-error 0-1{{C++11}} |
| 1104 | template <class T1, class T2> class S<T1, const T2&> {}; |
| 1105 | S<int, const int&> s; |
| 1106 | |
| 1107 | // FIXME: This should select the first partial specialization. Deduction of |
| 1108 | // the second from the first should succeed, because we should ignore the |
| 1109 | // trailing pack in A with no corresponding P. |
| 1110 | template<class T, class... U> struct A; // expected-error 0-1{{C++11}} |
| 1111 | template<class T1, class T2, class... U> struct A<T1,T2*,U...>; // expected-note {{matches}} expected-error 0-1{{C++11}} |
| 1112 | template<class T1, class T2> struct A<T1,T2> {}; // expected-note {{matches}} |
| 1113 | template struct A<int, int*>; // expected-error {{ambiguous}} |
| 1114 | } |
| 1115 | |
| 1116 | namespace temp_deduct_type_example3 { |
| 1117 | // FIXME: This should select the first template, as in the case above. |
| 1118 | template<class T, class... U> void f(T*, U...){} // expected-note {{candidate}} expected-error 0-1{{C++11}} |
| 1119 | template<class T> void f(T){} // expected-note {{candidate}} |
| 1120 | template void f(int*); // expected-error {{ambiguous}} |
| 1121 | } |
| 1122 | } |
| 1123 | |