public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Patrick Palka <ppalka@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c++: lvalueness of non-dependent assignment [PR114994]
Date: Fri, 10 May 2024 15:42:16 -0400	[thread overview]
Message-ID: <1954fac4-af79-459a-9554-94b778786e05@redhat.com> (raw)
In-Reply-To: <20240509202300.2742125-1-ppalka@redhat.com>

On 5/9/24 16:23, Patrick Palka wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look
> OK for trunk/14?  For trunk as a follow-up I can implement the
> mentionted representation change to use CALL_EXPR instead of
> MODOP_EXPR for a non-dependent simple assignment expression that
> resolved to an operator= overload.
> 
> -- >8 --
> 
> r14-4111 made us check non-dependent assignment expressions ahead of
> time, as well as give them a type.  Unlike for compound assignment
> expressions however, if a simple assignment resolves to an operator
> overload we still represent it as a (typed) MODOP_EXPR instead of a
> CALL_EXPR to the selected overload.  This, I reckoned, was just a
> pessimization (since we'll have to repeat overload resolution at
> instantiatiation time) but should be harmless.  (And it should be
> easily fixable by giving cp_build_modify_expr an 'overload' parameter).
> 
> But it breaks the below testcase ultimately because MODOP_EXPR (of
> non-reference type) is always treated as an lvalue according to
> lvalue_kind, which is incorrect for the MODOP_EXPR representing x=42.
> 
> We can fix this by representing such assignment expressions as CALL_EXPRs
> matching what that of compound assignments, but that turns out to
> require some tweaking of our -Wparentheses warning logic which seems
> unsuitable for backporting.
> 
> So this patch instead more conservatively fixes this by refining
> lvalue_kind to consider the type of a (simple) MODOP_EXPR as we
> already do for COND_EXPR.
> 
> 	PR c++/114994
> 
> gcc/cp/ChangeLog:
> 
> 	* tree.cc (lvalue_kind) <case MODOP_EXPR>: Consider the
> 	type of a simple assignment expression.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/template/non-dependent32.C: New test.
> ---
>   gcc/cp/tree.cc                                 |  7 +++++++
>   .../g++.dg/template/non-dependent32.C          | 18 ++++++++++++++++++
>   2 files changed, 25 insertions(+)
>   create mode 100644 gcc/testsuite/g++.dg/template/non-dependent32.C
> 
> diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
> index f1a23ffe817..0b97b789aab 100644
> --- a/gcc/cp/tree.cc
> +++ b/gcc/cp/tree.cc
> @@ -275,6 +275,13 @@ lvalue_kind (const_tree ref)
>         /* We expect to see unlowered MODOP_EXPRs only during
>   	 template processing.  */
>         gcc_assert (processing_template_decl);
> +      if (TREE_CODE (TREE_OPERAND (ref, 1)) == NOP_EXPR
> +	  && CLASS_TYPE_P (TREE_TYPE (TREE_OPERAND (ref, 0))))
> +	/* As in the COND_EXPR case, but for non-dependent assignment
> +	   expressions created by build_x_modify_expr.  */
> +	goto default_;

This seems overly specific, I'd think the same thing would apply to += 
and such?

Jason


  parent reply	other threads:[~2024-05-10 19:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-09 20:23 Patrick Palka
2024-05-09 20:29 ` Patrick Palka
2024-05-10 13:36   ` Patrick Palka
2024-05-10 19:42   ` Jason Merrill
2024-05-10 19:42 ` Jason Merrill [this message]
2024-05-12  0:46   ` Patrick Palka
2024-05-14 22:27     ` Jason Merrill

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=1954fac4-af79-459a-9554-94b778786e05@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=ppalka@redhat.com \
    /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).