2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
2015-12-10 09:07:17 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
|
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
|
|
|
|
|
2009-03-26 07:32:15 +08:00
|
|
|
template<typename T, T Divisor>
|
|
|
|
class X {
|
|
|
|
public:
|
2017-09-24 02:27:11 +08:00
|
|
|
static const T value = 10 / Divisor; // expected-error{{in-class initializer for static data member is not a constant expression}}
|
2009-03-26 07:32:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
int array1[X<int, 2>::value == 5? 1 : -1];
|
2010-03-10 19:27:22 +08:00
|
|
|
X<int, 0> xi0; // expected-note{{in instantiation of template class 'X<int, 0>' requested here}}
|
2009-03-26 07:32:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class Y {
|
2015-12-10 09:07:17 +08:00
|
|
|
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
|
2009-03-26 07:32:15 +08:00
|
|
|
};
|
|
|
|
|
2010-03-10 19:27:22 +08:00
|
|
|
Y<float> fy; // expected-note{{in instantiation of template class 'Y<float>' requested here}}
|
2009-07-28 01:43:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
// out-of-line static member variables
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct Z {
|
|
|
|
static T value;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
T Z<T>::value; // expected-error{{no matching constructor}}
|
|
|
|
|
|
|
|
struct DefCon {};
|
|
|
|
|
|
|
|
struct NoDefCon {
|
2010-01-06 17:43:14 +08:00
|
|
|
NoDefCon(const NoDefCon&); // expected-note{{candidate constructor}}
|
2009-07-28 01:43:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void test() {
|
|
|
|
DefCon &DC = Z<DefCon>::value;
|
|
|
|
NoDefCon &NDC = Z<NoDefCon>::value; // expected-note{{instantiation}}
|
2009-07-28 06:29:56 +08:00
|
|
|
}
|
2009-11-26 08:44:06 +08:00
|
|
|
|
|
|
|
// PR5609
|
|
|
|
struct X1 {
|
|
|
|
~X1(); // The errors won't be triggered without this dtor.
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct Y1 {
|
|
|
|
static char Helper(T);
|
|
|
|
static const int value = sizeof(Helper(T()));
|
|
|
|
};
|
|
|
|
|
|
|
|
struct X2 {
|
|
|
|
virtual ~X2();
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
class type_info { };
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct Y2 {
|
|
|
|
static T &Helper();
|
|
|
|
static const int value = sizeof(typeid(Helper()));
|
|
|
|
};
|
|
|
|
|
|
|
|
template <int>
|
|
|
|
struct Z1 {};
|
|
|
|
|
|
|
|
void Test() {
|
|
|
|
Z1<Y1<X1>::value> x;
|
|
|
|
int y[Y1<X1>::value];
|
|
|
|
Z1<Y2<X2>::value> x2;
|
|
|
|
int y2[Y2<X2>::value];
|
|
|
|
}
|
2009-12-04 01:10:37 +08:00
|
|
|
|
|
|
|
// PR5672
|
|
|
|
template <int n>
|
|
|
|
struct X3 {};
|
|
|
|
|
|
|
|
class Y3 {
|
|
|
|
public:
|
|
|
|
~Y3(); // The error isn't triggered without this dtor.
|
|
|
|
|
|
|
|
void Foo(X3<1>);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct SizeOf {
|
|
|
|
static const int value = sizeof(T);
|
|
|
|
};
|
|
|
|
|
|
|
|
void MyTest3() {
|
|
|
|
Y3().Foo(X3<SizeOf<char>::value>());
|
|
|
|
}
|
2010-03-02 03:11:54 +08:00
|
|
|
|
|
|
|
namespace PR6449 {
|
|
|
|
template<typename T>
|
|
|
|
struct X0 {
|
|
|
|
static const bool var = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
const bool X0<T>::var;
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct X1 : public X0<T> {
|
|
|
|
static const bool var = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
const bool X1<T>::var;
|
|
|
|
|
|
|
|
template class X0<char>;
|
|
|
|
template class X1<char>;
|
|
|
|
|
|
|
|
}
|
2015-01-27 03:04:10 +08:00
|
|
|
|
|
|
|
typedef char MyString[100];
|
|
|
|
template <typename T>
|
|
|
|
struct StaticVarWithTypedefString {
|
|
|
|
static MyString str;
|
|
|
|
};
|
|
|
|
template <typename T>
|
|
|
|
MyString StaticVarWithTypedefString<T>::str = "";
|
|
|
|
|
|
|
|
void testStaticVarWithTypedefString() {
|
|
|
|
(void)StaticVarWithTypedefString<int>::str;
|
|
|
|
}
|