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.

Reply via email to