From 45fe7947ed05c189b2010011593f9226326d06da Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 12 Oct 2009 00:39:04 -0400 Subject: [PATCH] re PR c++/37204 ([c++0x] reinterpret_cast(v) incorrectly yields an lvalue) PR c++/37204 * typeck.c (build_reinterpret_cast_1): Handle rvalue refs properly. From-SVN: r152661 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/typeck.c | 7 ++++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/rv-reinterpret.C | 11 +++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/rv-reinterpret.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 67a5deaa69e..d2a46b2b1b2 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2009-10-11 Jason Merrill + + PR c++/37204 + * typeck.c (build_reinterpret_cast_1): Handle rvalue refs + properly. + 2009-10-11 Richard Guenther * tree.c (cp_free_lang_data): Drop anonymous aggregate names. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 526e7066a60..3392fac68a9 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -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; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4865c0d1996..dad5cb4a919 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-10-11 Jason Merrill + + PR c++/37204 + * g++.dg/cpp0x/rv-reinterpret.C: New. + 2009-10-11 Jerry DeLisle 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 index 00000000000..5b6e4c3d126 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/rv-reinterpret.C @@ -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(x)); + return (x != 42); +}