| Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s | 
| Douglas Gregor | 01beed0 | 2009-01-16 17:06:33 +0000 | [diff] [blame] | 2 | struct A {  | 
| Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 3 |   int a;  // expected-note 4{{member found by ambiguous name lookup}} | 
| Douglas Gregor | 01beed0 | 2009-01-16 17:06:33 +0000 | [diff] [blame] | 4 |   static int b; | 
| Douglas Gregor | 4e6ba4b | 2010-03-03 04:38:46 +0000 | [diff] [blame] | 5 |   static int c; // expected-note 2{{member found by ambiguous name lookup}} | 
| Douglas Gregor | 01beed0 | 2009-01-16 17:06:33 +0000 | [diff] [blame] | 6 |  | 
 | 7 |   enum E { enumerator }; | 
 | 8 |  | 
 | 9 |   typedef int type; | 
 | 10 |  | 
 | 11 |   static void f(int); | 
| Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 12 |   void f(float); // expected-note 2{{member found by ambiguous name lookup}} | 
| Douglas Gregor | 01beed0 | 2009-01-16 17:06:33 +0000 | [diff] [blame] | 13 |  | 
 | 14 |   static void static_f(int); | 
 | 15 |   static void static_f(double); | 
 | 16 | }; | 
 | 17 |  | 
 | 18 | struct B : A { | 
| Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 19 |   int d; // expected-note 2{{member found by ambiguous name lookup}} | 
| Douglas Gregor | 01beed0 | 2009-01-16 17:06:33 +0000 | [diff] [blame] | 20 |  | 
 | 21 |   enum E2 { enumerator2 }; | 
 | 22 |  | 
| Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 23 |   enum E3 { enumerator3 }; // expected-note 2{{member found by ambiguous name lookup}} | 
| Douglas Gregor | 01beed0 | 2009-01-16 17:06:33 +0000 | [diff] [blame] | 24 | }; | 
 | 25 |  | 
 | 26 | struct C : A { | 
| Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 27 |   int c; // expected-note 2{{member found by ambiguous name lookup}} | 
 | 28 |   int d; // expected-note 2{{member found by ambiguous name lookup}} | 
| Douglas Gregor | 01beed0 | 2009-01-16 17:06:33 +0000 | [diff] [blame] | 29 |  | 
| Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 30 |   enum E3 { enumerator3_2 }; // expected-note 2{{member found by ambiguous name lookup}} | 
| Douglas Gregor | 01beed0 | 2009-01-16 17:06:33 +0000 | [diff] [blame] | 31 | }; | 
 | 32 |  | 
 | 33 | struct D : B, C { | 
 | 34 |   void test_lookup(); | 
 | 35 | }; | 
 | 36 |  | 
 | 37 | void test_lookup(D d) { | 
| John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 38 |   d.a; // expected-error{{non-static member 'a' found in multiple base-class subobjects of type 'A':}} | 
| Douglas Gregor | 01beed0 | 2009-01-16 17:06:33 +0000 | [diff] [blame] | 39 |   (void)d.b; // okay | 
 | 40 |   d.c; // expected-error{{member 'c' found in multiple base classes of different types}} | 
 | 41 |   d.d; // expected-error{{member 'd' found in multiple base classes of different types}} | 
| John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 42 |   d.f(0); // expected-error{{non-static member 'f' found in multiple base-class subobjects of type 'A':}} | 
| Douglas Gregor | 01beed0 | 2009-01-16 17:06:33 +0000 | [diff] [blame] | 43 |   d.static_f(0); // okay | 
 | 44 |  | 
 | 45 |   D::E e = D::enumerator; // okay | 
 | 46 |   D::type t = 0; // okay | 
 | 47 |  | 
 | 48 |   D::E2 e2 = D::enumerator2; // okay | 
 | 49 |  | 
| Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 50 |   D::E3 e3; // expected-error{{multiple base classes}} | 
| Douglas Gregor | 01beed0 | 2009-01-16 17:06:33 +0000 | [diff] [blame] | 51 | } | 
 | 52 |  | 
 | 53 | void D::test_lookup() { | 
| John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 54 |   a; // expected-error{{non-static member 'a' found in multiple base-class subobjects of type 'A':}} | 
| Douglas Gregor | 01beed0 | 2009-01-16 17:06:33 +0000 | [diff] [blame] | 55 |   (void)b; // okay | 
 | 56 |   c; // expected-error{{member 'c' found in multiple base classes of different types}} | 
 | 57 |   d; // expected-error{{member 'd' found in multiple base classes of different types}} | 
| John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 58 |   f(0); // expected-error{{non-static member 'f' found in multiple base-class subobjects of type 'A':}} | 
| Douglas Gregor | 01beed0 | 2009-01-16 17:06:33 +0000 | [diff] [blame] | 59 |   static_f(0); // okay | 
 | 60 |  | 
| Douglas Gregor | 66b947f | 2009-01-16 19:38:23 +0000 | [diff] [blame] | 61 |   E e = enumerator; // okay | 
| Douglas Gregor | 01beed0 | 2009-01-16 17:06:33 +0000 | [diff] [blame] | 62 |   type t = 0; // okay | 
 | 63 |  | 
| Douglas Gregor | 66b947f | 2009-01-16 19:38:23 +0000 | [diff] [blame] | 64 |   E2 e2 = enumerator2; // okay | 
| Douglas Gregor | 01beed0 | 2009-01-16 17:06:33 +0000 | [diff] [blame] | 65 |  | 
 | 66 |   E3 e3; // expected-error{{member 'E3' found in multiple base classes of different types}} | 
 | 67 | } | 
 | 68 |  | 
 | 69 | struct B2 : virtual A { | 
| Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 70 |   int d; // expected-note 2{{member found by ambiguous name lookup}} | 
| Douglas Gregor | 01beed0 | 2009-01-16 17:06:33 +0000 | [diff] [blame] | 71 |  | 
 | 72 |   enum E2 { enumerator2 }; | 
 | 73 |  | 
| Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 74 |   enum E3 { enumerator3 }; // expected-note 2 {{member found by ambiguous name lookup}} | 
| Douglas Gregor | 01beed0 | 2009-01-16 17:06:33 +0000 | [diff] [blame] | 75 | }; | 
 | 76 |  | 
 | 77 | struct C2 : virtual A { | 
| Douglas Gregor | 4e6ba4b | 2010-03-03 04:38:46 +0000 | [diff] [blame] | 78 |   int c; | 
| Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 79 |   int d; // expected-note 2{{member found by ambiguous name lookup}} | 
| Douglas Gregor | 01beed0 | 2009-01-16 17:06:33 +0000 | [diff] [blame] | 80 |  | 
| Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 81 |   enum E3 { enumerator3_2 }; // expected-note 2{{member found by ambiguous name lookup}} | 
| Douglas Gregor | 01beed0 | 2009-01-16 17:06:33 +0000 | [diff] [blame] | 82 | }; | 
 | 83 |  | 
 | 84 | struct D2 : B2, C2 {  | 
 | 85 |   void test_virtual_lookup(); | 
 | 86 | }; | 
 | 87 |  | 
 | 88 | struct F : A { }; | 
 | 89 | struct G : F, D2 {  | 
 | 90 |   void test_virtual_lookup(); | 
 | 91 | }; | 
 | 92 |  | 
 | 93 | void test_virtual_lookup(D2 d2, G g) { | 
 | 94 |   (void)d2.a; | 
 | 95 |   (void)d2.b; | 
| Douglas Gregor | 4e6ba4b | 2010-03-03 04:38:46 +0000 | [diff] [blame] | 96 |   (void)d2.c; // okay | 
| Douglas Gregor | 01beed0 | 2009-01-16 17:06:33 +0000 | [diff] [blame] | 97 |   d2.d; // expected-error{{member 'd' found in multiple base classes of different types}} | 
 | 98 |   d2.f(0); // okay | 
 | 99 |   d2.static_f(0); // okay | 
 | 100 |  | 
 | 101 |   D2::E e = D2::enumerator; // okay | 
 | 102 |   D2::type t = 0; // okay | 
 | 103 |  | 
 | 104 |   D2::E2 e2 = D2::enumerator2; // okay | 
 | 105 |  | 
 | 106 |   D2::E3 e3; // expected-error{{member 'E3' found in multiple base classes of different types}} | 
 | 107 |  | 
| John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 108 |   g.a; // expected-error{{non-static member 'a' found in multiple base-class subobjects of type 'A':}} | 
| Douglas Gregor | 01beed0 | 2009-01-16 17:06:33 +0000 | [diff] [blame] | 109 |   g.static_f(0); // okay | 
 | 110 | } | 
 | 111 |  | 
 | 112 | void D2::test_virtual_lookup() { | 
 | 113 |   (void)a; | 
 | 114 |   (void)b; | 
| Douglas Gregor | 4e6ba4b | 2010-03-03 04:38:46 +0000 | [diff] [blame] | 115 |   (void)c; // okay | 
| Douglas Gregor | 01beed0 | 2009-01-16 17:06:33 +0000 | [diff] [blame] | 116 |   d; // expected-error{{member 'd' found in multiple base classes of different types}} | 
 | 117 |   f(0); // okay | 
 | 118 |   static_f(0); // okay | 
 | 119 |  | 
 | 120 |   E e = enumerator; // okay | 
 | 121 |   type t = 0; // okay | 
 | 122 |  | 
 | 123 |   E2 e2 = enumerator2; // okay | 
 | 124 |  | 
 | 125 |   E3 e3; // expected-error{{member 'E3' found in multiple base classes of different types}} | 
 | 126 | } | 
 | 127 |  | 
 | 128 | void G::test_virtual_lookup() { | 
| John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 129 |   a; // expected-error{{non-static member 'a' found in multiple base-class subobjects of type 'A':}} | 
| Douglas Gregor | 01beed0 | 2009-01-16 17:06:33 +0000 | [diff] [blame] | 130 |   static_f(0); // okay | 
 | 131 | } | 
| Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 132 |  | 
 | 133 |  | 
 | 134 | struct HasMemberType1 { | 
| Douglas Gregor | b696ea3 | 2009-02-04 17:00:24 +0000 | [diff] [blame] | 135 |   struct type { }; // expected-note{{member found by ambiguous name lookup}} | 
| Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 136 | }; | 
 | 137 |  | 
 | 138 | struct HasMemberType2 { | 
| Douglas Gregor | b696ea3 | 2009-02-04 17:00:24 +0000 | [diff] [blame] | 139 |   struct type { }; // expected-note{{member found by ambiguous name lookup}} | 
| Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 140 | }; | 
 | 141 |  | 
 | 142 | struct HasAnotherMemberType : HasMemberType1, HasMemberType2 {  | 
| Douglas Gregor | e2c565d | 2009-02-03 19:26:08 +0000 | [diff] [blame] | 143 |   struct type { }; | 
| Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 144 | }; | 
| Douglas Gregor | b696ea3 | 2009-02-04 17:00:24 +0000 | [diff] [blame] | 145 |  | 
 | 146 | struct UsesAmbigMemberType : HasMemberType1, HasMemberType2 { | 
| Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 147 |   type t; // expected-error{{member 'type' found in multiple base classes of different types}} | 
| Douglas Gregor | b696ea3 | 2009-02-04 17:00:24 +0000 | [diff] [blame] | 148 | }; | 
| Douglas Gregor | e942bbe | 2009-09-10 16:57:35 +0000 | [diff] [blame] | 149 |  | 
 | 150 | struct X0 { | 
 | 151 |   struct Inner { | 
 | 152 |     static const int m; | 
 | 153 |   }; | 
 | 154 |    | 
 | 155 |   static const int n = 17; | 
 | 156 | }; | 
 | 157 |  | 
 | 158 | const int X0::Inner::m = n; |