1// RUN: %clang_cc1 -fsyntax-only -verify -Wc++11-compat %s
2class C {
3public:
4  auto int errx; // expected-error {{storage class specified for a member declaration}} expected-warning {{'auto' storage class specifier is redundant}}
5  register int erry; // expected-error {{storage class specified for a member declaration}}
6  extern int errz; // expected-error {{storage class specified for a member declaration}}
7
8  static void sm() {
9    sx = 0;
10    this->x = 0; // expected-error {{invalid use of 'this' outside of a non-static member function}}
11    x = 0; // expected-error {{invalid use of member 'x' in static member function}}
12  }
13
14  class NestedC {
15  public:
16    NestedC(int);
17    void f() {
18      sx = 0;
19      x = 0; // expected-error {{use of non-static data member 'x' of 'C' from nested type 'NestedC'}}
20      sm();
21      m(); // expected-error {{call to non-static member function 'm' of 'C' from nested type 'NestedC'}}
22    }
23  };
24
25  int b : 1, w : 2;
26  int : 1, : 2;
27  typedef int E : 1; // expected-error {{typedef member 'E' cannot be a bit-field}}
28  static int sb : 1; // expected-error {{static member 'sb' cannot be a bit-field}}
29  static int vs;
30
31  typedef int func();
32  func tm;
33  func *ptm;
34  func btm : 1; // expected-error {{bit-field 'btm' has non-integral type}}
35  NestedC bc : 1; // expected-error {{bit-field 'bc' has non-integral type}}
36
37  enum E1 { en1, en2 };
38
39  int i = 0; // expected-warning {{in-class initialization of non-static data member is a C++11 extension}}
40  static int si = 0; // expected-error {{non-const static data member must be initialized out of line}}
41  static const NestedC ci = 0; // expected-error {{static data member of type 'const C::NestedC' must be initialized out of line}}
42  static const int nci = vs; // expected-error {{in-class initializer for static data member is not a constant expression}}
43  static const int vi = 0;
44  static const volatile int cvi = 0; // ok, illegal in C++11
45  static const E evi = 0;
46
47  void m() {
48    sx = 0;
49    this->x = 0;
50    y = 0;
51    this = 0; // expected-error {{expression is not assignable}}
52  }
53
54  int f1(int p) {
55    A z = 6;
56    return p + x + this->y + z;
57  }
58
59  typedef int A;
60
61  virtual int viv; // expected-error {{'virtual' can only appear on non-static member functions}}
62  virtual static int vsif(); // expected-error {{'virtual' can only appear on non-static member functions}}
63  virtual int vif();
64
65private:
66  int x,y;
67  static int sx;
68
69  mutable int mi;
70  mutable int &mir; // expected-error {{'mutable' cannot be applied to references}}
71  mutable void mfn(); // expected-error {{'mutable' cannot be applied to functions}}
72  mutable const int mci; // expected-error {{'mutable' and 'const' cannot be mixed}}
73
74  static const int number = 50;
75  static int arr[number];
76};
77
78class C2 {
79  void f() {
80    static int lx;
81    class LC1 {
82      int m() { return lx; }
83    };
84    class LC2 {
85      int m() { return lx; }
86    };
87  }
88};
89
90struct C3 {
91  int i;
92  mutable int j;
93};
94void f()
95{
96  const C3 c3 = { 1, 2 };
97  (void)static_cast<int*>(&c3.i); // expected-error {{static_cast from 'const int *' to 'int *' is not allowed}}
98  // but no error here
99  (void)static_cast<int*>(&c3.j);
100}
101
102// Play with mutable a bit more, to make sure it doesn't crash anything.
103mutable int gi; // expected-error {{'mutable' can only be applied to member variables}}
104mutable void gfn(); // expected-error {{illegal storage class on function}}
105void ogfn()
106{
107  mutable int ml; // expected-error {{'mutable' can only be applied to member variables}}
108
109  // PR3020: This used to crash due to double ownership of C4.
110  struct C4;
111  C4; // expected-warning {{declaration does not declare anything}}
112}
113
114struct C4 {
115  void f(); // expected-note{{previous declaration is here}}
116  int f; // expected-error{{duplicate member 'f'}}
117};
118
119// PR5415 - don't hang!
120struct S
121{
122  void f(); // expected-note 1 {{previous declaration}} expected-note {{previous declaration}}
123  void S::f() {} // expected-error {{extra qualification on member}} expected-error {{class member cannot be redeclared}}
124  void f() {} // expected-error {{class member cannot be redeclared}}
125};
126
127// Don't crash on this bogus code.
128namespace pr6629 {
129  template<class T1, class T2> struct foo :
130    bogus<foo<T1,T2> > // expected-error {{unknown template name 'bogus'}}
131  { };
132
133  template<> struct foo<unknown,unknown> { // expected-error {{undeclared identifier 'unknown'}}
134    template <typename U1, typename U2> struct bar {
135      typedef bar type;
136      static const int value = 0;
137    };
138  };
139}
140
141namespace PR7153 {
142  class EnclosingClass {
143  public:
144    struct A { } mutable *member;
145  };
146
147  void f(const EnclosingClass &ec) {
148    ec.member = 0;
149  }
150}
151
152namespace PR7196 {
153  struct A {
154    int a;
155
156    void f() {
157      char i[sizeof(a)];
158      enum { x = sizeof(i) };
159      enum { y = sizeof(a) };
160    }
161  };
162}
163
164namespace rdar8066414 {
165  class C {
166    C() {}
167  } // expected-error{{expected ';' after class}}
168}
169
170namespace rdar8367341 {
171  float foo();
172
173  struct A {
174    static const float x = 5.0f; // expected-warning {{in-class initializer for static data member of type 'const float' is a GNU extension}}
175    static const float y = foo(); // expected-warning {{in-class initializer for static data member of type 'const float' is a GNU extension}} expected-error {{in-class initializer for static data member is not a constant expression}}
176  };
177}
178
179namespace with_anon {
180struct S {
181  union {
182    char c;
183  };
184};
185
186void f() {
187    S::c; // expected-error {{invalid use of non-static data member}}
188}
189}
190
191struct PR9989 {
192  static int const PR9989_Member = sizeof PR9989_Member;
193};
194