Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 1 | // RUN: clang -fsyntax-only -verify %s |
| 2 | |
| 3 | struct A {}; |
| 4 | enum B { Dummy }; |
| 5 | namespace C {} |
Sebastian Redl | 4433aaf | 2009-01-25 19:43:20 +0000 | [diff] [blame] | 6 | struct D : A {}; |
Sebastian Redl | 9e5e4aa | 2009-01-26 19:54:48 +0000 | [diff] [blame^] | 7 | struct E : A {}; |
| 8 | struct F : D, E {}; |
| 9 | struct G : virtual D {}; |
Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 10 | |
| 11 | int A::*pdi1; |
| 12 | int (::A::*pdi2); |
| 13 | int (A::*pfi)(int); |
| 14 | |
| 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 pointer to a reference}} |
Sebastian Redl | 8edef7c | 2009-01-24 23:29:36 +0000 | [diff] [blame] | 19 | |
| 20 | void f() { |
| 21 | // This requires tentative parsing. |
| 22 | int (A::*pf)(int, int); |
Sebastian Redl | 4433aaf | 2009-01-25 19:43:20 +0000 | [diff] [blame] | 23 | |
| 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 Redl | 9e5e4aa | 2009-01-26 19:54:48 +0000 | [diff] [blame^] | 35 | |
| 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 Redl | 8edef7c | 2009-01-24 23:29:36 +0000 | [diff] [blame] | 39 | } |