public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/98947] [10 Regression] Incorrect warning when using a ternary operator to select one of two volatile variables to write to
Date: Fri, 09 Apr 2021 22:35:06 +0000	[thread overview]
Message-ID: <bug-98947-4-41EHay0vn7@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-98947-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98947

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:

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

commit r10-9684-gf0f62557c3de0313673d7c0527277e86231ee95b
Author: Marek Polacek <polacek@redhat.com>
Date:   Wed Feb 3 17:57:22 2021 -0500

    c++: Fix bogus -Wvolatile warning in C++20 [PR98947]

    Since most of volatile is deprecated in C++20, we are required to warn
    for compound assignments to volatile variables and so on.  But here we
    have

      volatile int x, y, z;
      (b ? x : y) = 1;

    and we shouldn't warn, because simple assignments like x = 24; should
    not provoke the warning when they are a discarded-value expression.

    We warn here because when ?: is used as an lvalue, we transform it in
    cp_build_modify_expr/COND_EXPR from (a ? b : c) = rhs to

      (a ? (b = rhs) : (c = rhs))

    and build_conditional_expr then calls mark_lvalue_use for the new
    artificial assignments, which then evokes the warning.  The calls
    to mark_lvalue_use were added in r160289 to suppress warnings in
    Wunused-var-10.c, but looks like they're no longer needed.

    To warn on

        (b ? (x = 2) : y) = 1;
        (b ? x : (y = 5)) = 1;

    I've tweaked a check in mark_use/MODIFY_EXPR.

    I'd argue this is a regression because GCC 9 doesn't warn.

    gcc/cp/ChangeLog:

            PR c++/98947
            * call.c (build_conditional_expr_1): Don't call mark_lvalue_use
            on arg2/arg3.
            * expr.c (mark_use) <case MODIFY_EXPR>: Don't check read_p when
            issuing the -Wvolatile warning.  Only set TREE_THIS_VOLATILE if
            a warning was emitted.

    gcc/testsuite/ChangeLog:

            PR c++/98947
            * g++.dg/cpp2a/volatile5.C: New test.

    (cherry picked from commit 7a18bc4ae62081021f4fd90d591a588cac931f77)

  parent reply	other threads:[~2021-04-09 22:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-03  0:04 [Bug c++/98947] New: " headch at gmail dot com
2021-02-03  9:39 ` [Bug c++/98947] " marxin at gcc dot gnu.org
2021-02-03 15:24 ` mpolacek at gcc dot gnu.org
2021-02-03 22:49 ` [Bug c++/98947] [10/11 Regression] " mpolacek at gcc dot gnu.org
2021-02-05 16:11 ` cvs-commit at gcc dot gnu.org
2021-02-05 16:12 ` [Bug c++/98947] [10 " mpolacek at gcc dot gnu.org
2021-04-08 12:02 ` rguenth at gcc dot gnu.org
2021-04-09 22:35 ` cvs-commit at gcc dot gnu.org [this message]
2021-04-09 22:35 ` mpolacek at gcc dot gnu.org

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=bug-98947-4-41EHay0vn7@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).