From: jason Date: Thu, 3 Mar 2016 22:43:09 +0000 (+0000) Subject: PR c++/51406 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b0531ab4e2581d76137c956e486c3a4d2d75a223;p=thirdparty%2Fgcc.git PR c++/51406 * typeck.c (build_static_cast_1): Avoid folding back to lvalue. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@233946 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f2c9cd25c1bb..a7ae483c33d5 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2016-03-03 Jason Merrill + PR c++/51406 + * typeck.c (build_static_cast_1): Avoid folding back to lvalue. + PR c++/67364 * constexpr.c (cxx_eval_component_reference): Just return an empty CONSTRUCTOR for an empty class. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 51458798c5ba..20f0afc74d7a 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -6704,11 +6704,7 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p, tree lref = cp_build_reference_type (TREE_TYPE (type), false); result = (perform_direct_initialization_if_possible (lref, expr, c_cast_p, complain)); - result = cp_fold_convert (type, result); - /* Make sure we don't fold back down to a named rvalue reference, - because that would be an lvalue. */ - if (DECL_P (result)) - result = build1 (NON_LVALUE_EXPR, type, result); + result = build1 (NON_LVALUE_EXPR, type, result); return convert_from_reference (result); } else diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-cast5.C b/gcc/testsuite/g++.dg/cpp0x/rv-cast5.C new file mode 100644 index 000000000000..c2473e266b64 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/rv-cast5.C @@ -0,0 +1,12 @@ +// { dg-do compile { target c++11 } } + +template +struct hold { + T value; + constexpr T&& operator()() && { return static_cast(value); } +}; + +int main() +{ + hold{42}(); +}