From: Jason Merrill Date: Mon, 12 Oct 2009 04:39:04 +0000 (-0400) Subject: re PR c++/37204 ([c++0x] reinterpret_cast(v) incorrectly yields an lvalue) X-Git-Tag: releases/gcc-4.5.0~2965 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=45fe7947ed05c189b2010011593f9226326d06da;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 67a5deaa69ec..d2a46b2b1b27 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 526e7066a60c..3392fac68a93 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 4865c0d19963..dad5cb4a9191 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 000000000000..5b6e4c3d126a --- /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); +}