blob: 31973c1257007640e3991825d05f106b2bd65294 [file] [log] [blame]
Sebastian Redlf30208a2009-01-24 21:16:55 +00001// RUN: clang -fsyntax-only -verify %s
2
3struct A {};
4enum B { Dummy };
5namespace C {}
Sebastian Redl4433aaf2009-01-25 19:43:20 +00006struct D : A {};
Sebastian Redl9e5e4aa2009-01-26 19:54:48 +00007struct E : A {};
8struct F : D, E {};
9struct G : virtual D {};
Sebastian Redlf30208a2009-01-24 21:16:55 +000010
11int A::*pdi1;
12int (::A::*pdi2);
13int (A::*pfi)(int);
14
15int B::*pbi; // expected-error {{expected a class or namespace}}
16int C::*pci; // expected-error {{'pci' does not point into a class}}
17void A::*pdv; // expected-error {{'pdv' declared as a member pointer to void}}
18int& A::*pdr; // expected-error {{'pdr' declared as a pointer to a reference}}
Sebastian Redl8edef7c2009-01-24 23:29:36 +000019
20void f() {
21 // This requires tentative parsing.
22 int (A::*pf)(int, int);
Sebastian Redl4433aaf2009-01-25 19:43:20 +000023
24 // Implicit conversion to bool.
25 bool b = pdi1;
26 b = pfi;
27
28 // Conversion from null pointer constant.
29 pf = 0;
30 pf = __null;
31
32 // Conversion to member of derived.
33 int D::*pdid = pdi1;
34 pdid = pdi2;
Sebastian Redl9e5e4aa2009-01-26 19:54:48 +000035
36 // Fail conversion due to ambiguity and virtuality.
37 int F::*pdif = pdi1; // expected-error {{ambiguous conversion from pointer to member of base class 'struct A' to pointer to member of derived class 'struct F'}} expected-error {{incompatible type}}
38 int G::*pdig = pdi1; // expected-error {{conversion from pointer to member of class 'struct A' to pointer to member of class 'struct G' via virtual base 'struct D' is not allowed}} expected-error {{incompatible type}}
Sebastian Redl21593ac2009-01-28 18:33:18 +000039
40 // Conversion to member of base.
41 pdi1 = pdid; // expected-error {{incompatible type assigning 'int struct D::*', expected 'int struct A::*'}}
Sebastian Redl8edef7c2009-01-24 23:29:36 +000042}