re PR c++/58714 (Bogus overload resolution for the assignment operator in assignment...
authorJason Merrill <jason@redhat.com>
Fri, 9 May 2014 18:16:05 +0000 (14:16 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 9 May 2014 18:16:05 +0000 (14:16 -0400)
PR c++/58714
* tree.c (stabilize_expr): A stabilized prvalue is an xvalue.

From-SVN: r210283

gcc/cp/ChangeLog
gcc/cp/tree.c
gcc/testsuite/g++.dg/cpp0x/rv-cond1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/expr/cond12.C [new file with mode: 0644]

index 6bddd49..b13bd99 100644 (file)
@@ -1,5 +1,8 @@
 2014-05-09  Jason Merrill  <jason@redhat.com>
 
+       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".
index e140024..229d476 100644 (file)
@@ -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 (file)
index 0000000..a8f598f
--- /dev/null
@@ -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 (file)
index 0000000..9134f81
--- /dev/null
@@ -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();
+}