| 1 | // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors |
| 2 | // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors |
| 3 | // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors |
| 4 | // RUN: %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors |
| 5 | |
| 6 | namespace std { |
| 7 | __extension__ typedef __SIZE_TYPE__ size_t; |
| 8 | |
| 9 | template<typename T> struct initializer_list { |
| 10 | const T *p; size_t n; |
| 11 | initializer_list(const T *p, size_t n); |
| 12 | }; |
| 13 | } |
| 14 | |
| 15 | namespace dr1004 { // dr1004: 5 |
| 16 | template<typename> struct A {}; |
| 17 | template<typename> struct B1 {}; |
| 18 | template<template<typename> class> struct B2 {}; |
| 19 | template<typename X> void f(); // expected-note {{[with X = dr1004::A<int>]}} |
| 20 | template<template<typename> class X> void f(); // expected-note {{[with X = A]}} |
| 21 | template<template<typename> class X> void g(); // expected-note {{[with X = A]}} |
| 22 | template<typename X> void g(); // expected-note {{[with X = dr1004::A<int>]}} |
| 23 | struct C : A<int> { |
| 24 | B1<A> b1a; |
| 25 | B2<A> b2a; |
| 26 | void h() { |
| 27 | f<A>(); // expected-error {{ambiguous}} |
| 28 | g<A>(); // expected-error {{ambiguous}} |
| 29 | } |
| 30 | }; |
| 31 | |
| 32 | // This example (from the standard) is actually ill-formed, because |
| 33 | // name lookup of "T::template A" names the constructor. |
| 34 | template<class T, template<class> class U = T::template A> struct Third { }; // expected-error {{is a constructor name}} |
| 35 | Third<A<int> > t; // expected-note {{in instantiation of default argument}} |
| 36 | } |
| 37 | |
| 38 | namespace dr1048 { // dr1048: 3.6 |
| 39 | struct A {}; |
| 40 | const A f(); |
| 41 | A g(); |
| 42 | typedef const A CA; |
| 43 | #if __cplusplus >= 201103L |
| 44 | // ok: we deduce non-const A in each case. |
| 45 | A &&a = [] (int n) { |
| 46 | while (1) switch (n) { |
| 47 | case 0: return f(); |
| 48 | case 1: return g(); |
| 49 | case 2: return A(); |
| 50 | case 3: return CA(); |
| 51 | } |
| 52 | } (0); |
| 53 | #endif |
| 54 | } |
| 55 | |
| 56 | namespace dr1054 { // dr1054: no |
| 57 | // FIXME: Test is incomplete. |
| 58 | struct A {} volatile a; |
| 59 | void f() { |
| 60 | // FIXME: This is wrong: an lvalue-to-rvalue conversion is applied here, |
| 61 | // which copy-initializes a temporary from 'a'. Therefore this is |
| 62 | // ill-formed because A does not have a volatile copy constructor. |
| 63 | // (We might want to track this aspect under dr1383 instead?) |
| 64 | a; // expected-warning {{assign into a variable to force a volatile load}} |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | namespace dr1070 { // dr1070: 3.5 |
| 69 | #if __cplusplus >= 201103L |
| 70 | struct A { |
| 71 | A(std::initializer_list<int>); |
| 72 | }; |
| 73 | struct B { |
| 74 | int i; |
| 75 | A a; |
| 76 | }; |
| 77 | B b = {1}; |
| 78 | struct C { |
| 79 | std::initializer_list<int> a; |
| 80 | B b; |
| 81 | std::initializer_list<double> c; |
| 82 | }; |
| 83 | C c = {}; |
| 84 | #endif |
| 85 | } |
| 86 | |