aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorVolker Reichelt <reichelt@igpm.rwth-aachen.de>2006-04-19 17:15:54 +0000
committerVolker Reichelt <reichelt@gcc.gnu.org>2006-04-19 17:15:54 +0000
commitd149fba0ff511eda85cb47a630ffc499ea5a8756 (patch)
tree4c87550ddc6151cf241615c6e60fff6799983f78 /gcc
parent37e7dc121db68d87fb61996219088f0b94680455 (diff)
downloadgcc-d149fba0ff511eda85cb47a630ffc499ea5a8756.zip
gcc-d149fba0ff511eda85cb47a630ffc499ea5a8756.tar.gz
gcc-d149fba0ff511eda85cb47a630ffc499ea5a8756.tar.bz2
re PR c++/10385 (Internal compiler error in build_up_reference, at cp/cvt.c:353, on invalid dynamic_cast)
PR c++/10385 * rtti.c (build_dynamic_cast_1): Check for invalid conversions before calling convert_to_reference. * cvt.c (convert_to_reference): Assert that reftype is a REFERENCE_TYPE. * g++.dg/conversion/dynamic1.C: New test. From-SVN: r113084
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog8
-rw-r--r--gcc/cp/cvt.c1
-rw-r--r--gcc/cp/rtti.c6
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/conversion/dynamic1.C15
5 files changed, 32 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 2d80e52..27d31ba 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+2006-04-19 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
+
+ PR c++/10385
+ * rtti.c (build_dynamic_cast_1): Check for invalid conversions
+ before calling convert_to_reference.
+ * cvt.c (convert_to_reference): Assert that reftype is a
+ REFERENCE_TYPE.
+
2006-04-19 Mark Mitchell <mark@codesourcery.com>
PR c++/27102
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index c59c74c..902372e 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -460,6 +460,7 @@ convert_to_reference (tree reftype, tree expr, int convtype,
intype = TREE_TYPE (expr);
gcc_assert (TREE_CODE (intype) != REFERENCE_TYPE);
+ gcc_assert (TREE_CODE (reftype) == REFERENCE_TYPE);
intype = TYPE_MAIN_VARIANT (intype);
diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c
index 0275ed9..5c6d38d 100644
--- a/gcc/cp/rtti.c
+++ b/gcc/cp/rtti.c
@@ -513,10 +513,7 @@ build_dynamic_cast_1 (tree type, tree expr)
}
else
{
- /* Apply trivial conversion T -> T& for dereferenced ptrs. */
exprtype = build_reference_type (exprtype);
- expr = convert_to_reference (exprtype, expr, CONV_IMPLICIT,
- LOOKUP_NORMAL, NULL_TREE);
/* T is a reference type, v shall be an lvalue of a complete class
type, and the result is an lvalue of the type referred to by T. */
@@ -532,6 +529,9 @@ build_dynamic_cast_1 (tree type, tree expr)
goto fail;
}
+ /* Apply trivial conversion T -> T& for dereferenced ptrs. */
+ expr = convert_to_reference (exprtype, expr, CONV_IMPLICIT,
+ LOOKUP_NORMAL, NULL_TREE);
}
/* The dynamic_cast operator shall not cast away constness. */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index f3783b4..d88b8c8 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2006-04-19 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
+
+ PR c++/10385
+ * g++.dg/conversion/dynamic1.C: New test.
+
2006-04-19 Mark Mitchell <mark@codesourcery.com>
PR c++/27102
diff --git a/gcc/testsuite/g++.dg/conversion/dynamic1.C b/gcc/testsuite/g++.dg/conversion/dynamic1.C
new file mode 100644
index 0000000..a781cba
--- /dev/null
+++ b/gcc/testsuite/g++.dg/conversion/dynamic1.C
@@ -0,0 +1,15 @@
+// PR c++/10385
+// Origin: <douglas@coc.ufrj.br>
+// { dg-do compile }
+
+struct A
+{
+ void foo();
+};
+
+A& bar();
+
+void baz()
+{
+ dynamic_cast<A&>( bar().foo ); // { dg-error "cannot dynamic_cast" }
+}