// RUN: %clang_cc1 -fsyntax-only -verify %s // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s template class X { public: static const T value = 10 / Divisor; // expected-error{{in-class initializer for static data member is not a constant expression}} }; int array1[X::value == 5? 1 : -1]; X xi0; // expected-note{{in instantiation of template class 'X' requested here}} template class Y { static const T value = 0; #if __cplusplus <= 199711L // expected-warning@-2 {{in-class initializer for static data member of type 'const float' is a GNU extension}} #else // expected-error@-4 {{in-class initializer for static data member of type 'const float' requires 'constexpr' specifier}} // expected-note@-5 {{add 'constexpr'}} #endif }; Y fy; // expected-note{{in instantiation of template class 'Y' requested here}} // out-of-line static member variables template struct Z { static T value; }; template T Z::value; // expected-error{{no matching constructor}} struct DefCon {}; struct NoDefCon { NoDefCon(const NoDefCon&); // expected-note{{candidate constructor}} }; void test() { DefCon &DC = Z::value; NoDefCon &NDC = Z::value; // expected-note{{instantiation}} } // PR5609 struct X1 { ~X1(); // The errors won't be triggered without this dtor. }; template struct Y1 { static char Helper(T); static const int value = sizeof(Helper(T())); }; struct X2 { virtual ~X2(); }; namespace std { class type_info { }; } template struct Y2 { static T &Helper(); static const int value = sizeof(typeid(Helper())); }; template struct Z1 {}; void Test() { Z1::value> x; int y[Y1::value]; Z1::value> x2; int y2[Y2::value]; } // PR5672 template struct X3 {}; class Y3 { public: ~Y3(); // The error isn't triggered without this dtor. void Foo(X3<1>); }; template struct SizeOf { static const int value = sizeof(T); }; void MyTest3() { Y3().Foo(X3::value>()); } namespace PR6449 { template struct X0 { static const bool var = false; }; template const bool X0::var; template struct X1 : public X0 { static const bool var = false; }; template const bool X1::var; template class X0; template class X1; } typedef char MyString[100]; template struct StaticVarWithTypedefString { static MyString str; }; template MyString StaticVarWithTypedefString::str = ""; void testStaticVarWithTypedefString() { (void)StaticVarWithTypedefString::str; } namespace ArrayBound { #if __cplusplus >= 201103L template void make_unique(T &&); template struct Foo { static constexpr char kMessage[] = "abc"; static void f() { make_unique(kMessage); } static void g1() { const char (&ref)[4] = kMessage; } // OK // We can diagnose this prior to instantiation because kMessage is not type-dependent. static void g2() { const char (&ref)[5] = kMessage; } // expected-error {{could not bind}} }; template void Foo::f(); #endif template struct Bar { static const char kMessage[]; // Here, kMessage is type-dependent, so we don't diagnose until // instantiation. static void g1() { const char (&ref)[4] = kMessage; } // expected-error {{could not bind to an lvalue of type 'const char [5]'}} static void g2() { const char (&ref)[5] = kMessage; } // expected-error {{could not bind to an lvalue of type 'const char [4]'}} }; template const char Bar::kMessage[] = "foo"; template void Bar::g1(); template void Bar::g2(); // expected-note {{in instantiation of}} template<> const char Bar::kMessage[] = "foox"; template void Bar::g1(); // expected-note {{in instantiation of}} template void Bar::g2(); }