aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Mitchell <mark@markmitchell.com>1998-08-07 09:56:06 +0000
committerMark Mitchell <mmitchel@gcc.gnu.org>1998-08-07 09:56:06 +0000
commit523633872ac859b97c453f3c7356201f934e3478 (patch)
treef552903fd32c0e5acdd1baa05318a0912933f57a
parentbd106708cf7cea9e34749c116ebf70e8d5a0ece3 (diff)
downloadgcc-523633872ac859b97c453f3c7356201f934e3478.zip
gcc-523633872ac859b97c453f3c7356201f934e3478.tar.gz
gcc-523633872ac859b97c453f3c7356201f934e3478.tar.bz2
cvt.c (cp_convert_to_pointer): Handle NULL pointer conversions, even in complex virtual base class hierarchies.
* cvt.c (cp_convert_to_pointer): Handle NULL pointer conversions, even in complex virtual base class hierarchies. From-SVN: r21626
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/cvt.c10
-rw-r--r--gcc/testsuite/g++.old-deja/g++.other/cast1.C16
3 files changed, 30 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index f6bc1b6..f1957d8 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+1998-08-07 Mark Mitchell <mark@markmitchell.com>
+
+ * cvt.c (cp_convert_to_pointer): Handle a NULL pointer
+ conversions, even in complex virtual base class hierarchies.
+
1998-08-06 Mark Mitchell <mark@markmitchell.com>
* cp-tree.h (ENUM_TEMPLATE_INFO): New macro.
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 18b7d8b..1078488 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -154,7 +154,15 @@ cp_convert_to_pointer (type, expr)
&& TREE_CODE (TREE_TYPE (type)) == RECORD_TYPE
&& IS_AGGR_TYPE (TREE_TYPE (type))
&& IS_AGGR_TYPE (TREE_TYPE (intype))
- && TREE_CODE (TREE_TYPE (intype)) == RECORD_TYPE)
+ && TREE_CODE (TREE_TYPE (intype)) == RECORD_TYPE
+ /* If EXPR is NULL, then we don't need to do any arithmetic
+ to convert it:
+
+ [conv.ptr]
+
+ The null pointer value is converted to the null pointer
+ value of the destination type. */
+ && !integer_zerop (expr))
{
enum tree_code code = PLUS_EXPR;
tree binfo = get_binfo (TREE_TYPE (type), TREE_TYPE (intype), 1);
diff --git a/gcc/testsuite/g++.old-deja/g++.other/cast1.C b/gcc/testsuite/g++.old-deja/g++.other/cast1.C
new file mode 100644
index 0000000..7cd8059
--- /dev/null
+++ b/gcc/testsuite/g++.old-deja/g++.other/cast1.C
@@ -0,0 +1,16 @@
+// Build don't link:
+
+struct S0 { };
+struct S1 : virtual public S0 { };
+struct S2 : virtual public S0 { };
+
+struct S3 : public S1, public S2, virtual public S0
+{
+};
+
+void f(const S0*) {}
+
+void g()
+{
+ f(static_cast<S3*>(0));
+}