Clang Project

clang_source_code/test/CXX/class/class.mem/p13.cpp
1// RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s
2
3// If T is the name of a class, then each of the following shall have
4// a name different from T:
5
6// - every static data member of class T;
7struct X0 {
8  static int X0; // expected-error{{member 'X0' has the same name as its class}}
9};
10
11// - every member function of class T
12struct Xa {
13  int Xa() {} // expected-error{{constructor cannot have a return type}}
14};
15
16// - every member of class T that is itself a type;
17struct X1 {
18  enum X1 { }; // expected-error{{member 'X1' has the same name as its class}}
19};
20
21struct X1a {
22  struct X1a; // expected-error{{member 'X1a' has the same name as its class}}
23};
24
25struct X2 {
26  typedef int X2; // expected-error{{member 'X2' has the same name as its class}}
27};
28
29struct X2a {
30  using X2a = int; // expected-error{{member 'X2a' has the same name as its class}}
31};
32
33// - every member template of class T
34
35struct X2b {
36  template<typename T> struct X2b; // expected-error{{member 'X2b' has the same name as its class}}
37};
38struct X2c {
39  template<typename T> void X2c(); // expected-error{{constructor cannot have a return type}}
40};
41struct X2d {
42  template<typename T> static int X2d; // expected-error{{member 'X2d' has the same name as its class}}
43};
44struct X2e {
45  template<typename T> using X2e = int; // expected-error{{member 'X2e' has the same name as its class}}
46};
47
48// - every enumerator of every member of class T that is an unscoped enumerated type; and
49struct X3 {
50  enum E {
51    X3 // expected-error{{member 'X3' has the same name as its class}}
52  };
53};
54struct X3a {
55  enum class E {
56    X3a // ok
57  };
58};
59
60// - every member of every anonymous union that is a member of class T.
61struct X4 { // expected-note{{previous}}
62  union {
63    int X;
64    union {
65      float Y;
66      unsigned X4; // expected-error{{redeclares 'X4'}}
67    };
68  };
69};
70
71// This includes such things inherited from base classes.
72struct B {
73  static int D0;
74  int Da() {};
75  enum D1 {};
76  struct D1a;
77  typedef int D2;
78  using D2a = int;
79  template<typename T> struct D2b;
80  template<typename T> void D2c();
81  template<typename T> static int D2d;
82  template<typename T> using D2e = int;
83  union { int D4; };
84  int Dtemplate;
85  int Dtemplate_with_ctors;
86};
87struct B2 { int Dtemplate(); };
88
89struct D0 : B { using B::D0; }; // expected-error {{member 'D0' has the same name as its class}}
90struct Da : B { using B::Da; }; // expected-error {{member 'Da' has the same name as its class}}
91struct D1 : B { using B::D1; }; // expected-error {{member 'D1' has the same name as its class}}
92struct D1a : B { using B::D1a; }; // expected-error {{member 'D1a' has the same name as its class}}
93struct D2 : B { using B::D2; }; // expected-error {{member 'D2' has the same name as its class}}
94struct D2a : B { using B::D2a; }; // expected-error {{member 'D2a' has the same name as its class}}
95struct D2b : B { using B::D2b; }; // expected-error {{member 'D2b' has the same name as its class}}
96struct D2c : B { using B::D2c; }; // expected-error {{member 'D2c' has the same name as its class}}
97struct D2d : B { using B::D2d; }; // expected-error {{member 'D2d' has the same name as its class}}
98struct D2e : B { using B::D2e; }; // expected-error {{member 'D2e' has the same name as its class}}
99struct D4 : B { using B::D4; }; // expected-error {{member 'D4' has the same name as its class}}
100
101template<typename B> struct Dtemplate : B {
102  using B::Dtemplate; // expected-error {{member 'Dtemplate' has the same name as its class}}
103};
104Dtemplate<B> ok;
105Dtemplate<B2> error; // expected-note {{in instantiation of}}
106
107template<typename B> struct Dtemplate_with_ctors : B {
108  Dtemplate_with_ctors();
109  using B::Dtemplate_with_ctors; // expected-error {{member 'Dtemplate_with_ctors' has the same name as its class}}
110};
111
112template<typename B> struct CtorDtorName : B {
113  using B::CtorDtorName; // expected-error {{member 'CtorDtorName' has the same name as its class}}
114  CtorDtorName();
115  ~CtorDtorName(); // expected-error {{expected the class name after '~' to name a destructor}}
116};
117