]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/10385 (Internal compiler error in build_up_reference, at cp/cvt.c:353,...
authorVolker Reichelt <reichelt@igpm.rwth-aachen.de>
Wed, 19 Apr 2006 17:23:10 +0000 (17:23 +0000)
committerVolker Reichelt <reichelt@gcc.gnu.org>
Wed, 19 Apr 2006 17:23:10 +0000 (17:23 +0000)
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: r113086

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 15920a97781d1f83f59c4a515b099a9c998ed0a6..c41a9b561ad85267848eb284d90d07cf13455c8a 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-03-09  Release Manager
 
        * GCC 4.0.3 released.
        * pt.c (instantiate_class_template,
        resolve_typename_type): Likewise.
 
-2005-01-03  Volker Reichelt  <reichelt@igpm.rwth-aaachen.de>
+2005-01-03  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
 
        PR c++/14136
        * parser.c (cp_parser_unqualified_id): Do not issue error message
index ac48de15d92dcafff5c799e0b59cc638527b43dd..455027965fdbda95b6507e934ed896d6d363cb25 100644 (file)
@@ -458,6 +458,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 4fbf35a6f761483a05c94838a23247120c3d4120..5f44fd7ed1a53153f5055d64c16b8aff612ae6c8 100644 (file)
@@ -485,10 +485,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.  */
@@ -504,6 +501,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 c4ee2e558eab4738648ac99019d588e3769383f5..4d509d36c7d58d1d1e8a65ba624188ac85616c0c 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-10  Matthias Klose  <doko@debian.org>
 
        * testsuite/lib/gcc-defs.exp (gcc-set-multilib-library-path):
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" }
+}