summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/init/pm1.C
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/g++.dg/init/pm1.C
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/g++.dg/init/pm1.C')
-rw-r--r--gcc/testsuite/g++.dg/init/pm1.C88
1 files changed, 88 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/init/pm1.C b/gcc/testsuite/g++.dg/init/pm1.C
new file mode 100644
index 000000000..c0aed2410
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/pm1.C
@@ -0,0 +1,88 @@
+// { dg-do run }
+
+// Copyright 2002 Free Software Foundation
+// Contributed by Jason Merrill and Alexandre Oliva
+
+// Test zero-initialization of pointers to data members. Their NULL
+// value is represented with -1, not 0.
+
+#include <stdlib.h>
+
+struct A
+{
+ int i;
+};
+
+int A::* gp;
+
+typedef int A::* iApm;
+
+iApm gp_zero = 0;
+iApm gp_dflt = iApm();
+iApm gp_cast = (iApm)0;
+iApm gp_func = iApm(0);
+iApm gp_stat = static_cast<iApm>(0);
+
+struct AD : A {};
+
+int AD::* gp_impl = gp_dflt;
+int AD::* gp_down = static_cast<int AD::*>(gp_stat);
+
+int A::* ga[2];
+
+// Test use in a simple struct.
+struct B
+{
+ int A::* mp;
+};
+
+B gb;
+
+struct D;
+struct C;
+extern D gd;
+extern C gc;
+
+// Test that in a class with a constructor, the pointer to member is
+// zero-initialized until the constructor is run.
+struct C
+{
+ int A::* mp;
+ inline C ();
+};
+
+int fail;
+struct D
+{
+ int count;
+ inline D ();
+};
+
+C::C() : mp (&A::i) { gd.count++; }
+
+D::D() : count (0)
+{
+ if (gc.mp != 0)
+ abort ();
+}
+
+// The D must come first for this to work.
+D gd;
+C gc;
+
+int main()
+{
+ static int A::* slp;
+ static int A::* sla[2];
+ static B slb;
+
+ if (gp != 0 || slp != 0
+ || gp_zero != 0 || gp_dflt != 0 || gp_cast != 0
+ || gp_func != 0 || gp_stat != 0
+ || gp_impl != 0 || gp_down != 0)
+ abort ();
+ if (ga[1] != 0 || sla[1] != 0)
+ abort ();
+ if (gb.mp != 0 || slb.mp != 0)
+ abort ();
+}