1c2c11446caaee2d5a787cc8d0310330c6364210dDouglas Gregor// RUN: %clang_cc1 -fsyntax-only -verify -Wc++11-compat %s
207952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidisclass C {
307952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidispublic:
42fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu  auto int errx; // expected-error {{storage class specified for a member declaration}} expected-warning {{'auto' storage class specifier is redundant}}
52fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu  register int erry; // expected-error {{storage class specified for a member declaration}}
62fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu  extern int errz; // expected-error {{storage class specified for a member declaration}}
707952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis
807952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  static void sm() {
907952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis    sx = 0;
10a85cf39786fffd6860a940523be01eb02a4935c0Richard Smith    this->x = 0; // expected-error {{invalid use of 'this' outside of a non-static member function}}
112fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu    x = 0; // expected-error {{invalid use of member 'x' in static member function}}
1207952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  }
1307952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis
1407952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  class NestedC {
154e6356426fcfef84e2484820814a8eaaaf547edaJohn McCall  public:
164e6356426fcfef84e2484820814a8eaaaf547edaJohn McCall    NestedC(int);
17a85cf39786fffd6860a940523be01eb02a4935c0Richard Smith    void f() {
1807952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis      sx = 0;
19a85cf39786fffd6860a940523be01eb02a4935c0Richard Smith      x = 0; // expected-error {{use of non-static data member 'x' of 'C' from nested type 'NestedC'}}
20a85cf39786fffd6860a940523be01eb02a4935c0Richard Smith      sm();
21a85cf39786fffd6860a940523be01eb02a4935c0Richard Smith      m(); // expected-error {{call to non-static member function 'm' of 'C' from nested type 'NestedC'}}
2207952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis    }
2307952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  };
2407952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis
2507952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  int b : 1, w : 2;
2607952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  int : 1, : 2;
278b963ef99be6235f1e9fe866180fff7dbbe5e85bChris Lattner  typedef int E : 1; // expected-error {{typedef member 'E' cannot be a bit-field}}
284e6356426fcfef84e2484820814a8eaaaf547edaJohn McCall  static int sb : 1; // expected-error {{static member 'sb' cannot be a bit-field}}
2907952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  static int vs;
3007952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis
3107952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  typedef int func();
3207952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  func tm;
33d6caa9ef4cc68290b0bf33432934cc11dd5594e6Argyrios Kyrtzidis  func *ptm;
343cf538d5c49bbebac1afa6f4a5010e3d877440bbDouglas Gregor  func btm : 1; // expected-error {{bit-field 'btm' has non-integral type}}
353cf538d5c49bbebac1afa6f4a5010e3d877440bbDouglas Gregor  NestedC bc : 1; // expected-error {{bit-field 'bc' has non-integral type}}
3607952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis
3766973121788ca645fe3d4a66179b9cfb6f2bce08Douglas Gregor  enum E1 { en1, en2 };
3807952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis
39d7c56e1114bfe7d461786903bb720d2c6efc05a1Richard Smith  int i = 0; // expected-warning {{in-class initialization of non-static data member is a C++11 extension}}
404e6356426fcfef84e2484820814a8eaaaf547edaJohn McCall  static int si = 0; // expected-error {{non-const static data member must be initialized out of line}}
414e6356426fcfef84e2484820814a8eaaaf547edaJohn McCall  static const NestedC ci = 0; // expected-error {{static data member of type 'const C::NestedC' must be initialized out of line}}
42d7c56e1114bfe7d461786903bb720d2c6efc05a1Richard Smith  static const int nci = vs; // expected-error {{in-class initializer for static data member is not a constant expression}}
4307952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  static const int vi = 0;
44b3df1386680b3830d2f4d300d4d7eaba134135fcDouglas Gregor  static const volatile int cvi = 0; // ok, illegal in C++11
4507952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  static const E evi = 0;
4607952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis
4707952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  void m() {
4807952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis    sx = 0;
4907952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis    this->x = 0;
5007952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis    y = 0;
512fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu    this = 0; // expected-error {{expression is not assignable}}
5207952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  }
5307952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis
5407952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  int f1(int p) {
55d93f0ddba0965ded252e228134b30ce30e863fb0Sebastian Redl    A z = 6;
56d93f0ddba0965ded252e228134b30ce30e863fb0Sebastian Redl    return p + x + this->y + z;
5707952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  }
5807952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis
5907952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  typedef int A;
6007952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis
61021c3b372c58f5423b4fa2a5be6933d1c7ecc663Douglas Gregor  virtual int viv; // expected-error {{'virtual' can only appear on non-static member functions}}
622fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu  virtual static int vsif(); // expected-error {{'virtual' can only appear on non-static member functions}}
63d93f0ddba0965ded252e228134b30ce30e863fb0Sebastian Redl  virtual int vif();
64d93f0ddba0965ded252e228134b30ce30e863fb0Sebastian Redl
6507952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidisprivate:
6607952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  int x,y;
6707952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  static int sx;
68de933f025e839bde4b119f3437c320c2137bbe1fArgyrios Kyrtzidis
69669d5d74b880a8497b92a3ec159145713f4d6519Sebastian Redl  mutable int mi;
702fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu  mutable int &mir; // expected-error {{'mutable' cannot be applied to references}}
712fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu  mutable void mfn(); // expected-error {{'mutable' cannot be applied to functions}}
722fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu  mutable const int mci; // expected-error {{'mutable' and 'const' cannot be mixed}}
73669d5d74b880a8497b92a3ec159145713f4d6519Sebastian Redl
74de933f025e839bde4b119f3437c320c2137bbe1fArgyrios Kyrtzidis  static const int number = 50;
75de933f025e839bde4b119f3437c320c2137bbe1fArgyrios Kyrtzidis  static int arr[number];
7607952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis};
7707952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis
7807952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidisclass C2 {
7907952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  void f() {
8007952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis    static int lx;
8107952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis    class LC1 {
8207952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis      int m() { return lx; }
8307952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis    };
8407952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis    class LC2 {
8507952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis      int m() { return lx; }
8607952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis    };
8707952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis  }
8807952324dda0e758c17f8bc3015793c65c51c48cArgyrios Kyrtzidis};
89669d5d74b880a8497b92a3ec159145713f4d6519Sebastian Redl
90a11f42f4bca694b9be91350d0a74815f119e3fbfSebastian Redlstruct C3 {
91a11f42f4bca694b9be91350d0a74815f119e3fbfSebastian Redl  int i;
92a11f42f4bca694b9be91350d0a74815f119e3fbfSebastian Redl  mutable int j;
93a11f42f4bca694b9be91350d0a74815f119e3fbfSebastian Redl};
94a11f42f4bca694b9be91350d0a74815f119e3fbfSebastian Redlvoid f()
95a11f42f4bca694b9be91350d0a74815f119e3fbfSebastian Redl{
96a11f42f4bca694b9be91350d0a74815f119e3fbfSebastian Redl  const C3 c3 = { 1, 2 };
9758f9e13e87e57236fee4b914eea9be6f92a1c345Chris Lattner  (void)static_cast<int*>(&c3.i); // expected-error {{static_cast from 'const int *' to 'int *' is not allowed}}
98a11f42f4bca694b9be91350d0a74815f119e3fbfSebastian Redl  // but no error here
99a11f42f4bca694b9be91350d0a74815f119e3fbfSebastian Redl  (void)static_cast<int*>(&c3.j);
100a11f42f4bca694b9be91350d0a74815f119e3fbfSebastian Redl}
101a11f42f4bca694b9be91350d0a74815f119e3fbfSebastian Redl
102669d5d74b880a8497b92a3ec159145713f4d6519Sebastian Redl// Play with mutable a bit more, to make sure it doesn't crash anything.
1032fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieumutable int gi; // expected-error {{'mutable' can only be applied to member variables}}
104669d5d74b880a8497b92a3ec159145713f4d6519Sebastian Redlmutable void gfn(); // expected-error {{illegal storage class on function}}
105669d5d74b880a8497b92a3ec159145713f4d6519Sebastian Redlvoid ogfn()
106669d5d74b880a8497b92a3ec159145713f4d6519Sebastian Redl{
1072fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu  mutable int ml; // expected-error {{'mutable' can only be applied to member variables}}
108a4ed0d8d75212dc01b4438829a4b0c846d99458dSebastian Redl
109a4ed0d8d75212dc01b4438829a4b0c846d99458dSebastian Redl  // PR3020: This used to crash due to double ownership of C4.
110a4ed0d8d75212dc01b4438829a4b0c846d99458dSebastian Redl  struct C4;
111cb821d045f5e445384f34d05a526955036073c4aDouglas Gregor  C4; // expected-warning {{declaration does not declare anything}}
112669d5d74b880a8497b92a3ec159145713f4d6519Sebastian Redl}
11372de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor
11472de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregorstruct C4 {
11572de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor  void f(); // expected-note{{previous declaration is here}}
11672de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor  int f; // expected-error{{duplicate member 'f'}}
11772de6676bd30f9081ee4166bbe07b4c270258ce6Douglas Gregor};
11846408eedfff5aa33662cedb6716a20616f3bad31Sebastian Redl
11946408eedfff5aa33662cedb6716a20616f3bad31Sebastian Redl// PR5415 - don't hang!
12046408eedfff5aa33662cedb6716a20616f3bad31Sebastian Redlstruct S
12146408eedfff5aa33662cedb6716a20616f3bad31Sebastian Redl{
122d1a7846699a82f85ff3ce6b2e383409537c3f5c5Sebastian Redl  void f(); // expected-note 1 {{previous declaration}}
12375379455fc88ca1f021e55ffe1cab3a9c2b2a37aDouglas Gregor  void S::f() {} // expected-error {{extra qualification on member}} expected-error {{class member cannot be redeclared}} expected-note {{previous declaration}} expected-note {{previous definition}}
12446408eedfff5aa33662cedb6716a20616f3bad31Sebastian Redl  void f() {} // expected-error {{class member cannot be redeclared}} expected-error {{redefinition}}
12546408eedfff5aa33662cedb6716a20616f3bad31Sebastian Redl};
1264ad287edcc7c019c413484b86feb8457701eaccdJohn McCall
1274ad287edcc7c019c413484b86feb8457701eaccdJohn McCall// Don't crash on this bogus code.
1284ad287edcc7c019c413484b86feb8457701eaccdJohn McCallnamespace pr6629 {
1294ad287edcc7c019c413484b86feb8457701eaccdJohn McCall  template<class T1, class T2> struct foo :
13062f675cf69ca52c163fd9c0564d84356bb7ffca1Serge Pavlov    bogus<foo<T1,T2> > // expected-error {{unknown template name 'bogus'}}
1314ad287edcc7c019c413484b86feb8457701eaccdJohn McCall  { };
1324ad287edcc7c019c413484b86feb8457701eaccdJohn McCall
133994d73f8473cb2cd3ce2f69c9575c95015be788aRichard Smith  template<> struct foo<unknown,unknown> { // expected-error {{undeclared identifier 'unknown'}}
1344ad287edcc7c019c413484b86feb8457701eaccdJohn McCall    template <typename U1, typename U2> struct bar {
1354ad287edcc7c019c413484b86feb8457701eaccdJohn McCall      typedef bar type;
1364ad287edcc7c019c413484b86feb8457701eaccdJohn McCall      static const int value = 0;
1374ad287edcc7c019c413484b86feb8457701eaccdJohn McCall    };
1384ad287edcc7c019c413484b86feb8457701eaccdJohn McCall  };
1394ad287edcc7c019c413484b86feb8457701eaccdJohn McCall}
14033f992425213f381fc503699b26ee8cf9b60494eDouglas Gregor
14133f992425213f381fc503699b26ee8cf9b60494eDouglas Gregornamespace PR7153 {
14233f992425213f381fc503699b26ee8cf9b60494eDouglas Gregor  class EnclosingClass {
143293279ae4351f4f17ce44aa4f72861d0bc74c918Douglas Gregor  public:
14433f992425213f381fc503699b26ee8cf9b60494eDouglas Gregor    struct A { } mutable *member;
14533f992425213f381fc503699b26ee8cf9b60494eDouglas Gregor  };
146293279ae4351f4f17ce44aa4f72861d0bc74c918Douglas Gregor
147293279ae4351f4f17ce44aa4f72861d0bc74c918Douglas Gregor  void f(const EnclosingClass &ec) {
148293279ae4351f4f17ce44aa4f72861d0bc74c918Douglas Gregor    ec.member = 0;
149293279ae4351f4f17ce44aa4f72861d0bc74c918Douglas Gregor  }
15033f992425213f381fc503699b26ee8cf9b60494eDouglas Gregor}
151d9008318fe395dcbb9049cfb4f2b87cfb5a75f3aDouglas Gregor
152d9008318fe395dcbb9049cfb4f2b87cfb5a75f3aDouglas Gregornamespace PR7196 {
153d9008318fe395dcbb9049cfb4f2b87cfb5a75f3aDouglas Gregor  struct A {
154d9008318fe395dcbb9049cfb4f2b87cfb5a75f3aDouglas Gregor    int a;
155d9008318fe395dcbb9049cfb4f2b87cfb5a75f3aDouglas Gregor
156d9008318fe395dcbb9049cfb4f2b87cfb5a75f3aDouglas Gregor    void f() {
157d9008318fe395dcbb9049cfb4f2b87cfb5a75f3aDouglas Gregor      char i[sizeof(a)];
158d9008318fe395dcbb9049cfb4f2b87cfb5a75f3aDouglas Gregor      enum { x = sizeof(i) };
159d9008318fe395dcbb9049cfb4f2b87cfb5a75f3aDouglas Gregor      enum { y = sizeof(a) };
160d9008318fe395dcbb9049cfb4f2b87cfb5a75f3aDouglas Gregor    }
161d9008318fe395dcbb9049cfb4f2b87cfb5a75f3aDouglas Gregor  };
162d9008318fe395dcbb9049cfb4f2b87cfb5a75f3aDouglas Gregor}
163e0cc047b1984fc301bbe6e98b6d197bed39ad562Douglas Gregor
164e0cc047b1984fc301bbe6e98b6d197bed39ad562Douglas Gregornamespace rdar8066414 {
165e0cc047b1984fc301bbe6e98b6d197bed39ad562Douglas Gregor  class C {
166e0cc047b1984fc301bbe6e98b6d197bed39ad562Douglas Gregor    C() {}
167e0cc047b1984fc301bbe6e98b6d197bed39ad562Douglas Gregor  } // expected-error{{expected ';' after class}}
168e0cc047b1984fc301bbe6e98b6d197bed39ad562Douglas Gregor}
1694e6356426fcfef84e2484820814a8eaaaf547edaJohn McCall
1704e6356426fcfef84e2484820814a8eaaaf547edaJohn McCallnamespace rdar8367341 {
1714e6356426fcfef84e2484820814a8eaaaf547edaJohn McCall  float foo();
1724e6356426fcfef84e2484820814a8eaaaf547edaJohn McCall
1734e6356426fcfef84e2484820814a8eaaaf547edaJohn McCall  struct A {
174947be1941e9a1d4233116f51a45799d3904d4231Richard Smith    static const float x = 5.0f; // expected-warning {{in-class initializer for static data member of type 'const float' is a GNU extension}}
175d7c56e1114bfe7d461786903bb720d2c6efc05a1Richard 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}}
1764e6356426fcfef84e2484820814a8eaaaf547edaJohn McCall  };
1774e6356426fcfef84e2484820814a8eaaaf547edaJohn McCall}
1786ad5df132a0bcb3f6975362901270be5bf60dc56Argyrios Kyrtzidis
1796ad5df132a0bcb3f6975362901270be5bf60dc56Argyrios Kyrtzidisnamespace with_anon {
1806ad5df132a0bcb3f6975362901270be5bf60dc56Argyrios Kyrtzidisstruct S {
1816ad5df132a0bcb3f6975362901270be5bf60dc56Argyrios Kyrtzidis  union {
1826ad5df132a0bcb3f6975362901270be5bf60dc56Argyrios Kyrtzidis    char c;
1836ad5df132a0bcb3f6975362901270be5bf60dc56Argyrios Kyrtzidis  };
1846ad5df132a0bcb3f6975362901270be5bf60dc56Argyrios Kyrtzidis};
1856ad5df132a0bcb3f6975362901270be5bf60dc56Argyrios Kyrtzidis
1866ad5df132a0bcb3f6975362901270be5bf60dc56Argyrios Kyrtzidisvoid f() {
187a85cf39786fffd6860a940523be01eb02a4935c0Richard Smith    S::c; // expected-error {{invalid use of non-static data member}}
1886ad5df132a0bcb3f6975362901270be5bf60dc56Argyrios Kyrtzidis}
1896ad5df132a0bcb3f6975362901270be5bf60dc56Argyrios Kyrtzidis}
190147545d698972cfd34ece30a5d55e8180784161eDouglas Gregor
191147545d698972cfd34ece30a5d55e8180784161eDouglas Gregorstruct PR9989 {
192147545d698972cfd34ece30a5d55e8180784161eDouglas Gregor  static int const PR9989_Member = sizeof PR9989_Member;
193147545d698972cfd34ece30a5d55e8180784161eDouglas Gregor};
194