OSDN Git Service

PR c++/11332
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 27 Jun 2003 16:24:49 +0000 (16:24 +0000)
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 27 Jun 2003 16:24:49 +0000 (16:24 +0000)
* typeck.c (build_static_cast): Avoid returning expressions with
reference type.

PR c++/11332
* g++.dg/expr/static_cast2.C: New test.

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

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/expr/static_cast2.C [new file with mode: 0644]

index 9a22768..d0ecbdb 100644 (file)
@@ -1,3 +1,9 @@
+2003-06-26  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/11332
+       * typeck.c (build_static_cast): Avoid returning expressions with
+       reference type.
+
 2003-06-26  Nathan Sidwell  <nathan@codesourcery.com>
 
        * call.c (build_op_delete_call): Use strip_array_call. Correct
index c84cc84..6c17089 100644 (file)
@@ -4814,7 +4814,7 @@ build_static_cast (tree type, tree expr)
      t.  */
   result = perform_direct_initialization_if_possible (type, expr);
   if (result)
-    return result;
+    return convert_from_reference (result);
   
   /* [expr.static.cast]
 
@@ -4848,8 +4848,9 @@ build_static_cast (tree type, tree expr)
       /* Convert from B* to D*.  */
       expr = build_base_path (MINUS_EXPR, build_address (expr), 
                              base, /*nonnull=*/false);
-      /* Convert the pointer to a reference.  */
-      return build_nop (type, expr);
+      /* Convert the pointer to a reference -- but then remember that
+        there are no expressions with reference type in C++.  */
+      return convert_from_reference (build_nop (type, expr));
     }
 
   /* [expr.static.cast]
index 51bed04..190e0ef 100644 (file)
@@ -1,3 +1,8 @@
+2003-06-26  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/11332
+       * g++.dg/expr/static_cast2.C: New test.
+
 2003-06-26  Roger Sayle  <roger@eyesopen.com>
            Jakub Jelinek  <jakub@redhat.com>
 
diff --git a/gcc/testsuite/g++.dg/expr/static_cast2.C b/gcc/testsuite/g++.dg/expr/static_cast2.C
new file mode 100644 (file)
index 0000000..7b5d46d
--- /dev/null
@@ -0,0 +1,7 @@
+struct B {};
+
+int main () {
+  B a;
+  (1 ? static_cast<B&>(a) :
+       *static_cast<B*>(&a));
+}