Debian Codegraph @

gcc/testsuite/g++.old-deja/g++.other/cast6.C

raw
1 // { dg-do assemble }
2
3 // Copyright (C) 2000 Free Software Foundation, Inc.
4 // Contributed by Nathan Sidwell 28 Nov 2000 <[email protected]>
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); // { dg-error "via virtual base" } invalid static_cast
45 foofPtr fp2 = static_cast <foofPtr> (bp); // { dg-error "via virtual base" } invalid static_cast
46 foofPtr fp3 = bp; // { dg-error "via virtual base" } cannot convert
47 fp3 = (foofPtr)bp; // { dg-error "via virtual base" } via virtual base
48
49 foomPtr fmp = &foo::m;
50 barmPtr bmp = static_cast <barmPtr> (fmp); // { dg-error "via virtual base" } invalid static_cast
51 foomPtr fmp2 = static_cast <foomPtr> (bmp); // { dg-error "via virtual base" } invalid static_cast
52 foomPtr fmp3 = bmp; // { dg-error "via virtual base" } cannot convert
53 fmp3 = (foomPtr)bmp; // { dg-error "via virtual base" } via virtual base
54 }
55
56 return 0;
57 }