From: Jason Merrill Date: Thu, 7 Aug 2014 19:50:04 +0000 (-0400) Subject: re PR c++/58714 (Bogus overload resolution for the assignment operator in assignment... X-Git-Tag: releases/gcc-4.8.4~307 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=376f66e7dca47e003efcbd8394aee099d9ad22aa;p=thirdparty%2Fgcc.git re PR c++/58714 (Bogus overload resolution for the assignment operator in assignment to a conditional) PR c++/58714 * tree.c (stabilize_expr): A stabilized prvalue is an xvalue. From-SVN: r213734 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4b87bf50cc51..b0e1efd19732 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2014-08-07 Jason Merrill + + PR c++/58714 + * tree.c (stabilize_expr): A stabilized prvalue is an xvalue. + 2014-01-27 Jason Merrill PR c++/59823 diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index ed4bff6c5aa3..a9ff1c163506 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -3748,6 +3748,10 @@ stabilize_expr (tree exp, tree* initp) { init_expr = get_target_expr (exp); exp = TARGET_EXPR_SLOT (init_expr); + if (CLASS_TYPE_P (TREE_TYPE (exp))) + exp = move (exp); + else + exp = rvalue (exp); } else { diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-cond1.C b/gcc/testsuite/g++.dg/cpp0x/rv-cond1.C new file mode 100644 index 000000000000..a8f598f17d46 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/rv-cond1.C @@ -0,0 +1,13 @@ +// PR c++/58714 +// { dg-do compile { target c++11 } } + +struct X { + X& operator=(const X&) = delete; + X& operator=(X&& ) = default; +}; + +void f(bool t) { + X a, b; + *(t ? &a : &b) = X(); + (t ? a : b) = X(); +} diff --git a/gcc/testsuite/g++.dg/expr/cond12.C b/gcc/testsuite/g++.dg/expr/cond12.C new file mode 100644 index 000000000000..9134f81668ff --- /dev/null +++ b/gcc/testsuite/g++.dg/expr/cond12.C @@ -0,0 +1,12 @@ +// PR c++/58714 +// { dg-do run } + +struct X { + X& operator=(const X&){} + X& operator=(X&){__builtin_abort();} +}; + +int main(int argv,char**) { + X a, b; + ((argv > 2) ? a : b) = X(); +}