| 1 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s |
| 2 | |
| 3 | struct X0 { // expected-note 8{{candidate}} |
| 4 | X0(int*, float*); // expected-note 4{{candidate}} |
| 5 | }; |
| 6 | |
| 7 | template<typename T, typename U> |
| 8 | X0 f0(T t, U u) { |
| 9 | X0 x0(t, u); // expected-error{{no matching}} |
| 10 | return X0(t, u); // expected-error{{no matching}} |
| 11 | } |
| 12 | |
| 13 | void test_f0(int *ip, float *fp, double *dp) { |
| 14 | f0(ip, fp); |
| 15 | f0(ip, dp); // expected-note{{instantiation}} |
| 16 | } |
| 17 | |
| 18 | template<typename Ret, typename T, typename U> |
| 19 | Ret f1(Ret *retty, T t, U u) { |
| 20 | Ret r0(t, u); // expected-error{{no matching}} |
| 21 | return Ret(t, u); // expected-error{{no matching}} |
| 22 | } |
| 23 | |
| 24 | void test_f1(X0 *x0, int *ip, float *fp, double *dp) { |
| 25 | f1(x0, ip, fp); |
| 26 | f1(x0, ip, dp); // expected-note{{instantiation}} |
| 27 | } |
| 28 | |
| 29 | namespace PR6457 { |
| 30 | template <typename T> struct X { explicit X(T* p = 0) { }; }; |
| 31 | template <typename T> struct Y { Y(int, const T& x); }; |
| 32 | struct A { }; |
| 33 | template <typename T> |
| 34 | struct B { |
| 35 | B() : y(0, X<A>()) { } |
| 36 | Y<X<A> > y; |
| 37 | }; |
| 38 | B<int> b; |
| 39 | } |
| 40 | |
| 41 | namespace PR6657 { |
| 42 | struct X |
| 43 | { |
| 44 | X (int, int) { } |
| 45 | }; |
| 46 | |
| 47 | template <typename> |
| 48 | void f0() |
| 49 | { |
| 50 | X x = X(0, 0); |
| 51 | } |
| 52 | |
| 53 | void f1() |
| 54 | { |
| 55 | f0<int>(); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // Instantiate out-of-line definitions of static data members which complete |
| 60 | // types through an initializer even when the only use of the member that would |
| 61 | // cause instantiation is in an unevaluated context, but one requiring its |
| 62 | // complete type. |
| 63 | namespace PR10001 { |
| 64 | template <typename T> struct S { |
| 65 | static const int arr[]; |
| 66 | static const int x; |
| 67 | static int f(); |
| 68 | }; |
| 69 | |
| 70 | template <typename T> const int S<T>::arr[] = { 1, 2, 3 }; |
| 71 | template <typename T> const int S<T>::x = sizeof(arr) / sizeof(arr[0]); |
| 72 | template <typename T> int S<T>::f() { return x; } |
| 73 | |
| 74 | int x = S<int>::f(); |
| 75 | } |
| 76 | |
| 77 | namespace PR7985 { |
| 78 | template<int N> struct integral_c { }; |
| 79 | |
| 80 | template <typename T, int N> |
| 81 | integral_c<N> array_lengthof(T (&x)[N]) { return integral_c<N>(); } // expected-note 2{{candidate template ignored: could not match 'T [N]' against 'const Data<}} |
| 82 | |
| 83 | template<typename T> |
| 84 | struct Data { |
| 85 | T x; |
| 86 | }; |
| 87 | |
| 88 | template<typename T> |
| 89 | struct Description { |
| 90 | static const Data<T> data[]; |
| 91 | }; |
| 92 | |
| 93 | template<typename T> |
| 94 | const Data<T> Description<T>::data[] = {{ 1 }}; // expected-error{{cannot initialize a member subobject of type 'int *' with an rvalue of type 'int'}} |
| 95 | |
| 96 | template<> |
| 97 | const Data<float*> Description<float*>::data[]; |
| 98 | |
| 99 | void test() { |
| 100 | integral_c<1> ic1 = array_lengthof(Description<int>::data); |
| 101 | (void)sizeof(array_lengthof(Description<float>::data)); |
| 102 | |
| 103 | sizeof(array_lengthof( // expected-error{{no matching function for call to 'array_lengthof'}} |
| 104 | Description<int*>::data // expected-note{{in instantiation of static data member 'PR7985::Description<int *>::data' requested here}} |
| 105 | )); |
| 106 | |
| 107 | array_lengthof(Description<float*>::data); // expected-error{{no matching function for call to 'array_lengthof'}} |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | namespace PR13064 { |
| 112 | // Ensure that in-class direct-initialization is instantiated as |
| 113 | // direct-initialization and likewise copy-initialization is instantiated as |
| 114 | // copy-initialization. |
| 115 | struct A { explicit A(int); }; // expected-note{{here}} |
| 116 | template<typename T> struct B { T a { 0 }; }; |
| 117 | B<A> b; |
| 118 | template <typename T> struct C { // expected-note {{in instantiation of default member initializer}} |
| 119 | T a = {0}; // expected-error{{explicit}} |
| 120 | }; |
| 121 | C<A> c; // expected-note {{in evaluation of exception spec}} |
| 122 | } |
| 123 | |
| 124 | namespace PR16903 { |
| 125 | // Make sure we properly instantiate list-initialization. |
| 126 | template<typename T> |
| 127 | void fun (T it) { |
| 128 | int m = 0; |
| 129 | for (int i = 0; i < 4; ++i, ++it){ |
| 130 | m |= long{char{*it}}; |
| 131 | } |
| 132 | } |
| 133 | int test() { |
| 134 | char in[4] = {0,0,0,0}; |
| 135 | fun(in); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | namespace ReturnStmtIsInitialization { |
| 140 | struct X { |
| 141 | X() {} |
| 142 | X(const X &) = delete; |
| 143 | }; |
| 144 | template<typename T> X f() { return {}; } |
| 145 | auto &&x = f<void>(); |
| 146 | } |
| 147 | |
| 148 | namespace InitListUpdate { |
| 149 | struct A { int n; }; |
| 150 | using AA = A[1]; |
| 151 | |
| 152 | // Check that an init list update doesn't "lose" the pack-ness of an expression. |
| 153 | template <int... N> void f() { |
| 154 | g(AA{0, [0].n = N} ...); // expected-warning 3{{overrides prior init}} expected-note 3{{previous init}} |
| 155 | g(AA{N, [0].n = 0} ...); // expected-warning 3{{overrides prior init}} expected-note 3{{previous init}} |
| 156 | }; |
| 157 | |
| 158 | void g(AA, AA); |
| 159 | void h() { f<1, 2>(); } // expected-note {{instantiation of}} |
| 160 | } |
| 161 | |