From: Jason Merrill <jason@redhat.com>
To: Patrick Palka <ppalka@redhat.com>, gcc-patches@gcc.gnu.org
Cc: libstdc++@gcc.gnu.org
Subject: Re: [PATCH] c++: non-dependent assignment checking [PR63198, PR18474]
Date: Sun, 17 Sep 2023 23:01:29 -0400 [thread overview]
Message-ID: <13272bff-9f95-4dfd-d724-ff67cc568532@redhat.com> (raw)
In-Reply-To: <20230917185140.1333132-1-ppalka@redhat.com>
On 9/17/23 14:51, Patrick Palka wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk? Patch generatde with -w to avoid noisy whitespace changes.
>
> -- >8 --
>
> This patch makes us recognize and check non-dependent simple assigments
> ahead of time, like we already do for compound assignments. This means
> the templated representation of such assignments will now usually have
> an implicit INDIRECT_REF (due to the reference return type), which the
> -Wparentheses code needs to handle. As a drive-by improvement, this
> patch also makes maybe_convert_cond issue -Wparentheses warnings ahead
> of time.
>
> This revealed some libstdc++ tests were attempting to modify a data
> member from a uninstantiated const member function; naively fixed by
> making the data member mutable.
>
> PR c++/63198
> PR c++/18474
>
> gcc/cp/ChangeLog:
>
> * semantics.cc (maybe_convert_cond): Look through implicit
> INDIRECT_REF when deciding whether to issue a -Wparentheses
> warning, and consider templated assignment expressions as well.
> (finish_parenthesized_expr): Look through implicit INDIRECT_REF
> when suppressing -Wparentheses warning.
> * typeck.cc (build_x_modify_expr): Check simple assignments
> ahead time too, not just compound assignments. Give the second
> operand of MODOP_EXPR a non-null type so that it's not considered
> always instantiation-dependent.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/cpp0x/static_assert15.C: Expect diagnostic for
> non-constant static_assert condition.
> * g++.dg/expr/unary2.C: Remove xfails.
> * g++.dg/template/init7.C: Make initializer type-dependent to
> preserve intent of test.
> * g++.dg/template/recurse3.C: Likewise for the erroneous
> statement.
> * g++.dg/template/non-dependent26.C: New test.
> * g++.dg/warn/Wparentheses-32.C: New test.
>
> libstdc++/ChangeLog:
>
> * testsuite/26_numerics/random/discard_block_engine/cons/seed_seq2.cc:
> Make seed_seq::called member mutable.
> * testsuite/26_numerics/random/independent_bits_engine/cons/seed_seq2.cc:
> Likewise.
> * testsuite/26_numerics/random/linear_congruential_engine/cons/seed_seq2.cc
> Likewise.
> * testsuite/26_numerics/random/mersenne_twister_engine/cons/seed_seq2.cc:
> Likewise.
> * testsuite/26_numerics/random/shuffle_order_engine/cons/seed_seq2.cc:
> Likewise.
> * testsuite/26_numerics/random/subtract_with_carry_engine/cons/seed_seq2.cc:
> Likewise.
> * testsuite/ext/random/simd_fast_mersenne_twister_engine/cons/seed_seq2.cc
> Likewise.
> ---
> gcc/cp/semantics.cc | 17 +++++++----
> gcc/cp/typeck.cc | 23 +++++++--------
> gcc/testsuite/g++.dg/cpp0x/static_assert15.C | 2 +-
> gcc/testsuite/g++.dg/expr/unary2.C | 8 ++----
> gcc/testsuite/g++.dg/template/init7.C | 2 +-
> .../g++.dg/template/non-dependent26.C | 25 +++++++++++++++++
> gcc/testsuite/g++.dg/template/recurse3.C | 8 +++---
> gcc/testsuite/g++.dg/warn/Wparentheses-32.C | 28 +++++++++++++++++++
> .../discard_block_engine/cons/seed_seq2.cc | 2 +-
> .../independent_bits_engine/cons/seed_seq2.cc | 2 +-
> .../cons/seed_seq2.cc | 2 +-
> .../mersenne_twister_engine/cons/seed_seq2.cc | 2 +-
> .../shuffle_order_engine/cons/seed_seq2.cc | 2 +-
> .../cons/seed_seq2.cc | 2 +-
> .../cons/seed_seq2.cc | 2 +-
> 15 files changed, 91 insertions(+), 36 deletions(-)
> create mode 100644 gcc/testsuite/g++.dg/template/non-dependent26.C
> create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-32.C
>
> diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
> index 0f7f4e87ae4..b57c1ac868b 100644
> --- a/gcc/cp/semantics.cc
> +++ b/gcc/cp/semantics.cc
> diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
> index 459739d5866..74f5fced060 100644
> --- a/gcc/cp/typeck.cc
> +++ b/gcc/cp/typeck.cc
> @@ -9739,15 +9739,15 @@ build_x_modify_expr (location_t loc, tree lhs, enum tree_code modifycode,
> rhs = build_non_dependent_expr (rhs);
> }
>
> - if (modifycode != NOP_EXPR)
> - {
> - tree op = build_nt (modifycode, NULL_TREE, NULL_TREE);
> - tree rval = build_new_op (loc, MODIFY_EXPR, LOOKUP_NORMAL,
> + tree rval;
> + if (modifycode == NOP_EXPR)
> + rval = cp_build_modify_expr (loc, lhs, modifycode, rhs, complain);
> + else
> + rval = build_new_op (loc, MODIFY_EXPR, LOOKUP_NORMAL,
> lhs, rhs, op, lookups, &overload, complain);
> - if (rval)
> - {
> if (rval == error_mark_node)
> - return rval;
> + return error_mark_node;
> + if (modifycode != NOP_EXPR)
> suppress_warning (rval /* What warning? */);
Did you try disabling this to see if it's still needed?
Jason
next prev parent reply other threads:[~2023-09-18 3:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-17 18:51 Patrick Palka
2023-09-18 3:01 ` Jason Merrill [this message]
2023-09-18 13:12 ` Patrick Palka
2023-09-18 13:33 ` 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=13272bff-9f95-4dfd-d724-ff67cc568532@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@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).