public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/98947] New: Incorrect warning when using a ternary operator to select one of two volatile variables to write to
@ 2021-02-03  0:04 headch at gmail dot com
  2021-02-03  9:39 ` [Bug c++/98947] " marxin at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: headch at gmail dot com @ 2021-02-03  0:04 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98947
           Summary: Incorrect warning when using a ternary operator to
                    select one of two volatile variables to write to
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: headch at gmail dot com
  Target Milestone: ---

Using a ternary operator to select one of two variables of the same
volatile-qualified type and then writing into the selected variable yields a
warning in C++2a mode, which I believe either it should not or it is
incorrectly worded.

$ cat test.cpp
volatile int x, y;

void f(bool b) {
        (b ? x : y) = 27;
}

$ g++-10.2.0 -Wall -Wextra -std=c++2a -c test.cpp
test.cpp: In function ‘void f(bool)’:
test.cpp:4:14: warning: using value of simple assignment with
‘volatile’-qualified left operand is deprecated [-Wvolatile]
    4 |  (b ? x : y) = 27;
      |  ~~~~~~~~~~~~^~~~
test.cpp:4:14: warning: using value of simple assignment with
‘volatile’-qualified left operand is deprecated [-Wvolatile]

$ g++-10.2.0 --version
g++-10.2.0 (Gentoo 10.2.0-r5 p6) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I’m not sure whether this code is even deprecated or not. Either way, though,
the warning is wrong. I am not, as the warning claims, using the return value
of the assignment operator.

The roughly equivalent form “*(b ? &x : &y) = 27;” does not generate a warning.

The even more similar, and silly, “*&(b ? x : y) = 27;” also does not generate
a warning.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-04-09 22:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-03  0:04 [Bug c++/98947] New: Incorrect warning when using a ternary operator to select one of two volatile variables to write to 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
2021-04-09 22:35 ` mpolacek at gcc dot gnu.org

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).