159 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s2struct A { 3 int a; // expected-note 4{{member found by ambiguous name lookup}}4 static int b;5 static int c; // expected-note 2{{member found by ambiguous name lookup}}6 7 enum E { enumerator };8 9 typedef int type;10 11 static void f(int);12 void f(float); // expected-note 2{{member found by ambiguous name lookup}}13 14 static void static_f(int);15 static void static_f(double);16};17 18struct B : A {19 int d; // expected-note 2{{member found by ambiguous name lookup}}20 21 enum E2 { enumerator2 };22 23 enum E3 { enumerator3 }; // expected-note 2{{member type 'B::E3' found by ambiguous name lookup}}24};25 26struct C : A {27 int c; // expected-note 2{{member found by ambiguous name lookup}}28 int d; // expected-note 2{{member found by ambiguous name lookup}}29 30 enum E3 { enumerator3_2 }; // expected-note 2{{member type 'C::E3' found by ambiguous name lookup}}31};32 33struct D : B, C {34 void test_lookup();35};36 37void test_lookup(D d) {38 d.a; // expected-error{{non-static member 'a' found in multiple base-class subobjects of type 'A':}}39 (void)d.b; // okay40 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}}42 d.f(0); // expected-error{{non-static member 'f' found in multiple base-class subobjects of type 'A':}}43 d.static_f(0); // okay44 45 D::E e = D::enumerator; // okay46 D::type t = 0; // okay47 48 D::E2 e2 = D::enumerator2; // okay49 50 D::E3 e3; // expected-error{{multiple base classes}}51}52 53void D::test_lookup() {54 a; // expected-error{{non-static member 'a' found in multiple base-class subobjects of type 'A':}}55 (void)b; // okay56 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}}58 f(0); // expected-error{{non-static member 'f' found in multiple base-class subobjects of type 'A':}}59 static_f(0); // okay60 61 E e = enumerator; // okay62 type t = 0; // okay63 64 E2 e2 = enumerator2; // okay65 66 E3 e3; // expected-error{{member 'E3' found in multiple base classes of different types}}67}68 69struct B2 : virtual A {70 int d; // expected-note 2{{member found by ambiguous name lookup}}71 72 enum E2 { enumerator2 };73 74 enum E3 { enumerator3 }; // expected-note 2 {{member type 'B2::E3' found by ambiguous name lookup}}75};76 77struct C2 : virtual A {78 int c;79 int d; // expected-note 2{{member found by ambiguous name lookup}}80 81 enum E3 { enumerator3_2 }; // expected-note 2{{member type 'C2::E3' found by ambiguous name lookup}}82};83 84struct D2 : B2, C2 { 85 void test_virtual_lookup();86};87 88struct F : A { };89struct G : F, D2 { 90 void test_virtual_lookup();91};92 93void test_virtual_lookup(D2 d2, G g) {94 (void)d2.a;95 (void)d2.b;96 (void)d2.c; // okay97 d2.d; // expected-error{{member 'd' found in multiple base classes of different types}}98 d2.f(0); // okay99 d2.static_f(0); // okay100 101 D2::E e = D2::enumerator; // okay102 D2::type t = 0; // okay103 104 D2::E2 e2 = D2::enumerator2; // okay105 106 D2::E3 e3; // expected-error{{member 'E3' found in multiple base classes of different types}}107 108 g.a; // expected-error{{non-static member 'a' found in multiple base-class subobjects of type 'A':}}109 g.static_f(0); // okay110}111 112void D2::test_virtual_lookup() {113 (void)a;114 (void)b;115 (void)c; // okay116 d; // expected-error{{member 'd' found in multiple base classes of different types}}117 f(0); // okay118 static_f(0); // okay119 120 E e = enumerator; // okay121 type t = 0; // okay122 123 E2 e2 = enumerator2; // okay124 125 E3 e3; // expected-error{{member 'E3' found in multiple base classes of different types}}126}127 128void G::test_virtual_lookup() {129 a; // expected-error{{non-static member 'a' found in multiple base-class subobjects of type 'A':}}130 static_f(0); // okay131}132 133 134struct HasMemberType1 {135 struct type { }; // expected-note{{member type 'HasMemberType1::type' found by ambiguous name lookup}}136};137 138struct HasMemberType2 {139 struct type { }; // expected-note{{member type 'HasMemberType2::type' found by ambiguous name lookup}}140};141 142struct HasAnotherMemberType : HasMemberType1, HasMemberType2 { 143 struct type { };144};145 146struct UsesAmbigMemberType : HasMemberType1, HasMemberType2 {147 type t; // expected-error{{member 'type' found in multiple base classes of different types}}148};149 150struct X0 {151 struct Inner {152 static const int m;153 };154 155 static const int n = 17;156};157 158const int X0::Inner::m = n;159