// { dg-do run }
|
// { dg-do run }
|
|
|
// Copyright 2002 Free Software Foundation
|
// Copyright 2002 Free Software Foundation
|
// Contributed by Jason Merrill and Alexandre Oliva
|
// Contributed by Jason Merrill and Alexandre Oliva
|
|
|
// Test zero-initialization of pointers to data members. Their NULL
|
// Test zero-initialization of pointers to data members. Their NULL
|
// value is represented with -1, not 0.
|
// value is represented with -1, not 0.
|
|
|
#include
|
#include
|
|
|
struct A
|
struct A
|
{
|
{
|
int i;
|
int i;
|
};
|
};
|
|
|
int A::* gp;
|
int A::* gp;
|
|
|
typedef int A::* iApm;
|
typedef int A::* iApm;
|
|
|
iApm gp_zero = 0;
|
iApm gp_zero = 0;
|
iApm gp_dflt = iApm();
|
iApm gp_dflt = iApm();
|
iApm gp_cast = (iApm)0;
|
iApm gp_cast = (iApm)0;
|
iApm gp_func = iApm(0);
|
iApm gp_func = iApm(0);
|
iApm gp_stat = static_cast(0);
|
iApm gp_stat = static_cast(0);
|
|
|
struct AD : A {};
|
struct AD : A {};
|
|
|
int AD::* gp_impl = gp_dflt;
|
int AD::* gp_impl = gp_dflt;
|
int AD::* gp_down = static_cast(gp_stat);
|
int AD::* gp_down = static_cast(gp_stat);
|
|
|
int A::* ga[2];
|
int A::* ga[2];
|
|
|
// Test use in a simple struct.
|
// Test use in a simple struct.
|
struct B
|
struct B
|
{
|
{
|
int A::* mp;
|
int A::* mp;
|
};
|
};
|
|
|
B gb;
|
B gb;
|
|
|
struct D;
|
struct D;
|
struct C;
|
struct C;
|
extern D gd;
|
extern D gd;
|
extern C gc;
|
extern C gc;
|
|
|
// Test that in a class with a constructor, the pointer to member is
|
// Test that in a class with a constructor, the pointer to member is
|
// zero-initialized until the constructor is run.
|
// zero-initialized until the constructor is run.
|
struct C
|
struct C
|
{
|
{
|
int A::* mp;
|
int A::* mp;
|
inline C ();
|
inline C ();
|
};
|
};
|
|
|
int fail;
|
int fail;
|
struct D
|
struct D
|
{
|
{
|
int count;
|
int count;
|
inline D ();
|
inline D ();
|
};
|
};
|
|
|
C::C() : mp (&A::i) { gd.count++; }
|
C::C() : mp (&A::i) { gd.count++; }
|
|
|
D::D() : count (0)
|
D::D() : count (0)
|
{
|
{
|
if (gc.mp != 0)
|
if (gc.mp != 0)
|
abort ();
|
abort ();
|
}
|
}
|
|
|
// The D must come first for this to work.
|
// The D must come first for this to work.
|
D gd;
|
D gd;
|
C gc;
|
C gc;
|
|
|
int main()
|
int main()
|
{
|
{
|
static int A::* slp;
|
static int A::* slp;
|
static int A::* sla[2];
|
static int A::* sla[2];
|
static B slb;
|
static B slb;
|
|
|
if (gp != 0 || slp != 0
|
if (gp != 0 || slp != 0
|
|| gp_zero != 0 || gp_dflt != 0 || gp_cast != 0
|
|| gp_zero != 0 || gp_dflt != 0 || gp_cast != 0
|
|| gp_func != 0 || gp_stat != 0
|
|| gp_func != 0 || gp_stat != 0
|
|| gp_impl != 0 || gp_down != 0)
|
|| gp_impl != 0 || gp_down != 0)
|
abort ();
|
abort ();
|
if (ga[1] != 0 || sla[1] != 0)
|
if (ga[1] != 0 || sla[1] != 0)
|
abort ();
|
abort ();
|
if (gb.mp != 0 || slb.mp != 0)
|
if (gb.mp != 0 || slb.mp != 0)
|
abort ();
|
abort ();
|
}
|
}
|
|
|