2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.dg / init / pm1.C
blobc0aed241086bdeeb1c17d0da519baa270780271a
1 // { dg-do run }
3 // Copyright 2002  Free Software Foundation
4 // Contributed by Jason Merrill and Alexandre Oliva
6 // Test zero-initialization of pointers to data members.  Their NULL
7 // value is represented with -1, not 0.
9 #include <stdlib.h>
11 struct A
13   int i;
16 int A::* gp;
18 typedef int A::* iApm;
20 iApm gp_zero = 0;
21 iApm gp_dflt = iApm();
22 iApm gp_cast = (iApm)0;
23 iApm gp_func = iApm(0);
24 iApm gp_stat = static_cast<iApm>(0);
26 struct AD : A {};
28 int AD::* gp_impl = gp_dflt;
29 int AD::* gp_down = static_cast<int AD::*>(gp_stat);
31 int A::* ga[2];
33 // Test use in a simple struct.
34 struct B
36   int A::* mp;
39 B gb;
41 struct D;
42 struct C;
43 extern D gd;
44 extern C gc;
46 // Test that in a class with a constructor, the pointer to member is
47 // zero-initialized until the constructor is run.
48 struct C
50   int A::* mp;
51   inline C ();
54 int fail;
55 struct D
57   int count;
58   inline D ();
61 C::C() : mp (&A::i) { gd.count++; }
63 D::D() : count (0)
65   if (gc.mp != 0)
66     abort ();
69 // The D must come first for this to work.
70 D gd;
71 C gc;
73 int main()
75   static int A::* slp;
76   static int A::* sla[2];
77   static B slb;
79   if (gp != 0 || slp != 0
80       || gp_zero != 0 || gp_dflt != 0 || gp_cast != 0
81       || gp_func != 0 || gp_stat != 0
82       || gp_impl != 0 || gp_down != 0)
83     abort ();
84   if (ga[1] != 0 || sla[1] != 0)
85     abort ();
86   if (gb.mp != 0 || slb.mp != 0)
87     abort ();