1// { dg-do run }
2
3// Copyright 2002  Free Software Foundation
4// Contributed by Jason Merrill and Alexandre Oliva
5
6// Test zero-initialization of pointers to data members.  Their NULL
7// value is represented with -1, not 0.
8
9#include <stdlib.h>
10
11struct A
12{
13  int i;
14};
15
16int A::* gp;
17
18typedef int A::* iApm;
19
20iApm gp_zero = 0;
21iApm gp_dflt = iApm();
22iApm gp_cast = (iApm)0;
23iApm gp_func = iApm(0);
24iApm gp_stat = static_cast<iApm>(0);
25
26struct AD : A {};
27
28int AD::* gp_impl = gp_dflt;
29int AD::* gp_down = static_cast<int AD::*>(gp_stat);
30
31int A::* ga[2];
32
33// Test use in a simple struct.
34struct B
35{
36  int A::* mp;
37};
38
39B gb;
40
41struct D;
42struct C;
43extern D gd;
44extern C gc;
45
46// Test that in a class with a constructor, the pointer to member is
47// zero-initialized until the constructor is run.
48struct C
49{
50  int A::* mp;
51  inline C ();
52};
53
54int fail;
55struct D
56{
57  int count;
58  inline D ();
59};
60
61C::C() : mp (&A::i) { gd.count++; }
62
63D::D() : count (0)
64{
65  if (gc.mp != 0)
66    abort ();
67}
68
69// The D must come first for this to work.
70D gd;
71C gc;
72
73int main()
74{
75  static int A::* slp;
76  static int A::* sla[2];
77  static B slb;
78
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 ();
88}
89