1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
5 template<typename T
, T Divisor
>
8 static const T value
= 10 / Divisor
; // expected-error{{in-class initializer for static data member is not a constant expression}}
11 int array1
[X
<int, 2>::value
== 5? 1 : -1];
12 X
<int, 0> xi0
; // expected-note{{in instantiation of template class 'X<int, 0>' requested here}}
17 static const T value
= 0;
18 #if __cplusplus <= 199711L
19 // expected-warning@-2 {{in-class initializer for static data member of type 'const float' is a GNU extension}}
21 // expected-error@-4 {{in-class initializer for static data member of type 'const float' requires 'constexpr' specifier}}
22 // expected-note@-5 {{add 'constexpr'}}
26 Y
<float> fy
; // expected-note{{in instantiation of template class 'Y<float>' requested here}}
29 // out-of-line static member variables
37 T Z
<T
>::value
; // expected-error{{no matching constructor}}
42 NoDefCon(const NoDefCon
&); // expected-note{{candidate constructor}}
46 DefCon
&DC
= Z
<DefCon
>::value
;
47 NoDefCon
&NDC
= Z
<NoDefCon
>::value
; // expected-note{{instantiation}}
52 ~X1(); // The errors won't be triggered without this dtor.
57 static char Helper(T
);
58 static const int value
= sizeof(Helper(T()));
72 static const int value
= sizeof(typeid(Helper()));
82 int y2
[Y2
<X2
>::value
];
91 ~Y3(); // The error isn't triggered without this dtor.
98 static const int value
= sizeof(T
);
102 Y3().Foo(X3
<SizeOf
<char>::value
>());
108 static const bool var
= false;
112 const bool X0
<T
>::var
;
115 struct X1
: public X0
<T
> {
116 static const bool var
= false;
120 const bool X1
<T
>::var
;
122 template class X0
<char>;
123 template class X1
<char>;
127 typedef char MyString
[100];
128 template <typename T
>
129 struct StaticVarWithTypedefString
{
132 template <typename T
>
133 MyString StaticVarWithTypedefString
<T
>::str
= "";
135 void testStaticVarWithTypedefString() {
136 (void)StaticVarWithTypedefString
<int>::str
;
139 namespace ArrayBound
{
140 #if __cplusplus >= 201103L
141 template<typename T
> void make_unique(T
&&);
143 template<typename
> struct Foo
{
144 static constexpr char kMessage
[] = "abc";
145 static void f() { make_unique(kMessage
); }
146 static void g1() { const char (&ref
)[4] = kMessage
; } // OK
147 // We can diagnose this prior to instantiation because kMessage is not type-dependent.
148 static void g2() { const char (&ref
)[5] = kMessage
; } // expected-error {{could not bind}}
150 template void Foo
<int>::f();
153 template<typename
> struct Bar
{
154 static const char kMessage
[];
155 // Here, kMessage is type-dependent, so we don't diagnose until
157 static void g1() { const char (&ref
)[4] = kMessage
; } // expected-error {{could not bind to an lvalue of type 'const char[5]'}}
158 static void g2() { const char (&ref
)[5] = kMessage
; } // expected-error {{could not bind to an lvalue of type 'const char[4]'}}
160 template<typename T
> const char Bar
<T
>::kMessage
[] = "foo";
161 template void Bar
<int>::g1();
162 template void Bar
<int>::g2(); // expected-note {{in instantiation of}}
164 template<> const char Bar
<char>::kMessage
[] = "foox";
165 template void Bar
<char>::g1(); // expected-note {{in instantiation of}}
166 template void Bar
<char>::g2();