| 1 |
// Copyright (C) 2007 Free Software Foundation |
| 2 |
// Contributed by Ollie Wild <[email protected]> |
| 3 |
// { dg-do compile } |
| 4 |
|
| 5 |
// Assorted pointer to member function static cast tests. |
| 6 |
|
| 7 |
struct A { int f (); }; |
| 8 |
struct B : A { int f (); }; |
| 9 |
struct P : A { int f (); }; |
| 10 |
struct V { int f (); }; |
| 11 |
struct D : B, virtual V, private P { int f (); }; |
| 12 |
|
| 13 |
// Valid static casts. |
| 14 |
int (B::*p1)() = static_cast<int (B::*)()>(&D::f); |
| 15 |
int (D::*p2)() = static_cast<int (D::*)()>(&B::f); |
| 16 |
|
| 17 |
// Virtual base class. |
| 18 |
int (V::*p3)() = static_cast<int (V::*)()>(&D::f); // { dg-error "" } |
| 19 |
int (D::*p4)() = static_cast<int (D::*)()>(&V::f); // { dg-error "" } |
| 20 |
|
| 21 |
// Inaccessible base class. |
| 22 |
int (P::*p5)() = static_cast<int (P::*)()>(&D::f); // { dg-error "" } |
| 23 |
int (D::*p6)() = static_cast<int (D::*)()>(&P::f); // { dg-error "" } |
| 24 |
|
| 25 |
// Ambiguous base class. |
| 26 |
int (A::*p7)() = static_cast<int (A::*)()>(&D::f); // { dg-error "" } |
| 27 |
int (D::*p8)() = static_cast<int (D::*)()>(&A::f); // { dg-error "" } |
| 28 |
|
| 29 |
// Attempts to change member type. |
| 30 |
float (B::*p13)() = static_cast<float (B::*)()>(&D::f); // { dg-error "21:invalid .static_cast." } |
| 31 |
float (D::*p14)() = static_cast<float (D::*)()>(&B::f); // { dg-error "21:invalid .static_cast." } |