cxx0x-class.cpp 1.3 KB

12345678910111213141516171819202122232425262728
  1. // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
  2. int vs = 0;
  3. class C {
  4. public:
  5. struct NestedC {
  6. NestedC(int);
  7. };
  8. int i = 0;
  9. static int si = 0; // expected-error {{non-const static data member must be initialized out of line}}
  10. static const NestedC ci = 0; // expected-error {{static data member of type 'const C::NestedC' must be initialized out of line}}
  11. static const int nci = vs; // expected-error {{in-class initializer for static data member is not a constant expression}}
  12. static const int vi = 0;
  13. static const volatile int cvi = 0; // expected-error {{static const volatile data member must be initialized out of line}}
  14. };
  15. namespace rdar8367341 {
  16. float foo(); // expected-note {{here}}
  17. struct A {
  18. static const float x = 5.0f; // expected-warning {{GNU extension}} expected-note {{use 'constexpr' specifier to silence this warning}}
  19. static const float y = foo(); // expected-warning {{GNU extension}} expected-note {{use 'constexpr' specifier to silence this warning}} expected-error {{in-class initializer for static data member is not a constant expression}}
  20. static constexpr float x2 = 5.0f;
  21. static constexpr float y2 = foo(); // expected-error {{must be initialized by a constant expression}} expected-note {{non-constexpr function 'foo'}}
  22. };
  23. }