blob: 789fe3db872ee01ff2478f08a830ac0689b25138 [file] [log] [blame]
Shih-wei Liaof8fd82b2010-02-10 11:10:31 -08001// RUN: %clang_cc1 -fsyntax-only -verify %s
2template<typename T, T Divisor>
3class X {
4public:
5 static const T value = 10 / Divisor; // expected-error{{in-class initializer is not an integral constant expression}}
6};
7
8int array1[X<int, 2>::value == 5? 1 : -1];
9X<int, 0> xi0; // expected-note{{in instantiation of template class 'class X<int, 0>' requested here}}
10
11
12template<typename T>
13class 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
17Y<float> fy; // expected-note{{in instantiation of template class 'class Y<float>' requested here}}
18
19
20// out-of-line static member variables
21
22template<typename T>
23struct Z {
24 static T value;
25};
26
27template<typename T>
28T Z<T>::value; // expected-error{{no matching constructor}}
29
30struct DefCon {};
31
32struct NoDefCon {
33 NoDefCon(const NoDefCon&); // expected-note{{candidate constructor}}
34};
35
36void test() {
37 DefCon &DC = Z<DefCon>::value;
38 NoDefCon &NDC = Z<NoDefCon>::value; // expected-note{{instantiation}}
39}
40
41// PR5609
42struct X1 {
43 ~X1(); // The errors won't be triggered without this dtor.
44};
45
46template <typename T>
47struct Y1 {
48 static char Helper(T);
49 static const int value = sizeof(Helper(T()));
50};
51
52struct X2 {
53 virtual ~X2();
54};
55
56namespace std {
57 class type_info { };
58}
59
60template <typename T>
61struct Y2 {
62 static T &Helper();
63 static const int value = sizeof(typeid(Helper()));
64};
65
66template <int>
67struct Z1 {};
68
69void 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}
75
76// PR5672
77template <int n>
78struct X3 {};
79
80class Y3 {
81 public:
82 ~Y3(); // The error isn't triggered without this dtor.
83
84 void Foo(X3<1>);
85};
86
87template <typename T>
88struct SizeOf {
89 static const int value = sizeof(T);
90};
91
92void MyTest3() {
93 Y3().Foo(X3<SizeOf<char>::value>());
94}