xref: /llvm-project/clang/test/CXX/class/class.mem/p13.cpp (revision 0e3a48778408b505946e465abf5c77a2ddd4918c)
188fe69ceSRichard Smith // RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s
236c22a23SDouglas Gregor 
336c22a23SDouglas Gregor // If T is the name of a class, then each of the following shall have
436c22a23SDouglas Gregor // a name different from T:
536c22a23SDouglas Gregor 
636c22a23SDouglas Gregor // - every static data member of class T;
736c22a23SDouglas Gregor struct X0 {
836c22a23SDouglas Gregor   static int X0; // expected-error{{member 'X0' has the same name as its class}}
936c22a23SDouglas Gregor };
1036c22a23SDouglas Gregor 
1136c22a23SDouglas Gregor // - every member function of class T
1288fe69ceSRichard Smith struct Xa {
XaXa1388fe69ceSRichard Smith   int Xa() {} // expected-error{{constructor cannot have a return type}}
1488fe69ceSRichard Smith };
1536c22a23SDouglas Gregor 
1636c22a23SDouglas Gregor // - every member of class T that is itself a type;
1788fe69ceSRichard Smith struct X1 {
1888fe69ceSRichard Smith   enum X1 { }; // expected-error{{member 'X1' has the same name as its class}}
1988fe69ceSRichard Smith };
2088fe69ceSRichard Smith 
2188fe69ceSRichard Smith struct X1a {
2288fe69ceSRichard Smith   struct X1a; // expected-error{{member 'X1a' has the same name as its class}}
2336c22a23SDouglas Gregor };
2436c22a23SDouglas Gregor 
2536c22a23SDouglas Gregor struct X2 {
26553b2b2eSRichard Trieu   typedef int X2; // expected-error{{member 'X2' has the same name as its class}}
2736c22a23SDouglas Gregor };
2836c22a23SDouglas Gregor 
2988fe69ceSRichard Smith struct X2a {
3088fe69ceSRichard Smith   using X2a = int; // expected-error{{member 'X2a' has the same name as its class}}
3188fe69ceSRichard Smith };
3288fe69ceSRichard Smith 
3388fe69ceSRichard Smith // - every member template of class T
3488fe69ceSRichard Smith 
3588fe69ceSRichard Smith struct X2b {
3688fe69ceSRichard Smith   template<typename T> struct X2b; // expected-error{{member 'X2b' has the same name as its class}}
3788fe69ceSRichard Smith };
3888fe69ceSRichard Smith struct X2c {
3988fe69ceSRichard Smith   template<typename T> void X2c(); // expected-error{{constructor cannot have a return type}}
4088fe69ceSRichard Smith };
4188fe69ceSRichard Smith struct X2d {
4288fe69ceSRichard Smith   template<typename T> static int X2d; // expected-error{{member 'X2d' has the same name as its class}}
4388fe69ceSRichard Smith };
4488fe69ceSRichard Smith struct X2e {
4588fe69ceSRichard Smith   template<typename T> using X2e = int; // expected-error{{member 'X2e' has the same name as its class}}
4688fe69ceSRichard Smith };
4788fe69ceSRichard Smith 
4888fe69ceSRichard Smith // - every enumerator of every member of class T that is an unscoped enumerated type; and
4936c22a23SDouglas Gregor struct X3 {
5036c22a23SDouglas Gregor   enum E {
5136c22a23SDouglas Gregor     X3 // expected-error{{member 'X3' has the same name as its class}}
5236c22a23SDouglas Gregor   };
5336c22a23SDouglas Gregor };
5488fe69ceSRichard Smith struct X3a {
5588fe69ceSRichard Smith   enum class E {
5688fe69ceSRichard Smith     X3a // ok
5788fe69ceSRichard Smith   };
5888fe69ceSRichard Smith };
5936c22a23SDouglas Gregor 
6036c22a23SDouglas Gregor // - every member of every anonymous union that is a member of class T.
610f56118cSRichard Smith struct X4 { // expected-note{{previous}}
6236c22a23SDouglas Gregor   union {
6336c22a23SDouglas Gregor     int X;
6436c22a23SDouglas Gregor     union {
6536c22a23SDouglas Gregor       float Y;
660f56118cSRichard Smith       unsigned X4; // expected-error{{redeclares 'X4'}}
6736c22a23SDouglas Gregor     };
6836c22a23SDouglas Gregor   };
6936c22a23SDouglas Gregor };
70715ee079SRichard Smith 
71715ee079SRichard Smith // This includes such things inherited from base classes.
72715ee079SRichard Smith struct B {
73715ee079SRichard Smith   static int D0;
DaB74715ee079SRichard Smith   int Da() {};
75715ee079SRichard Smith   enum D1 {};
76715ee079SRichard Smith   struct D1a;
77715ee079SRichard Smith   typedef int D2;
78715ee079SRichard Smith   using D2a = int;
79715ee079SRichard Smith   template<typename T> struct D2b;
80715ee079SRichard Smith   template<typename T> void D2c();
81715ee079SRichard Smith   template<typename T> static int D2d;
82715ee079SRichard Smith   template<typename T> using D2e = int;
83715ee079SRichard Smith   union { int D4; };
84715ee079SRichard Smith   int Dtemplate;
85715ee079SRichard Smith   int Dtemplate_with_ctors;
86715ee079SRichard Smith };
87715ee079SRichard Smith struct B2 { int Dtemplate(); };
88715ee079SRichard Smith 
89715ee079SRichard Smith struct D0 : B { using B::D0; }; // expected-error {{member 'D0' has the same name as its class}}
90715ee079SRichard Smith struct Da : B { using B::Da; }; // expected-error {{member 'Da' has the same name as its class}}
91715ee079SRichard Smith struct D1 : B { using B::D1; }; // expected-error {{member 'D1' has the same name as its class}}
92715ee079SRichard Smith struct D1a : B { using B::D1a; }; // expected-error {{member 'D1a' has the same name as its class}}
93715ee079SRichard Smith struct D2 : B { using B::D2; }; // expected-error {{member 'D2' has the same name as its class}}
94715ee079SRichard Smith struct D2a : B { using B::D2a; }; // expected-error {{member 'D2a' has the same name as its class}}
95715ee079SRichard Smith struct D2b : B { using B::D2b; }; // expected-error {{member 'D2b' has the same name as its class}}
96715ee079SRichard Smith struct D2c : B { using B::D2c; }; // expected-error {{member 'D2c' has the same name as its class}}
97715ee079SRichard Smith struct D2d : B { using B::D2d; }; // expected-error {{member 'D2d' has the same name as its class}}
98715ee079SRichard Smith struct D2e : B { using B::D2e; }; // expected-error {{member 'D2e' has the same name as its class}}
99715ee079SRichard Smith struct D4 : B { using B::D4; }; // expected-error {{member 'D4' has the same name as its class}}
100715ee079SRichard Smith 
101715ee079SRichard Smith template<typename B> struct Dtemplate : B {
102715ee079SRichard Smith   using B::Dtemplate; // expected-error {{member 'Dtemplate' has the same name as its class}}
103715ee079SRichard Smith };
104715ee079SRichard Smith Dtemplate<B> ok;
105715ee079SRichard Smith Dtemplate<B2> error; // expected-note {{in instantiation of}}
106715ee079SRichard Smith 
107715ee079SRichard Smith template<typename B> struct Dtemplate_with_ctors : B {
108715ee079SRichard Smith   Dtemplate_with_ctors();
109715ee079SRichard Smith   using B::Dtemplate_with_ctors; // expected-error {{member 'Dtemplate_with_ctors' has the same name as its class}}
110715ee079SRichard Smith };
111715ee079SRichard Smith 
112715ee079SRichard Smith template<typename B> struct CtorDtorName : B {
113*0e3a4877SRichard Smith   using B::CtorDtorName; // expected-error {{member 'CtorDtorName' has the same name as its class}} expected-note {{non-type declaration found by destructor name lookup}}
114715ee079SRichard Smith   CtorDtorName();
115*0e3a4877SRichard Smith   ~CtorDtorName(); // expected-error {{identifier 'CtorDtorName' after '~' in destructor name does not name a type}}
116715ee079SRichard Smith };
117