PR c++/10385
authorreichelt <reichelt@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 19 Apr 2006 17:15:54 +0000 (17:15 +0000)
committerreichelt <reichelt@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 19 Apr 2006 17:15:54 +0000 (17:15 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@113084 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/cvt.c
gcc/cp/rtti.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/conversion/dynamic1.C [new file with mode: 0644]

index 2d80e52..27d31ba 100644 (file)
@@ -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
index c59c74c..902372e 100644 (file)
@@ -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);
 
index 0275ed9..5c6d38d 100644 (file)
@@ -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.  */
index f3783b4..d88b8c8 100644 (file)
@@ -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 (file)
index 0000000..a781cba
--- /dev/null
@@ -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" }
+}