diff options
author | Jason Merrill <jason@redhat.com> | 2022-01-24 00:01:40 -0500 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2022-05-13 13:39:30 -0400 |
commit | 3daf541e8fe2dd0807a3dd49a9b8c065d7d46731 (patch) | |
tree | efcf48273061037cba5dd0c05ac44d958388ba23 | |
parent | 623842bead8452c03f2b1c6817f2a86a1d2d4d12 (diff) |
c++: assignment to temporary [PR59950]
Given build_this of a TARGET_EXPR, cp_build_fold_indirect_ref returns the
TARGET_EXPR. But that's the wrong value category for the result of the
defaulted class assignment operator, which returns an lvalue, so we need to
actually build the INDIRECT_REF.
PR c++/59950
gcc/cp/ChangeLog:
* call.c (build_over_call): Use cp_build_indirect_ref.
gcc/testsuite/ChangeLog:
* g++.dg/init/assign2.C: New test.
-rw-r--r-- | gcc/cp/call.c | 7 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/init/assign2.C | 6 |
2 files changed, 11 insertions, 2 deletions
diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 1110e49c62c..65fbff3b893 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -8662,8 +8662,11 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) && DECL_OVERLOADED_OPERATOR_IS (fn, NOP_EXPR) && trivial_fn_p (fn)) { - tree to = cp_stabilize_reference - (cp_build_fold_indirect_ref (argarray[0])); + /* Don't use cp_build_fold_indirect_ref, op= returns an lvalue even if + the object argument isn't one. */ + tree to = cp_build_indirect_ref (argarray[0], + RO_ARROW, complain); + to = cp_stabilize_reference (to); tree type = TREE_TYPE (to); tree as_base = CLASSTYPE_AS_BASE (type); tree arg = argarray[1]; diff --git a/gcc/testsuite/g++.dg/init/assign2.C b/gcc/testsuite/g++.dg/init/assign2.C new file mode 100644 index 00000000000..72d1264f3c9 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/assign2.C @@ -0,0 +1,6 @@ +// PR c++/59950 + + struct Foo {}; + + int f(Foo *p); + int n = f(&(Foo() = Foo())); |