1 // RUN: %clang_cc1 -fsyntax-only -verify %s
9 struct G : virtual D {};
15 int B::*pbi; // expected-error {{expected a class or namespace}}
16 int C::*pci; // expected-error {{'pci' does not point into a class}}
17 void A::*pdv; // expected-error {{'pdv' declared as a member pointer to void}}
18 int& A::*pdr; // expected-error {{'pdr' declared as a member pointer to a reference}}
21 // This requires tentative parsing.
22 int (A::*pf)(int, int);
24 // Implicit conversion to bool.
28 // Conversion from null pointer constant.
32 // Conversion to member of derived.
36 // Fail conversion due to ambiguity and virtuality.
37 int F::*pdif = pdi1; // expected-error {{ambiguous conversion from pointer to member of base class 'A' to pointer to member of derived class 'F':}}
38 int G::*pdig = pdi1; // expected-error {{conversion from pointer to member of class 'A' to pointer to member of class 'G' via virtual base 'D' is not allowed}}
40 // Conversion to member of base.
41 pdi1 = pdid; // expected-error {{assigning to 'int A::*' from incompatible type 'int D::*'}}
44 int (A::*pf2)(int, int);
45 int (D::*pf3)(int, int) = 0;
46 bool b1 = (pf == pf2); (void)b1;
47 bool b2 = (pf != pf2); (void)b2;
48 bool b3 = (pf == pf3); (void)b3;
49 bool b4 = (pf != 0); (void)b4;
57 struct HasMembers : TheBase
64 static void g(double);
76 int HasMembers::*pmi = &HasMembers::i;
80 void (HasMembers::*pmf)() = &HasMembers::f;
81 void (*pnf)() = &Fake::f;
82 &hm.f; // expected-error {{must explicitly qualify}} expected-warning{{result unused}}
84 void (HasMembers::*pmgv)() = &HasMembers::g;
85 void (HasMembers::*pmgi)(int) = &HasMembers::g;
86 void (*pmgd)(double) = &HasMembers::g;
88 void (HasMembers::*pmd)() = &HasMembers::d;
91 struct Incomplete; // expected-note {{forward declaration}}
94 HasMembers hm, *phm = &hm;
96 int HasMembers::*pi = &HasMembers::i;
103 void (HasMembers::*pf)() = &HasMembers::f;
107 (void)(hm->*pi); // expected-error {{left hand operand to ->* must be a pointer to class compatible with the right hand operand, but is 'HasMembers'}}
108 (void)(phm.*pi); // expected-error {{left hand operand to .* must be a class compatible with the right hand operand, but is 'HasMembers *'}}
109 (void)(i.*pi); // expected-error {{left hand operand to .* must be a class compatible with the right hand operand, but is 'int'}}
111 (void)(ptr->*pi); // expected-error {{left hand operand to ->* must be a pointer to class compatible with the right hand operand, but is 'int *'}}
118 (void)(f.*pai); // expected-error {{left hand operand to .* must be a class compatible with the right hand operand, but is 'F'}}
119 (void)(ptrf->*pai); // expected-error {{left hand operand to ->* must be a pointer to class compatible with the right hand operand, but is 'F *'}}
121 (void)(hm.*i); // expected-error {{pointer-to-member}}
122 (void)(phm->*i); // expected-error {{pointer-to-member}}
125 int Incomplete::*pii = 0;
126 (void)(inc->*pii); // expected-error {{pointer into incomplete}}
129 struct OverloadsPtrMem
131 int operator ->*(const char *);
136 int foo = m->*"Awesome!";
144 p = &h; // expected-error {{must explicitly qualify}}
145 p = &this->h; // expected-error {{must explicitly qualify}}
146 p = &(*this).h; // expected-error {{must explicitly qualify}}
153 struct X; // expected-note {{forward declaration}}
155 int test1(int Base::* p2m, X* object)
157 return object->*p2m; // expected-error {{left hand operand to ->*}}
166 struct Continuous : Process
172 typedef bool( base::Process::*Condition )();
175 { (void)(Condition) &base::Continuous::cond; }