p3.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
  2. struct NonLit { // expected-note 3{{no constexpr constructors}}
  3. NonLit();
  4. };
  5. struct S {
  6. static constexpr int a = 0;
  7. static constexpr int b; // expected-error {{declaration of constexpr static data member 'b' requires an initializer}}
  8. static constexpr int c = 0;
  9. static const int d;
  10. static const int d2 = 0;
  11. static constexpr double e = 0.0; // ok
  12. static const double f = 0.0; // expected-error {{requires 'constexpr' specifier}} expected-note {{add 'constexpr'}}
  13. static char *const g = 0; // expected-error {{requires 'constexpr' specifier}}
  14. static const NonLit h = NonLit(); // expected-error {{must be initialized out of line}}
  15. };
  16. constexpr int S::a;
  17. constexpr int S::b = 0;
  18. const int S::c;
  19. constexpr int S::d = 0;
  20. constexpr int S::d2;
  21. template<typename T>
  22. struct U {
  23. static constexpr int a = 0;
  24. static constexpr int b; // expected-error {{declaration of constexpr static data member 'b' requires an initializer}}
  25. static constexpr NonLit h = NonLit(); // expected-error {{cannot have non-literal type 'const NonLit'}}
  26. static constexpr T c = T(); // expected-error {{cannot have non-literal type}}
  27. static const T d;
  28. };
  29. template<typename T> constexpr T U<T>::d = T(); // expected-error {{non-literal type 'const NonLit'}}
  30. U<int> u1;
  31. U<NonLit> u2; // expected-note {{here}}
  32. static_assert(U<int>::a == 0, "");
  33. constexpr int outofline = (U<NonLit>::d, 0); // expected-note {{here}} expected-warning {{unused}}