1 // RUN: %clang_cc1 -fsyntax-only -verify %std_cxx98- %s
9 struct G
: virtual D
{};
10 class H
: A
{}; // expected-note 2{{implicitly declared private here}}
15 void (*A::*ppfie
)() throw();
16 #if __cplusplus < 201703L
17 // expected-error@-2 {{exception specifications are not allowed beyond a single level of indirection}}
21 #if __cplusplus <= 199711L // C++03 or earlier modes
22 // expected-warning@-2 {{use of enumeration in a nested name specifier is a C++11 extension}}
24 // expected-error@-4 {{'pbi' does not point into a class}}
25 int C::*pci
; // expected-error {{'pci' does not point into a class}}
26 void A::*pdv
; // expected-error {{'pdv' declared as a member pointer to void}}
27 int& A::*pdr
; // expected-error {{'pdr' declared as a member pointer to a reference}}
30 // This requires tentative parsing.
31 int (A::*pf
)(int, int);
33 // Implicit conversion to bool.
37 // Conversion from null pointer constant.
41 // Conversion to member of derived.
45 // Fail conversion due to ambiguity and virtuality.
46 int F::*pdif
= pdi1
; // expected-error {{ambiguous conversion from pointer to member of base class 'A' to pointer to member of derived class 'F':}}
47 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}}
49 // Conversion to member of base.
50 pdi1
= pdid
; // expected-error {{assigning to 'int A::*' from incompatible type 'int D::*'}}
53 int (A::*pf2
)(int, int);
54 int (D::*pf3
)(int, int) = 0;
55 bool b1
= (pf
== pf2
); (void)b1
;
56 bool b2
= (pf
!= pf2
); (void)b2
;
57 bool b3
= (pf
== pf3
); (void)b3
;
58 bool b4
= (pf
!= 0); (void)b4
;
66 struct HasMembers
: TheBase
73 static void g(double);
85 int HasMembers::*pmi
= &HasMembers::i
;
89 void (HasMembers::*pmf
)() = &HasMembers::f
;
90 void (*pnf
)() = &Fake::f
;
91 &hm
.f
; // expected-error {{cannot create a non-constant pointer to member function}}
93 void (HasMembers::*pmgv
)() = &HasMembers::g
;
94 void (HasMembers::*pmgi
)(int) = &HasMembers::g
;
95 void (*pmgd
)(double) = &HasMembers::g
;
97 void (HasMembers::*pmd
)() = &HasMembers::d
;
103 HasMembers hm
, *phm
= &hm
;
105 int HasMembers::*pi
= &HasMembers::i
;
112 void (HasMembers::*pf
)() = &HasMembers::f
;
116 (void)(hm
->*pi
); // expected-error {{left hand operand to ->* must be a pointer to class compatible with the right hand operand, but is 'HasMembers'}}
117 (void)(phm
.*pi
); // expected-error {{left hand operand to .* must be a class compatible with the right hand operand, but is 'HasMembers *'}}
118 (void)(i
.*pi
); // expected-error {{left hand operand to .* must be a class compatible with the right hand operand, but is 'int'}}
120 (void)(ptr
->*pi
); // expected-error {{left hand operand to ->* must be a pointer to class compatible with the right hand operand, but is 'int *'}}
127 (void)(f
.*pai
); // expected-error {{ambiguous conversion from derived class 'F' to base class 'A'}}
128 (void)(ptrf
->*pai
); // expected-error {{ambiguous conversion from derived class 'F' to base class 'A'}}
130 (void)(h
.*pai
); // expected-error {{cannot cast 'H' to its private base class 'A'}}
131 (void)(ptrh
->*pai
); // expected-error {{cannot cast 'H' to its private base class 'A'}}
133 (void)(hm
.*i
); // expected-error {{pointer-to-member}}
134 (void)(phm
->*i
); // expected-error {{pointer-to-member}}
138 int Incomplete::*pii
= 0;
142 struct OverloadsPtrMem
144 int operator ->*(const char *);
149 int foo
= m
->*"Awesome!";
157 p
= &h
; // expected-error {{must explicitly qualify}}
158 p
= &this->h
; // expected-error {{cannot create a non-constant pointer to member function}}
159 p
= &(*this).h
; // expected-error {{cannot create a non-constant pointer to member function}}
166 struct X
; // expected-note {{forward declaration}}
168 int test1(int Base::* p2m
, X
* object
)
170 return object
->*p2m
; // expected-error {{left hand operand to ->*}}
179 struct Continuous
: Process
185 typedef bool( base::Process::*Condition
)();
188 { (void)(Condition
) &base::Continuous::cond
; }
191 namespace rdar8358512
{
192 // We can't call this with an overload set because we're not allowed
193 // to look into overload sets unless the parameter has some kind of
195 template <class F
> void bind(F f
); // expected-note 12 {{candidate template ignored}}
196 template <class F
, class T
> void bindmem(F (T::*f
)()); // expected-note 4 {{candidate template ignored}}
197 template <class F
> void bindfn(F (*f
)()); // expected-note 4 {{candidate template ignored}}
204 static void mixed(int);
207 static void stat(int);
209 template <typename T
> struct Test0
{
211 bind(&nonstat
); // expected-error {{no matching function for call}}
212 bind(&A::nonstat
); // expected-error {{no matching function for call}}
214 bind(&mixed
); // expected-error {{no matching function for call}}
215 bind(&A::mixed
); // expected-error {{no matching function for call}}
217 bind(&stat
); // expected-error {{no matching function for call}}
218 bind(&A::stat
); // expected-error {{no matching function for call}}
222 template <typename T
> struct Test1
{
224 bindmem(&nonstat
); // expected-error {{no matching function for call}}
225 bindmem(&A::nonstat
);
227 bindmem(&mixed
); // expected-error {{no matching function for call}}
230 bindmem(&stat
); // expected-error {{no matching function for call}}
231 bindmem(&A::stat
); // expected-error {{no matching function for call}}
235 template <typename T
> struct Test2
{
237 bindfn(&nonstat
); // expected-error {{no matching function for call}}
238 bindfn(&A::nonstat
); // expected-error {{no matching function for call}}
240 bindfn(&mixed
); // expected-error {{no matching function for call}}
241 bindfn(&A::mixed
); // expected-error {{no matching function for call}}
249 template <class T
> class B
{
254 static void mixed(int);
257 static void stat(int);
259 // None of these can be diagnosed yet, because the arguments are
273 bind(&nonstat
); // expected-error {{no matching function for call}}
274 bind(&B::nonstat
); // expected-error {{no matching function for call}}
276 bind(&mixed
); // expected-error {{no matching function for call}}
277 bind(&B::mixed
); // expected-error {{no matching function for call}}
279 bind(&stat
); // expected-error {{no matching function for call}}
280 bind(&B::stat
); // expected-error {{no matching function for call}}
284 template void B
<int>::test0b(); // expected-note {{in instantiation}}
288 template<class R
, class T
> struct dm
292 template<class U
> int & call(U u
)
293 { return u
->*f_
; } // expected-error{{reference to non-static member function must be called; did you mean to call it with no arguments?}} expected-error {{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'int'}}
295 template<class U
> int operator()(U u
)
296 { call(u
); } // expected-note{{in instantiation of}}
299 template<class R
, class T
>
300 dm
<R
, T
> mem_fn(R
T::*) ;
303 { int nullary_v(); };
308 mem_fn(&test::nullary_v
)(t
); // expected-note{{in instantiation of}}
313 struct A
{ int foo
; };
315 // Verify that we perform (and check) an lvalue conversion on the operands here.
316 return (*((A
**) 0)) // expected-warning {{indirection of non-volatile null pointer will be deleted}} expected-note {{consider}}
317 ->**(int A::**) 0; // expected-warning {{indirection of non-volatile null pointer will be deleted}} expected-note {{consider}}
321 // Verify that we perform (and check) an lvalue conversion on the operands here.
322 // TODO: the .* should itself warn about being a dereference of null.
324 .**(int A::**) 0; // expected-warning {{indirection of non-volatile null pointer will be deleted}} expected-note {{consider}}