OSDN Git Service

/cp
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 3 Jan 2012 15:29:42 +0000 (15:29 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 3 Jan 2012 15:29:42 +0000 (15:29 +0000)
2012-01-03  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/29273
* rtti.c (build_dynamic_cast_1): In case of T a pointer type,
call decay_conversion on v.

/testsuite
2012-01-03  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/29273
* g++.dg/rtti/dyncast5.C: New.

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

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

index 4f6faf5..a5387da 100644 (file)
@@ -1,5 +1,11 @@
 2012-01-03  Paolo Carlini  <paolo.carlini@oracle.com>
 
 2012-01-03  Paolo Carlini  <paolo.carlini@oracle.com>
 
+       PR c++/29273
+       * rtti.c (build_dynamic_cast_1): In case of T a pointer type,
+       call decay_conversion on v.
+
+2012-01-03  Paolo Carlini  <paolo.carlini@oracle.com>
+
        PR c++/15867
        * decl.c (duplicate_decls): With -Wredundant-decls don't warn for
        declaration followed by specialization.
        PR c++/15867
        * decl.c (duplicate_decls): With -Wredundant-decls don't warn for
        declaration followed by specialization.
index 4494fdd..30383ed 100644 (file)
@@ -515,7 +515,7 @@ static tree
 build_dynamic_cast_1 (tree type, tree expr, tsubst_flags_t complain)
 {
   enum tree_code tc = TREE_CODE (type);
 build_dynamic_cast_1 (tree type, tree expr, tsubst_flags_t complain)
 {
   enum tree_code tc = TREE_CODE (type);
-  tree exprtype = TREE_TYPE (expr);
+  tree exprtype;
   tree dcast_fn;
   tree old_expr = expr;
   const char *errstr = NULL;
   tree dcast_fn;
   tree old_expr = expr;
   const char *errstr = NULL;
@@ -551,6 +551,9 @@ build_dynamic_cast_1 (tree type, tree expr, tsubst_flags_t complain)
 
   if (tc == POINTER_TYPE)
     {
 
   if (tc == POINTER_TYPE)
     {
+      expr = decay_conversion (expr);
+      exprtype = TREE_TYPE (expr);
+
       /* If T is a pointer type, v shall be an rvalue of a pointer to
         complete class type, and the result is an rvalue of type T.  */
 
       /* If T is a pointer type, v shall be an rvalue of a pointer to
         complete class type, and the result is an rvalue of type T.  */
 
@@ -576,7 +579,7 @@ build_dynamic_cast_1 (tree type, tree expr, tsubst_flags_t complain)
     {
       expr = mark_lvalue_use (expr);
 
     {
       expr = mark_lvalue_use (expr);
 
-      exprtype = build_reference_type (exprtype);
+      exprtype = build_reference_type (TREE_TYPE (expr));
 
       /* 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.  */
 
       /* 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.  */
@@ -764,7 +767,7 @@ build_dynamic_cast_1 (tree type, tree expr, tsubst_flags_t complain)
  fail:
   if (complain & tf_error)
     error ("cannot dynamic_cast %qE (of type %q#T) to type %q#T (%s)",
  fail:
   if (complain & tf_error)
     error ("cannot dynamic_cast %qE (of type %q#T) to type %q#T (%s)",
-           expr, exprtype, type, errstr);
+           old_expr, TREE_TYPE (old_expr), type, errstr);
   return error_mark_node;
 }
 
   return error_mark_node;
 }
 
index 6b7808a..f7ffe36 100644 (file)
@@ -1,3 +1,8 @@
+2012-01-03  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/29273
+       * g++.dg/rtti/dyncast5.C: New.
+
 2012-01-03  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/51070
 2012-01-03  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/51070
diff --git a/gcc/testsuite/g++.dg/rtti/dyncast5.C b/gcc/testsuite/g++.dg/rtti/dyncast5.C
new file mode 100644 (file)
index 0000000..d0d58d0
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/29273
+
+struct A { virtual ~A () { } };
+struct B: A { } b [1];
+
+void foo ()
+{
+  dynamic_cast<B*>(b);
+}