| Daniel Dunbar | 8fbe78f | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s | 
| Douglas Gregor | ef1a09a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 2 | template<typename T, T Divisor> | 
|  | 3 | class X { | 
|  | 4 | public: | 
| Chris Lattner | faa5417 | 2010-01-12 21:23:57 +0000 | [diff] [blame] | 5 | static const T value = 10 / Divisor; // expected-error{{in-class initializer is not an integral constant expression}} expected-warning {{division by zero is undefined}} | 
| Douglas Gregor | ef1a09a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 6 | }; | 
|  | 7 |  | 
|  | 8 | int array1[X<int, 2>::value == 5? 1 : -1]; | 
|  | 9 | X<int, 0> xi0; // expected-note{{in instantiation of template class 'class X<int, 0>' requested here}} | 
|  | 10 |  | 
|  | 11 |  | 
|  | 12 | template<typename T> | 
|  | 13 | class Y { | 
|  | 14 | static const T value = 0; // expected-error{{'value' can only be initialized if it is a static const integral data member}} | 
|  | 15 | }; | 
|  | 16 |  | 
|  | 17 | Y<float> fy; // expected-note{{in instantiation of template class 'class Y<float>' requested here}} | 
| Douglas Gregor | d612997 | 2009-07-27 17:43:39 +0000 | [diff] [blame] | 18 |  | 
|  | 19 |  | 
|  | 20 | // out-of-line static member variables | 
|  | 21 |  | 
|  | 22 | template<typename T> | 
|  | 23 | struct Z { | 
|  | 24 | static T value; | 
|  | 25 | }; | 
|  | 26 |  | 
|  | 27 | template<typename T> | 
|  | 28 | T Z<T>::value; // expected-error{{no matching constructor}} | 
|  | 29 |  | 
|  | 30 | struct DefCon {}; | 
|  | 31 |  | 
|  | 32 | struct NoDefCon { | 
| John McCall | fd0b2f8 | 2010-01-06 09:43:14 +0000 | [diff] [blame] | 33 | NoDefCon(const NoDefCon&); // expected-note{{candidate constructor}} | 
| Douglas Gregor | d612997 | 2009-07-27 17:43:39 +0000 | [diff] [blame] | 34 | }; | 
|  | 35 |  | 
|  | 36 | void test() { | 
|  | 37 | DefCon &DC = Z<DefCon>::value; | 
|  | 38 | NoDefCon &NDC = Z<NoDefCon>::value; // expected-note{{instantiation}} | 
| Owen Anderson | 0e0189d | 2009-07-27 22:29:56 +0000 | [diff] [blame] | 39 | } | 
| Douglas Gregor | ff790f1 | 2009-11-26 00:44:06 +0000 | [diff] [blame] | 40 |  | 
|  | 41 | // PR5609 | 
|  | 42 | struct X1 { | 
|  | 43 | ~X1();  // The errors won't be triggered without this dtor. | 
|  | 44 | }; | 
|  | 45 |  | 
|  | 46 | template <typename T> | 
|  | 47 | struct Y1 { | 
|  | 48 | static char Helper(T); | 
|  | 49 | static const int value = sizeof(Helper(T())); | 
|  | 50 | }; | 
|  | 51 |  | 
|  | 52 | struct X2 { | 
|  | 53 | virtual ~X2(); | 
|  | 54 | }; | 
|  | 55 |  | 
|  | 56 | namespace std { | 
|  | 57 | class type_info { }; | 
|  | 58 | } | 
|  | 59 |  | 
|  | 60 | template <typename T> | 
|  | 61 | struct Y2 { | 
|  | 62 | static T &Helper(); | 
|  | 63 | static const int value = sizeof(typeid(Helper())); | 
|  | 64 | }; | 
|  | 65 |  | 
|  | 66 | template <int> | 
|  | 67 | struct Z1 {}; | 
|  | 68 |  | 
|  | 69 | void Test() { | 
|  | 70 | Z1<Y1<X1>::value> x; | 
|  | 71 | int y[Y1<X1>::value]; | 
|  | 72 | Z1<Y2<X2>::value> x2; | 
|  | 73 | int y2[Y2<X2>::value]; | 
|  | 74 | } | 
| Douglas Gregor | 580cd4a | 2009-12-03 17:10:37 +0000 | [diff] [blame] | 75 |  | 
|  | 76 | // PR5672 | 
|  | 77 | template <int n> | 
|  | 78 | struct X3 {}; | 
|  | 79 |  | 
|  | 80 | class Y3 { | 
|  | 81 | public: | 
|  | 82 | ~Y3();  // The error isn't triggered without this dtor. | 
|  | 83 |  | 
|  | 84 | void Foo(X3<1>); | 
|  | 85 | }; | 
|  | 86 |  | 
|  | 87 | template <typename T> | 
|  | 88 | struct SizeOf { | 
|  | 89 | static const int value = sizeof(T); | 
|  | 90 | }; | 
|  | 91 |  | 
|  | 92 | void MyTest3() { | 
|  | 93 | Y3().Foo(X3<SizeOf<char>::value>()); | 
|  | 94 | } |