xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/cxx0x-class.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -Wno-uninitialized -fsyntax-only -verify -std=c++11 -Wno-error=static-float-init %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc int vs = 0;
4*f4a2713aSLionel Sambuc 
5*f4a2713aSLionel Sambuc class C {
6*f4a2713aSLionel Sambuc public:
7*f4a2713aSLionel Sambuc   struct NestedC {
8*f4a2713aSLionel Sambuc     NestedC(int);
9*f4a2713aSLionel Sambuc   };
10*f4a2713aSLionel Sambuc 
11*f4a2713aSLionel Sambuc   int i = 0;
12*f4a2713aSLionel Sambuc   static int si = 0; // expected-error {{non-const static data member must be initialized out of line}}
13*f4a2713aSLionel Sambuc   static const NestedC ci = 0; // expected-error {{static data member of type 'const C::NestedC' must be initialized out of line}}
14*f4a2713aSLionel Sambuc   static const int nci = vs; // expected-error {{in-class initializer for static data member is not a constant expression}}
15*f4a2713aSLionel Sambuc   static const int vi = 0;
16*f4a2713aSLionel Sambuc   static const volatile int cvi = 0; // expected-error {{static const volatile data member must be initialized out of line}}
17*f4a2713aSLionel Sambuc };
18*f4a2713aSLionel Sambuc 
19*f4a2713aSLionel Sambuc namespace rdar8367341 {
20*f4a2713aSLionel Sambuc   float foo(); // expected-note {{here}}
21*f4a2713aSLionel Sambuc 
22*f4a2713aSLionel Sambuc   struct A {
23*f4a2713aSLionel Sambuc     static const float x = 5.0f; // expected-warning {{requires 'constexpr'}} expected-note {{add 'constexpr'}}
24*f4a2713aSLionel Sambuc     static const float y = foo(); // expected-warning {{requires 'constexpr'}} expected-note {{add 'constexpr'}}
25*f4a2713aSLionel Sambuc     static constexpr float x2 = 5.0f;
26*f4a2713aSLionel Sambuc     static constexpr float y2 = foo(); // expected-error {{must be initialized by a constant expression}} expected-note {{non-constexpr function 'foo'}}
27*f4a2713aSLionel Sambuc   };
28*f4a2713aSLionel Sambuc }
29*f4a2713aSLionel Sambuc 
30*f4a2713aSLionel Sambuc 
31*f4a2713aSLionel Sambuc namespace Foo {
32*f4a2713aSLionel Sambuc   // Regression test -- forward declaration of Foo should not cause error about
33*f4a2713aSLionel Sambuc   // nonstatic data member.
34*f4a2713aSLionel Sambuc   class Foo;
35*f4a2713aSLionel Sambuc   class Foo {
36*f4a2713aSLionel Sambuc     int x;
37*f4a2713aSLionel Sambuc     int y = x;
38*f4a2713aSLionel Sambuc   };
39*f4a2713aSLionel Sambuc }
40