From fc2bfea1399d51ab99516266948a40de92b14a0c Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Fri, 9 May 2014 14:16:05 -0400 Subject: [PATCH] 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: r210283 --- gcc/cp/ChangeLog | 3 +++ gcc/cp/tree.c | 4 ++++ gcc/testsuite/g++.dg/cpp0x/rv-cond1.C | 13 +++++++++++++ gcc/testsuite/g++.dg/expr/cond12.C | 12 ++++++++++++ 4 files changed, 32 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/rv-cond1.C create mode 100644 gcc/testsuite/g++.dg/expr/cond12.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6bddd4974f0a..b13bd99a0614 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2014-05-09 Jason Merrill + PR c++/58714 + * tree.c (stabilize_expr): A stabilized prvalue is an xvalue. + PR c++/54348 * call.c (build_conditional_expr_1): If overload resolution finds no match, just say "different types". diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index e14002482be3..229d47620d60 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -3785,6 +3785,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(); +} -- 2.47.2