Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify %s |
| 2 | |
| 3 | template<typename T, T Divisor> |
| 4 | class X { |
| 5 | public: |
| 6 | static const T value = 10 / Divisor; // expected-error{{in-class initializer is not an integral constant expression}} |
| 7 | }; |
| 8 | |
| 9 | int array1[X<int, 2>::value == 5? 1 : -1]; |
| 10 | X<int, 0> xi0; // expected-note{{in instantiation of template class 'class X<int, 0>' requested here}} |
| 11 | |
| 12 | |
| 13 | template<typename T> |
| 14 | class Y { |
| 15 | static const T value = 0; // expected-error{{'value' can only be initialized if it is a static const integral data member}} |
| 16 | }; |
| 17 | |
| 18 | Y<float> fy; // expected-note{{in instantiation of template class 'class Y<float>' requested here}} |
Douglas Gregor | 65b9005 | 2009-07-27 17:43:39 +0000 | [diff] [blame] | 19 | |
| 20 | |
| 21 | // out-of-line static member variables |
| 22 | |
| 23 | template<typename T> |
| 24 | struct Z { |
| 25 | static T value; |
| 26 | }; |
| 27 | |
| 28 | template<typename T> |
| 29 | T Z<T>::value; // expected-error{{no matching constructor}} |
| 30 | |
| 31 | struct DefCon {}; |
| 32 | |
| 33 | struct NoDefCon { |
| 34 | NoDefCon(const NoDefCon&); |
| 35 | }; |
| 36 | |
| 37 | void test() { |
| 38 | DefCon &DC = Z<DefCon>::value; |
| 39 | NoDefCon &NDC = Z<NoDefCon>::value; // expected-note{{instantiation}} |
Owen Anderson | 08e2524 | 2009-07-27 22:29:56 +0000 | [diff] [blame] | 40 | } |