1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s 2*f4a2713aSLionel Sambuc template<typename T, T Divisor> 3*f4a2713aSLionel Sambuc class X { 4*f4a2713aSLionel Sambuc public: 5*f4a2713aSLionel Sambuc static const T value = 10 / Divisor; // expected-error{{in-class initializer for static data member is not a constant expression}} 6*f4a2713aSLionel Sambuc }; 7*f4a2713aSLionel Sambuc 8*f4a2713aSLionel Sambuc int array1[X<int, 2>::value == 5? 1 : -1]; 9*f4a2713aSLionel Sambuc X<int, 0> xi0; // expected-note{{in instantiation of template class 'X<int, 0>' requested here}} 10*f4a2713aSLionel Sambuc 11*f4a2713aSLionel Sambuc 12*f4a2713aSLionel Sambuc template<typename T> 13*f4a2713aSLionel Sambuc class Y { 14*f4a2713aSLionel Sambuc static const T value = 0; // expected-warning{{in-class initializer for static data member of type 'const float' is a GNU extension}} 15*f4a2713aSLionel Sambuc }; 16*f4a2713aSLionel Sambuc 17*f4a2713aSLionel Sambuc Y<float> fy; // expected-note{{in instantiation of template class 'Y<float>' requested here}} 18*f4a2713aSLionel Sambuc 19*f4a2713aSLionel Sambuc 20*f4a2713aSLionel Sambuc // out-of-line static member variables 21*f4a2713aSLionel Sambuc 22*f4a2713aSLionel Sambuc template<typename T> 23*f4a2713aSLionel Sambuc struct Z { 24*f4a2713aSLionel Sambuc static T value; 25*f4a2713aSLionel Sambuc }; 26*f4a2713aSLionel Sambuc 27*f4a2713aSLionel Sambuc template<typename T> 28*f4a2713aSLionel Sambuc T Z<T>::value; // expected-error{{no matching constructor}} 29*f4a2713aSLionel Sambuc 30*f4a2713aSLionel Sambuc struct DefCon {}; 31*f4a2713aSLionel Sambuc 32*f4a2713aSLionel Sambuc struct NoDefCon { 33*f4a2713aSLionel Sambuc NoDefCon(const NoDefCon&); // expected-note{{candidate constructor}} 34*f4a2713aSLionel Sambuc }; 35*f4a2713aSLionel Sambuc test()36*f4a2713aSLionel Sambucvoid test() { 37*f4a2713aSLionel Sambuc DefCon &DC = Z<DefCon>::value; 38*f4a2713aSLionel Sambuc NoDefCon &NDC = Z<NoDefCon>::value; // expected-note{{instantiation}} 39*f4a2713aSLionel Sambuc } 40*f4a2713aSLionel Sambuc 41*f4a2713aSLionel Sambuc // PR5609 42*f4a2713aSLionel Sambuc struct X1 { 43*f4a2713aSLionel Sambuc ~X1(); // The errors won't be triggered without this dtor. 44*f4a2713aSLionel Sambuc }; 45*f4a2713aSLionel Sambuc 46*f4a2713aSLionel Sambuc template <typename T> 47*f4a2713aSLionel Sambuc struct Y1 { 48*f4a2713aSLionel Sambuc static char Helper(T); 49*f4a2713aSLionel Sambuc static const int value = sizeof(Helper(T())); 50*f4a2713aSLionel Sambuc }; 51*f4a2713aSLionel Sambuc 52*f4a2713aSLionel Sambuc struct X2 { 53*f4a2713aSLionel Sambuc virtual ~X2(); 54*f4a2713aSLionel Sambuc }; 55*f4a2713aSLionel Sambuc 56*f4a2713aSLionel Sambuc namespace std { 57*f4a2713aSLionel Sambuc class type_info { }; 58*f4a2713aSLionel Sambuc } 59*f4a2713aSLionel Sambuc 60*f4a2713aSLionel Sambuc template <typename T> 61*f4a2713aSLionel Sambuc struct Y2 { 62*f4a2713aSLionel Sambuc static T &Helper(); 63*f4a2713aSLionel Sambuc static const int value = sizeof(typeid(Helper())); 64*f4a2713aSLionel Sambuc }; 65*f4a2713aSLionel Sambuc 66*f4a2713aSLionel Sambuc template <int> 67*f4a2713aSLionel Sambuc struct Z1 {}; 68*f4a2713aSLionel Sambuc Test()69*f4a2713aSLionel Sambucvoid Test() { 70*f4a2713aSLionel Sambuc Z1<Y1<X1>::value> x; 71*f4a2713aSLionel Sambuc int y[Y1<X1>::value]; 72*f4a2713aSLionel Sambuc Z1<Y2<X2>::value> x2; 73*f4a2713aSLionel Sambuc int y2[Y2<X2>::value]; 74*f4a2713aSLionel Sambuc } 75*f4a2713aSLionel Sambuc 76*f4a2713aSLionel Sambuc // PR5672 77*f4a2713aSLionel Sambuc template <int n> 78*f4a2713aSLionel Sambuc struct X3 {}; 79*f4a2713aSLionel Sambuc 80*f4a2713aSLionel Sambuc class Y3 { 81*f4a2713aSLionel Sambuc public: 82*f4a2713aSLionel Sambuc ~Y3(); // The error isn't triggered without this dtor. 83*f4a2713aSLionel Sambuc 84*f4a2713aSLionel Sambuc void Foo(X3<1>); 85*f4a2713aSLionel Sambuc }; 86*f4a2713aSLionel Sambuc 87*f4a2713aSLionel Sambuc template <typename T> 88*f4a2713aSLionel Sambuc struct SizeOf { 89*f4a2713aSLionel Sambuc static const int value = sizeof(T); 90*f4a2713aSLionel Sambuc }; 91*f4a2713aSLionel Sambuc MyTest3()92*f4a2713aSLionel Sambucvoid MyTest3() { 93*f4a2713aSLionel Sambuc Y3().Foo(X3<SizeOf<char>::value>()); 94*f4a2713aSLionel Sambuc } 95*f4a2713aSLionel Sambuc 96*f4a2713aSLionel Sambuc namespace PR6449 { 97*f4a2713aSLionel Sambuc template<typename T> 98*f4a2713aSLionel Sambuc struct X0 { 99*f4a2713aSLionel Sambuc static const bool var = false; 100*f4a2713aSLionel Sambuc }; 101*f4a2713aSLionel Sambuc 102*f4a2713aSLionel Sambuc template<typename T> 103*f4a2713aSLionel Sambuc const bool X0<T>::var; 104*f4a2713aSLionel Sambuc 105*f4a2713aSLionel Sambuc template<typename T> 106*f4a2713aSLionel Sambuc struct X1 : public X0<T> { 107*f4a2713aSLionel Sambuc static const bool var = false; 108*f4a2713aSLionel Sambuc }; 109*f4a2713aSLionel Sambuc 110*f4a2713aSLionel Sambuc template<typename T> 111*f4a2713aSLionel Sambuc const bool X1<T>::var; 112*f4a2713aSLionel Sambuc 113*f4a2713aSLionel Sambuc template class X0<char>; 114*f4a2713aSLionel Sambuc template class X1<char>; 115*f4a2713aSLionel Sambuc 116*f4a2713aSLionel Sambuc } 117