OSDN Git Service

PR c++/4222, c++/5995
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.old-deja / g++.other / cast6.C
1 // Build don't link:
2
3 // Copyright (C) 2000 Free Software Foundation, Inc.
4 // Contributed by Nathan Sidwell 28 Nov 2000 <nathan@codesourcery.com>
5
6 // We failed to reject static_cast and implicit conversions of pointers to
7 // member that traversed a virtual base.
8
9 struct bar
10 {
11   int barm;
12     static void a();
13 };
14 struct filler1 {int fm;};
15 struct filler2 {int fm;};
16 struct filler3 {int fm;};
17 struct filler4 {int fm;};
18
19 struct baz : filler1, bar, filler2
20 {
21   int bazm;
22 };
23
24 struct foo : filler3, virtual baz, filler4
25 {
26     static void a();
27     void b() {};
28     int m;
29 };
30
31 typedef void (bar::*barfPtr)();
32 typedef void (foo::*foofPtr)();
33 typedef int bar::*barmPtr;
34 typedef int foo::*foomPtr;
35
36 struct X;
37 typedef void (X::*xfPtr) ();
38 typedef int X::*xmPtr;
39
40 int main ()
41 {
42   {
43     foofPtr fp = &foo::b;
44     barfPtr bp = static_cast <barfPtr> (fp);    // ERROR - invalid static_cast
45     foofPtr fp2 = static_cast <foofPtr> (bp);   // ERROR - invalid static_cast
46     foofPtr fp3 = bp;                           // ERROR - cannot convert
47     fp3 = (foofPtr)bp;                          // WARNING - via virtual base
48     
49     foomPtr fmp = &foo::m;
50     barmPtr bmp = static_cast <barmPtr> (fmp);  // ERROR - invalid static_cast
51     foomPtr fmp2 = static_cast <foomPtr> (bmp); // ERROR - invalid static_cast
52     foomPtr fmp3 = bmp;                         // ERROR - cannot convert
53     fmp3 = (foomPtr)bmp;                        // WARNING - via virtual base
54   }
55   
56   return 0;
57 }