]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/37204 ([c++0x] reinterpret_cast<T&&>(v) incorrectly yields an lvalue)
authorJason Merrill <jason@redhat.com>
Mon, 12 Oct 2009 04:39:04 +0000 (00:39 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 12 Oct 2009 04:39:04 +0000 (00:39 -0400)
PR c++/37204
* typeck.c (build_reinterpret_cast_1): Handle rvalue refs
properly.

From-SVN: r152661

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/rv-reinterpret.C [new file with mode: 0644]

index 67a5deaa69ec29408bcef862cd8a5a1097e366b3..d2a46b2b1b27a9fac091934dc68361cec781f29b 100644 (file)
@@ -1,3 +1,9 @@
+2009-10-11  Jason Merrill  <jason@redhat.com>
+
+       PR c++/37204
+       * typeck.c (build_reinterpret_cast_1): Handle rvalue refs
+       properly.
+
 2009-10-11  Richard Guenther  <rguenther@suse.de>
 
        * tree.c (cp_free_lang_data): Drop anonymous aggregate names.
index 526e7066a60c0e07c7fc3b81ac1240207f6189a6..3392fac68a9314bee56796f8b8f3864d26c4df88 100644 (file)
@@ -5599,12 +5599,17 @@ build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p,
                 intype, type);
 
       expr = cp_build_unary_op (ADDR_EXPR, expr, 0, complain);
+
+      if (warn_strict_aliasing > 2)
+       strict_aliasing_warning (TREE_TYPE (expr), type, expr);
+
       if (expr != error_mark_node)
        expr = build_reinterpret_cast_1
          (build_pointer_type (TREE_TYPE (type)), expr, c_cast_p,
           valid_p, complain);
       if (expr != error_mark_node)
-       expr = cp_build_indirect_ref (expr, 0, complain);
+       /* cp_build_indirect_ref isn't right for rvalue refs.  */
+       expr = convert_from_reference (fold_convert (type, expr));
       return expr;
     }
 
index 4865c0d19963ed1b632815ff8891c37c5615b09d..dad5cb4a91914e60617c67bfc2aa4fdcf4e97ac6 100644 (file)
@@ -1,3 +1,8 @@
+2009-10-11  Jason Merrill  <jason@redhat.com>
+
+       PR c++/37204
+       * g++.dg/cpp0x/rv-reinterpret.C: New.
+
 2009-10-11  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        PR libgfortran/38439
diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-reinterpret.C b/gcc/testsuite/g++.dg/cpp0x/rv-reinterpret.C
new file mode 100644 (file)
index 0000000..5b6e4c3
--- /dev/null
@@ -0,0 +1,11 @@
+// { dg-options -std=c++0x }
+// { dg-do run }
+
+void f(int &);
+void f(int &&ir) { ir = 42; }
+int main()
+{
+  int x;
+  f(reinterpret_cast<int&&>(x));
+  return (x != 42);
+}