Richard Smith | 88fe69c | 2015-07-06 01:45:27 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s |
Douglas Gregor | 36c22a2 | 2010-10-15 13:21:21 +0000 | [diff] [blame] | 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; |
| 7 | struct 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 |
Richard Smith | 88fe69c | 2015-07-06 01:45:27 +0000 | [diff] [blame] | 12 | struct Xa { |
| 13 | int Xa() {} // expected-error{{constructor cannot have a return type}} |
| 14 | }; |
Douglas Gregor | 36c22a2 | 2010-10-15 13:21:21 +0000 | [diff] [blame] | 15 | |
| 16 | // - every member of class T that is itself a type; |
Richard Smith | 88fe69c | 2015-07-06 01:45:27 +0000 | [diff] [blame] | 17 | struct X1 { |
| 18 | enum X1 { }; // expected-error{{member 'X1' has the same name as its class}} |
| 19 | }; |
| 20 | |
| 21 | struct X1a { |
| 22 | struct X1a; // expected-error{{member 'X1a' has the same name as its class}} |
Douglas Gregor | 36c22a2 | 2010-10-15 13:21:21 +0000 | [diff] [blame] | 23 | }; |
| 24 | |
| 25 | struct X2 { |
Richard Trieu | 553b2b2 | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 26 | typedef int X2; // expected-error{{member 'X2' has the same name as its class}} |
Douglas Gregor | 36c22a2 | 2010-10-15 13:21:21 +0000 | [diff] [blame] | 27 | }; |
| 28 | |
Richard Smith | 88fe69c | 2015-07-06 01:45:27 +0000 | [diff] [blame] | 29 | struct 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 | |
| 35 | struct X2b { |
| 36 | template<typename T> struct X2b; // expected-error{{member 'X2b' has the same name as its class}} |
| 37 | }; |
| 38 | struct X2c { |
| 39 | template<typename T> void X2c(); // expected-error{{constructor cannot have a return type}} |
| 40 | }; |
| 41 | struct X2d { |
| 42 | template<typename T> static int X2d; // expected-error{{member 'X2d' has the same name as its class}} |
| 43 | }; |
| 44 | struct 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 |
Douglas Gregor | 36c22a2 | 2010-10-15 13:21:21 +0000 | [diff] [blame] | 49 | struct X3 { |
| 50 | enum E { |
| 51 | X3 // expected-error{{member 'X3' has the same name as its class}} |
| 52 | }; |
| 53 | }; |
Richard Smith | 88fe69c | 2015-07-06 01:45:27 +0000 | [diff] [blame] | 54 | struct X3a { |
| 55 | enum class E { |
| 56 | X3a // ok |
| 57 | }; |
| 58 | }; |
Douglas Gregor | 36c22a2 | 2010-10-15 13:21:21 +0000 | [diff] [blame] | 59 | |
| 60 | // - every member of every anonymous union that is a member of class T. |
| 61 | struct X4 { |
| 62 | union { |
| 63 | int X; |
| 64 | union { |
| 65 | float Y; |
| 66 | unsigned X4; // expected-error{{member 'X4' has the same name as its class}} |
| 67 | }; |
| 68 | }; |
| 69 | }; |