public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r10-10723] c++: assignment to temporary [PR59950]
Date: Thu, 12 May 2022 21:15:54 +0000 (GMT)	[thread overview]
Message-ID: <20220512211554.56969385041E@sourceware.org> (raw)

https://gcc.gnu.org/g:080e737a851d57697d0aac55749296c5c454c421

commit r10-10723-g080e737a851d57697d0aac55749296c5c454c421
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                       | 7 +++++--
 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 49eb673ebcc..5a4f93527bd 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -9081,8 +9081,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 (input_location, 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()));


                 reply	other threads:[~2022-05-12 21:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220512211554.56969385041E@sourceware.org \
    --to=jason@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).