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