xref: /aosp_15_r20/external/clang/test/CXX/class/class.mem/p13.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s
2*67e74705SXin Li 
3*67e74705SXin Li // If T is the name of a class, then each of the following shall have
4*67e74705SXin Li // a name different from T:
5*67e74705SXin Li 
6*67e74705SXin Li // - every static data member of class T;
7*67e74705SXin Li struct X0 {
8*67e74705SXin Li   static int X0; // expected-error{{member 'X0' has the same name as its class}}
9*67e74705SXin Li };
10*67e74705SXin Li 
11*67e74705SXin Li // - every member function of class T
12*67e74705SXin Li struct Xa {
XaXa13*67e74705SXin Li   int Xa() {} // expected-error{{constructor cannot have a return type}}
14*67e74705SXin Li };
15*67e74705SXin Li 
16*67e74705SXin Li // - every member of class T that is itself a type;
17*67e74705SXin Li struct X1 {
18*67e74705SXin Li   enum X1 { }; // expected-error{{member 'X1' has the same name as its class}}
19*67e74705SXin Li };
20*67e74705SXin Li 
21*67e74705SXin Li struct X1a {
22*67e74705SXin Li   struct X1a; // expected-error{{member 'X1a' has the same name as its class}}
23*67e74705SXin Li };
24*67e74705SXin Li 
25*67e74705SXin Li struct X2 {
26*67e74705SXin Li   typedef int X2; // expected-error{{member 'X2' has the same name as its class}}
27*67e74705SXin Li };
28*67e74705SXin Li 
29*67e74705SXin Li struct X2a {
30*67e74705SXin Li   using X2a = int; // expected-error{{member 'X2a' has the same name as its class}}
31*67e74705SXin Li };
32*67e74705SXin Li 
33*67e74705SXin Li // - every member template of class T
34*67e74705SXin Li 
35*67e74705SXin Li struct X2b {
36*67e74705SXin Li   template<typename T> struct X2b; // expected-error{{member 'X2b' has the same name as its class}}
37*67e74705SXin Li };
38*67e74705SXin Li struct X2c {
39*67e74705SXin Li   template<typename T> void X2c(); // expected-error{{constructor cannot have a return type}}
40*67e74705SXin Li };
41*67e74705SXin Li struct X2d {
42*67e74705SXin Li   template<typename T> static int X2d; // expected-error{{member 'X2d' has the same name as its class}}
43*67e74705SXin Li };
44*67e74705SXin Li struct X2e {
45*67e74705SXin Li   template<typename T> using X2e = int; // expected-error{{member 'X2e' has the same name as its class}}
46*67e74705SXin Li };
47*67e74705SXin Li 
48*67e74705SXin Li // - every enumerator of every member of class T that is an unscoped enumerated type; and
49*67e74705SXin Li struct X3 {
50*67e74705SXin Li   enum E {
51*67e74705SXin Li     X3 // expected-error{{member 'X3' has the same name as its class}}
52*67e74705SXin Li   };
53*67e74705SXin Li };
54*67e74705SXin Li struct X3a {
55*67e74705SXin Li   enum class E {
56*67e74705SXin Li     X3a // ok
57*67e74705SXin Li   };
58*67e74705SXin Li };
59*67e74705SXin Li 
60*67e74705SXin Li // - every member of every anonymous union that is a member of class T.
61*67e74705SXin Li struct X4 { // expected-note{{previous}}
62*67e74705SXin Li   union {
63*67e74705SXin Li     int X;
64*67e74705SXin Li     union {
65*67e74705SXin Li       float Y;
66*67e74705SXin Li       unsigned X4; // expected-error{{redeclares 'X4'}}
67*67e74705SXin Li     };
68*67e74705SXin Li   };
69*67e74705SXin Li };
70