1c2c11446caaee2d5a787cc8d0310330c6364210dDouglas Gregor// RUN: %clang_cc1 -fsyntax-only -verify -Wc++11-compat %s
207952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidisclass C {
307952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidispublic:
44967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar  auto int errx; // expected-error {{storage class specified for a member declaration}}
54967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar#if __cplusplus <= 199711L
64967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar  // expected-warning@-2 {{'auto' storage class specifier is redundant}}
74967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar#else
84967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar  // expected-warning@-4 {{'auto' storage class specifier is not permitted in C++11, and will not be supported in future releases}}
94967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar#endif
102fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu  register int erry; // expected-error {{storage class specified for a member declaration}}
112fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu  extern int errz; // expected-error {{storage class specified for a member declaration}}
1207952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis
1307952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  static void sm() {
1407952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis    sx = 0;
15a85cf39786fffd6860a940523be01eb02a4935c0Richard Smith    this->x = 0; // expected-error {{invalid use of 'this' outside of a non-static member function}}
162fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu    x = 0; // expected-error {{invalid use of member 'x' in static member function}}
1707952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  }
1807952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis
1907952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  class NestedC {
204e6356426fcfef84e2484820814a8eaaaf547edaJohn McCall  public:
214e6356426fcfef84e2484820814a8eaaaf547edaJohn McCall    NestedC(int);
22a85cf39786fffd6860a940523be01eb02a4935c0Richard Smith    void f() {
2307952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis      sx = 0;
24a85cf39786fffd6860a940523be01eb02a4935c0Richard Smith      x = 0; // expected-error {{use of non-static data member 'x' of 'C' from nested type 'NestedC'}}
25a85cf39786fffd6860a940523be01eb02a4935c0Richard Smith      sm();
26a85cf39786fffd6860a940523be01eb02a4935c0Richard Smith      m(); // expected-error {{call to non-static member function 'm' of 'C' from nested type 'NestedC'}}
2707952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis    }
2807952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  };
2907952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis
3007952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  int b : 1, w : 2;
3107952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  int : 1, : 2;
328b963ef99be6235f1e9fe866180fff7dbbe5e85bChris Lattner  typedef int E : 1; // expected-error {{typedef member 'E' cannot be a bit-field}}
334e6356426fcfef84e2484820814a8eaaaf547edaJohn McCall  static int sb : 1; // expected-error {{static member 'sb' cannot be a bit-field}}
3407952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  static int vs;
3507952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis
3607952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  typedef int func();
3707952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  func tm;
38d6caa9ef4cc68290b0bf33432934cc11dd5594e6Argyrios Kyrtzidis  func *ptm;
393cf538d5c49bbebac1afa6f4a5010e3d877440bbDouglas Gregor  func btm : 1; // expected-error {{bit-field 'btm' has non-integral type}}
403cf538d5c49bbebac1afa6f4a5010e3d877440bbDouglas Gregor  NestedC bc : 1; // expected-error {{bit-field 'bc' has non-integral type}}
4107952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis
4266973121788ca645fe3d4a66179b9cfb6f2bce08Douglas Gregor  enum E1 { en1, en2 };
4307952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis
444967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar  int i = 0;
454967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar#if __cplusplus <= 199711L
464967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar  // expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}}
474967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar#endif
484e6356426fcfef84e2484820814a8eaaaf547edaJohn McCall  static int si = 0; // expected-error {{non-const static data member must be initialized out of line}}
494e6356426fcfef84e2484820814a8eaaaf547edaJohn McCall  static const NestedC ci = 0; // expected-error {{static data member of type 'const C::NestedC' must be initialized out of line}}
50d7c56e1114bfe7d461786903bb720d2c6efc05a1Richard Smith  static const int nci = vs; // expected-error {{in-class initializer for static data member is not a constant expression}}
5107952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  static const int vi = 0;
52b3df1386680b3830d2f4d300d4d7eaba134135fcDouglas Gregor  static const volatile int cvi = 0; // ok, illegal in C++11
534967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar#if __cplusplus >= 201103L
544967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar  // expected-error@-2 {{static const volatile data member must be initialized out of line}}
554967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar#endif
5607952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  static const E evi = 0;
5707952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis
5807952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  void m() {
5907952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis    sx = 0;
6007952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis    this->x = 0;
6107952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis    y = 0;
622fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu    this = 0; // expected-error {{expression is not assignable}}
6307952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  }
6407952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis
6507952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  int f1(int p) {
66d93f0ddba0965ded252e228134b30ce30e863fb0Sebastian Redl    A z = 6;
67d93f0ddba0965ded252e228134b30ce30e863fb0Sebastian Redl    return p + x + this->y + z;
6807952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  }
6907952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis
7007952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  typedef int A;
7107952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis
72021c3b372c58f5423b4fa2a5be6933d1c7ecc663Douglas Gregor  virtual int viv; // expected-error {{'virtual' can only appear on non-static member functions}}
732fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu  virtual static int vsif(); // expected-error {{'virtual' can only appear on non-static member functions}}
74d93f0ddba0965ded252e228134b30ce30e863fb0Sebastian Redl  virtual int vif();
75d93f0ddba0965ded252e228134b30ce30e863fb0Sebastian Redl
7607952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidisprivate:
7707952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  int x,y;
7807952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  static int sx;
79de933f025e839bde4b119f3437c320c2137bbe1fArgyrios Kyrtzidis
80669d5d74b880a8497b92a3ec159145713f4d6519Sebastian Redl  mutable int mi;
812fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu  mutable int &mir; // expected-error {{'mutable' cannot be applied to references}}
822fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu  mutable void mfn(); // expected-error {{'mutable' cannot be applied to functions}}
832fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu  mutable const int mci; // expected-error {{'mutable' and 'const' cannot be mixed}}
84669d5d74b880a8497b92a3ec159145713f4d6519Sebastian Redl
85de933f025e839bde4b119f3437c320c2137bbe1fArgyrios Kyrtzidis  static const int number = 50;
86de933f025e839bde4b119f3437c320c2137bbe1fArgyrios Kyrtzidis  static int arr[number];
8707952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis};
8807952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis
8907952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidisclass C2 {
9007952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  void f() {
9107952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis    static int lx;
9207952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis    class LC1 {
9307952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis      int m() { return lx; }
9407952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis    };
9507952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis    class LC2 {
9607952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis      int m() { return lx; }
9707952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis    };
9807952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  }
9907952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis};
100669d5d74b880a8497b92a3ec159145713f4d6519Sebastian Redl
101a11f42f4bca694b9be91350d0a74815f119e3fbfSebastian Redlstruct C3 {
102a11f42f4bca694b9be91350d0a74815f119e3fbfSebastian Redl  int i;
103a11f42f4bca694b9be91350d0a74815f119e3fbfSebastian Redl  mutable int j;
104a11f42f4bca694b9be91350d0a74815f119e3fbfSebastian Redl};
105a11f42f4bca694b9be91350d0a74815f119e3fbfSebastian Redlvoid f()
106a11f42f4bca694b9be91350d0a74815f119e3fbfSebastian Redl{
107a11f42f4bca694b9be91350d0a74815f119e3fbfSebastian Redl  const C3 c3 = { 1, 2 };
10858f9e13e87e57236fee4b914eea9be6f92a1c345Chris Lattner  (void)static_cast<int*>(&c3.i); // expected-error {{static_cast from 'const int *' to 'int *' is not allowed}}
109a11f42f4bca694b9be91350d0a74815f119e3fbfSebastian Redl  // but no error here
110a11f42f4bca694b9be91350d0a74815f119e3fbfSebastian Redl  (void)static_cast<int*>(&c3.j);
111a11f42f4bca694b9be91350d0a74815f119e3fbfSebastian Redl}
112a11f42f4bca694b9be91350d0a74815f119e3fbfSebastian Redl
113669d5d74b880a8497b92a3ec159145713f4d6519Sebastian Redl// Play with mutable a bit more, to make sure it doesn't crash anything.
1142fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieumutable int gi; // expected-error {{'mutable' can only be applied to member variables}}
115669d5d74b880a8497b92a3ec159145713f4d6519Sebastian Redlmutable void gfn(); // expected-error {{illegal storage class on function}}
116669d5d74b880a8497b92a3ec159145713f4d6519Sebastian Redlvoid ogfn()
117669d5d74b880a8497b92a3ec159145713f4d6519Sebastian Redl{
1182fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu  mutable int ml; // expected-error {{'mutable' can only be applied to member variables}}
119a4ed0d8d75212dc01b4438829a4b0c846d99458dSebastian Redl
120a4ed0d8d75212dc01b4438829a4b0c846d99458dSebastian Redl  // PR3020: This used to crash due to double ownership of C4.
121a4ed0d8d75212dc01b4438829a4b0c846d99458dSebastian Redl  struct C4;
122cb821d045f5e445384f34d05a526955036073c4aDouglas Gregor  C4; // expected-warning {{declaration does not declare anything}}
123669d5d74b880a8497b92a3ec159145713f4d6519Sebastian Redl}
12472de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor
12572de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregorstruct C4 {
12672de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor  void f(); // expected-note{{previous declaration is here}}
12772de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor  int f; // expected-error{{duplicate member 'f'}}
12872de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor};
12946408eedfff5aa33662cedb6716a20616f3bad31Sebastian Redl
13046408eedfff5aa33662cedb6716a20616f3bad31Sebastian Redl// PR5415 - don't hang!
13146408eedfff5aa33662cedb6716a20616f3bad31Sebastian Redlstruct S
13246408eedfff5aa33662cedb6716a20616f3bad31Sebastian Redl{
1330e2c34f92f00628d48968dfea096d36381f494cbStephen Hines  void f(); // expected-note 1 {{previous declaration}} expected-note {{previous declaration}}
1340e2c34f92f00628d48968dfea096d36381f494cbStephen Hines  void S::f() {} // expected-error {{extra qualification on member}} expected-error {{class member cannot be redeclared}}
1350e2c34f92f00628d48968dfea096d36381f494cbStephen Hines  void f() {} // expected-error {{class member cannot be redeclared}}
13646408eedfff5aa33662cedb6716a20616f3bad31Sebastian Redl};
1374ad287edcc7c019c413484b86feb8457701eaccdJohn McCall
1384ad287edcc7c019c413484b86feb8457701eaccdJohn McCall// Don't crash on this bogus code.
1394ad287edcc7c019c413484b86feb8457701eaccdJohn McCallnamespace pr6629 {
1404ad287edcc7c019c413484b86feb8457701eaccdJohn McCall  template<class T1, class T2> struct foo :
14162f675cf69ca52c163fd9c0564d84356bb7ffca1Serge Pavlov    bogus<foo<T1,T2> > // expected-error {{unknown template name 'bogus'}}
1424ad287edcc7c019c413484b86feb8457701eaccdJohn McCall  { };
1434ad287edcc7c019c413484b86feb8457701eaccdJohn McCall
144994d73f8473cb2cd3ce2f69c9575c95015be788aRichard Smith  template<> struct foo<unknown,unknown> { // expected-error {{undeclared identifier 'unknown'}}
1454ad287edcc7c019c413484b86feb8457701eaccdJohn McCall    template <typename U1, typename U2> struct bar {
1464ad287edcc7c019c413484b86feb8457701eaccdJohn McCall      typedef bar type;
1474ad287edcc7c019c413484b86feb8457701eaccdJohn McCall      static const int value = 0;
1484ad287edcc7c019c413484b86feb8457701eaccdJohn McCall    };
1494ad287edcc7c019c413484b86feb8457701eaccdJohn McCall  };
1504ad287edcc7c019c413484b86feb8457701eaccdJohn McCall}
15133f992425213f381fc503699b26ee8cf9b60494eDouglas Gregor
15233f992425213f381fc503699b26ee8cf9b60494eDouglas Gregornamespace PR7153 {
15333f992425213f381fc503699b26ee8cf9b60494eDouglas Gregor  class EnclosingClass {
154293279ae4351f4f17ce44aa4f72861d0bc74c918Douglas Gregor  public:
15533f992425213f381fc503699b26ee8cf9b60494eDouglas Gregor    struct A { } mutable *member;
15633f992425213f381fc503699b26ee8cf9b60494eDouglas Gregor  };
157293279ae4351f4f17ce44aa4f72861d0bc74c918Douglas Gregor
158293279ae4351f4f17ce44aa4f72861d0bc74c918Douglas Gregor  void f(const EnclosingClass &ec) {
159293279ae4351f4f17ce44aa4f72861d0bc74c918Douglas Gregor    ec.member = 0;
160293279ae4351f4f17ce44aa4f72861d0bc74c918Douglas Gregor  }
16133f992425213f381fc503699b26ee8cf9b60494eDouglas Gregor}
162d9008318fe395dcbb9049cfb4f2b87cfb5a75f3aDouglas Gregor
163d9008318fe395dcbb9049cfb4f2b87cfb5a75f3aDouglas Gregornamespace PR7196 {
164d9008318fe395dcbb9049cfb4f2b87cfb5a75f3aDouglas Gregor  struct A {
165d9008318fe395dcbb9049cfb4f2b87cfb5a75f3aDouglas Gregor    int a;
166d9008318fe395dcbb9049cfb4f2b87cfb5a75f3aDouglas Gregor
167d9008318fe395dcbb9049cfb4f2b87cfb5a75f3aDouglas Gregor    void f() {
168d9008318fe395dcbb9049cfb4f2b87cfb5a75f3aDouglas Gregor      char i[sizeof(a)];
169d9008318fe395dcbb9049cfb4f2b87cfb5a75f3aDouglas Gregor      enum { x = sizeof(i) };
170d9008318fe395dcbb9049cfb4f2b87cfb5a75f3aDouglas Gregor      enum { y = sizeof(a) };
171d9008318fe395dcbb9049cfb4f2b87cfb5a75f3aDouglas Gregor    }
172d9008318fe395dcbb9049cfb4f2b87cfb5a75f3aDouglas Gregor  };
173d9008318fe395dcbb9049cfb4f2b87cfb5a75f3aDouglas Gregor}
174e0cc047b1984fc301bbe6e98b6d197bed39ad562Douglas Gregor
175e0cc047b1984fc301bbe6e98b6d197bed39ad562Douglas Gregornamespace rdar8066414 {
176e0cc047b1984fc301bbe6e98b6d197bed39ad562Douglas Gregor  class C {
177e0cc047b1984fc301bbe6e98b6d197bed39ad562Douglas Gregor    C() {}
178e0cc047b1984fc301bbe6e98b6d197bed39ad562Douglas Gregor  } // expected-error{{expected ';' after class}}
179e0cc047b1984fc301bbe6e98b6d197bed39ad562Douglas Gregor}
1804e6356426fcfef84e2484820814a8eaaaf547edaJohn McCall
1814e6356426fcfef84e2484820814a8eaaaf547edaJohn McCallnamespace rdar8367341 {
1824e6356426fcfef84e2484820814a8eaaaf547edaJohn McCall  float foo();
1834967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar#if __cplusplus >= 201103L
1844967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar  // expected-note@-2 {{declared here}}
1854967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar#endif
1864e6356426fcfef84e2484820814a8eaaaf547edaJohn McCall
1874e6356426fcfef84e2484820814a8eaaaf547edaJohn McCall  struct A {
1884967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar#if __cplusplus <= 199711L
189947be1941e9a1d4233116f51a45799d3904d4231Richard Smith    static const float x = 5.0f; // expected-warning {{in-class initializer for static data member of type 'const float' is a GNU extension}}
190d7c56e1114bfe7d461786903bb720d2c6efc05a1Richard Smith    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}}
1914967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar#else
1924967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar    static constexpr float x = 5.0f;
1934967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar    static constexpr float y = foo(); // expected-error {{constexpr variable 'y' must be initialized by a constant expression}} expected-note {{non-constexpr function 'foo' cannot be used in a constant expression}}
1944967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar#endif
1954e6356426fcfef84e2484820814a8eaaaf547edaJohn McCall  };
1964e6356426fcfef84e2484820814a8eaaaf547edaJohn McCall}
1976ad5df132a0bcb3f6975362901270be5bf60dc56Argyrios Kyrtzidis
1986ad5df132a0bcb3f6975362901270be5bf60dc56Argyrios Kyrtzidisnamespace with_anon {
1996ad5df132a0bcb3f6975362901270be5bf60dc56Argyrios Kyrtzidisstruct S {
2006ad5df132a0bcb3f6975362901270be5bf60dc56Argyrios Kyrtzidis  union {
2016ad5df132a0bcb3f6975362901270be5bf60dc56Argyrios Kyrtzidis    char c;
2026ad5df132a0bcb3f6975362901270be5bf60dc56Argyrios Kyrtzidis  };
2036ad5df132a0bcb3f6975362901270be5bf60dc56Argyrios Kyrtzidis};
2046ad5df132a0bcb3f6975362901270be5bf60dc56Argyrios Kyrtzidis
2056ad5df132a0bcb3f6975362901270be5bf60dc56Argyrios Kyrtzidisvoid f() {
206a85cf39786fffd6860a940523be01eb02a4935c0Richard Smith    S::c; // expected-error {{invalid use of non-static data member}}
2076ad5df132a0bcb3f6975362901270be5bf60dc56Argyrios Kyrtzidis}
2086ad5df132a0bcb3f6975362901270be5bf60dc56Argyrios Kyrtzidis}
209147545d698972cfd34ece30a5d55e8180784161eDouglas Gregor
210147545d698972cfd34ece30a5d55e8180784161eDouglas Gregorstruct PR9989 {
211147545d698972cfd34ece30a5d55e8180784161eDouglas Gregor  static int const PR9989_Member = sizeof PR9989_Member;
212147545d698972cfd34ece30a5d55e8180784161eDouglas Gregor};
213