public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-9681] c++: assignment to temporary [PR59950]
@ 2022-03-22  5:18 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2022-03-22  5:18 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:cb123480984d49c6a6e81b026633fc8ffff7883e

commit r11-9681-gcb123480984d49c6a6e81b026633fc8ffff7883e
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Jan 24 00:01:40 2022 -0500

    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.

Diff:
---
 gcc/cp/call.c                       | 5 ++++-
 gcc/testsuite/g++.dg/init/assign2.C | 6 ++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 2280fde1926..5e5bc97f63b 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -9456,7 +9456,10 @@ 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_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 (input_location, argarray[0],
+				       RO_ARROW, complain);
       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()));


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-03-22  5:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-22  5:18 [gcc r11-9681] c++: assignment to temporary [PR59950] Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).