1a5728872c7702ddd09537c95bc3cbd20e1f2fb09Daniel Dunbar// RUN: %clang_cc1 -fsyntax-only -verify %s
23d7a12a50558c31d4351e923c15ab57688f4fdf2Douglas Gregortemplate<typename T, T Divisor>
33d7a12a50558c31d4351e923c15ab57688f4fdf2Douglas Gregorclass X {
43d7a12a50558c31d4351e923c15ab57688f4fdf2Douglas Gregorpublic:
5d7c56e1114bfe7d461786903bb720d2c6efc05a1Richard Smith  static const T value = 10 / Divisor; // expected-error{{in-class initializer for static data member is not a constant expression}}
63d7a12a50558c31d4351e923c15ab57688f4fdf2Douglas Gregor};
73d7a12a50558c31d4351e923c15ab57688f4fdf2Douglas Gregor
83d7a12a50558c31d4351e923c15ab57688f4fdf2Douglas Gregorint array1[X<int, 2>::value == 5? 1 : -1];
97c2342dd4c9947806842e5aca3d2bb2e542853c9John McCallX<int, 0> xi0; // expected-note{{in instantiation of template class 'X<int, 0>' requested here}}
103d7a12a50558c31d4351e923c15ab57688f4fdf2Douglas Gregor
113d7a12a50558c31d4351e923c15ab57688f4fdf2Douglas Gregor
123d7a12a50558c31d4351e923c15ab57688f4fdf2Douglas Gregortemplate<typename T>
133d7a12a50558c31d4351e923c15ab57688f4fdf2Douglas Gregorclass Y {
14947be1941e9a1d4233116f51a45799d3904d4231Richard Smith  static const T value = 0; // expected-warning{{in-class initializer for static data member of type 'const float' is a GNU extension}}
153d7a12a50558c31d4351e923c15ab57688f4fdf2Douglas Gregor};
163d7a12a50558c31d4351e923c15ab57688f4fdf2Douglas Gregor
177c2342dd4c9947806842e5aca3d2bb2e542853c9John McCallY<float> fy; // expected-note{{in instantiation of template class 'Y<float>' requested here}}
1865b90055dd30cfb83d8344ff62ed428257431be4Douglas Gregor
1965b90055dd30cfb83d8344ff62ed428257431be4Douglas Gregor
2065b90055dd30cfb83d8344ff62ed428257431be4Douglas Gregor// out-of-line static member variables
2165b90055dd30cfb83d8344ff62ed428257431be4Douglas Gregor
2265b90055dd30cfb83d8344ff62ed428257431be4Douglas Gregortemplate<typename T>
2365b90055dd30cfb83d8344ff62ed428257431be4Douglas Gregorstruct Z {
2465b90055dd30cfb83d8344ff62ed428257431be4Douglas Gregor  static T value;
2565b90055dd30cfb83d8344ff62ed428257431be4Douglas Gregor};
2665b90055dd30cfb83d8344ff62ed428257431be4Douglas Gregor
2765b90055dd30cfb83d8344ff62ed428257431be4Douglas Gregortemplate<typename T>
2865b90055dd30cfb83d8344ff62ed428257431be4Douglas GregorT Z<T>::value; // expected-error{{no matching constructor}}
2965b90055dd30cfb83d8344ff62ed428257431be4Douglas Gregor
3065b90055dd30cfb83d8344ff62ed428257431be4Douglas Gregorstruct DefCon {};
3165b90055dd30cfb83d8344ff62ed428257431be4Douglas Gregor
3265b90055dd30cfb83d8344ff62ed428257431be4Douglas Gregorstruct NoDefCon {
33b1622a1fd7b7f4ab8d00d0183d17c90ad25c14e3John McCall  NoDefCon(const NoDefCon&); // expected-note{{candidate constructor}}
3465b90055dd30cfb83d8344ff62ed428257431be4Douglas Gregor};
3565b90055dd30cfb83d8344ff62ed428257431be4Douglas Gregor
3665b90055dd30cfb83d8344ff62ed428257431be4Douglas Gregorvoid test() {
3765b90055dd30cfb83d8344ff62ed428257431be4Douglas Gregor  DefCon &DC = Z<DefCon>::value;
3865b90055dd30cfb83d8344ff62ed428257431be4Douglas Gregor  NoDefCon &NDC = Z<NoDefCon>::value; // expected-note{{instantiation}}
3908e252425ca2cbdc44ba65d9a657ed5398014e36Owen Anderson}
402afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor
412afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor// PR5609
422afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregorstruct X1 {
432afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor  ~X1();  // The errors won't be triggered without this dtor.
442afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor};
452afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor
462afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregortemplate <typename T>
472afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregorstruct Y1 {
482afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor  static char Helper(T);
492afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor  static const int value = sizeof(Helper(T()));
502afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor};
512afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor
522afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregorstruct X2 {
532afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor  virtual ~X2();
542afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor};
552afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor
562afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregornamespace std {
572afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor  class type_info { };
582afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor}
592afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor
602afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregortemplate <typename T>
612afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregorstruct Y2 {
622afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor  static T &Helper();
632afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor  static const int value = sizeof(typeid(Helper()));
642afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor};
652afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor
662afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregortemplate <int>
672afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregorstruct Z1 {};
682afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor
692afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregorvoid Test() {
702afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor  Z1<Y1<X1>::value> x;
712afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor  int y[Y1<X1>::value];
722afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor  Z1<Y2<X2>::value> x2;
732afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor  int y2[Y2<X2>::value];
742afce7248b7a362f1e322ad18e43484d575b9c9dDouglas Gregor}
751f5f3a4d58a1c7c50c331b33329fc14563533c04Douglas Gregor
761f5f3a4d58a1c7c50c331b33329fc14563533c04Douglas Gregor// PR5672
771f5f3a4d58a1c7c50c331b33329fc14563533c04Douglas Gregortemplate <int n>
781f5f3a4d58a1c7c50c331b33329fc14563533c04Douglas Gregorstruct X3 {};
791f5f3a4d58a1c7c50c331b33329fc14563533c04Douglas Gregor
801f5f3a4d58a1c7c50c331b33329fc14563533c04Douglas Gregorclass Y3 {
811f5f3a4d58a1c7c50c331b33329fc14563533c04Douglas Gregor public:
821f5f3a4d58a1c7c50c331b33329fc14563533c04Douglas Gregor  ~Y3();  // The error isn't triggered without this dtor.
831f5f3a4d58a1c7c50c331b33329fc14563533c04Douglas Gregor
841f5f3a4d58a1c7c50c331b33329fc14563533c04Douglas Gregor  void Foo(X3<1>);
851f5f3a4d58a1c7c50c331b33329fc14563533c04Douglas Gregor};
861f5f3a4d58a1c7c50c331b33329fc14563533c04Douglas Gregor
871f5f3a4d58a1c7c50c331b33329fc14563533c04Douglas Gregortemplate <typename T>
881f5f3a4d58a1c7c50c331b33329fc14563533c04Douglas Gregorstruct SizeOf {
891f5f3a4d58a1c7c50c331b33329fc14563533c04Douglas Gregor  static const int value = sizeof(T);
901f5f3a4d58a1c7c50c331b33329fc14563533c04Douglas Gregor};
911f5f3a4d58a1c7c50c331b33329fc14563533c04Douglas Gregor
921f5f3a4d58a1c7c50c331b33329fc14563533c04Douglas Gregorvoid MyTest3() {
931f5f3a4d58a1c7c50c331b33329fc14563533c04Douglas Gregor   Y3().Foo(X3<SizeOf<char>::value>());
941f5f3a4d58a1c7c50c331b33329fc14563533c04Douglas Gregor}
95449d0a829007ea654912098e6a73134a2c529d61Douglas Gregor
96449d0a829007ea654912098e6a73134a2c529d61Douglas Gregornamespace PR6449 {
97449d0a829007ea654912098e6a73134a2c529d61Douglas Gregor  template<typename T>
98449d0a829007ea654912098e6a73134a2c529d61Douglas Gregor  struct X0  {
99449d0a829007ea654912098e6a73134a2c529d61Douglas Gregor    static const bool var = false;
100449d0a829007ea654912098e6a73134a2c529d61Douglas Gregor  };
101449d0a829007ea654912098e6a73134a2c529d61Douglas Gregor
102449d0a829007ea654912098e6a73134a2c529d61Douglas Gregor  template<typename T>
103449d0a829007ea654912098e6a73134a2c529d61Douglas Gregor  const bool X0<T>::var;
104449d0a829007ea654912098e6a73134a2c529d61Douglas Gregor
105449d0a829007ea654912098e6a73134a2c529d61Douglas Gregor  template<typename T>
106449d0a829007ea654912098e6a73134a2c529d61Douglas Gregor  struct X1 : public X0<T> {
107449d0a829007ea654912098e6a73134a2c529d61Douglas Gregor    static const bool var = false;
108449d0a829007ea654912098e6a73134a2c529d61Douglas Gregor  };
109449d0a829007ea654912098e6a73134a2c529d61Douglas Gregor
110449d0a829007ea654912098e6a73134a2c529d61Douglas Gregor  template<typename T>
111449d0a829007ea654912098e6a73134a2c529d61Douglas Gregor  const bool X1<T>::var;
112449d0a829007ea654912098e6a73134a2c529d61Douglas Gregor
113449d0a829007ea654912098e6a73134a2c529d61Douglas Gregor  template class X0<char>;
114449d0a829007ea654912098e6a73134a2c529d61Douglas Gregor  template class X1<char>;
115449d0a829007ea654912098e6a73134a2c529d61Douglas Gregor
116449d0a829007ea654912098e6a73134a2c529d61Douglas Gregor}
117