* [Bug c++/98947] Incorrect warning when using a ternary operator to select one of two volatile variables to write to
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 ` marxin at gcc dot gnu.org
2021-02-03 15:24 ` mpolacek at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-02-03 9:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98947
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2021-02-03
CC| |marxin at gcc dot gnu.org,
| |mpolacek at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Can you take a look Marek?
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/98947] Incorrect warning when using a ternary operator to select one of two volatile variables to write to
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
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-02-03 15:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98947
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/98947] [10/11 Regression] Incorrect warning when using a ternary operator to select one of two volatile variables to write to
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 ` mpolacek at gcc dot gnu.org
2021-02-05 16:11 ` cvs-commit at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-02-03 22:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98947
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|Incorrect warning when |[10/11 Regression]
|using a ternary operator to |Incorrect warning when
|select one of two volatile |using a ternary operator to
|variables to write to |select one of two volatile
| |variables to write to
Priority|P3 |P2
Target Milestone|--- |10.3
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I think warning on
(b ? x : y) = 27;
is bogus, therefore I'd argue that this is a regression; gcc 9 didn't issue any
warnings with -std=c++2a.
I have a patch. Of course, we should still warn for
(b ? x : y) += 27;
(b ? (x = 24) : y) = 25;
etc.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/98947] [10/11 Regression] Incorrect warning when using a ternary operator to select one of two volatile variables to write to
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
` (2 preceding siblings ...)
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
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-02-05 16:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98947
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:7a18bc4ae62081021f4fd90d591a588cac931f77
commit r11-7126-g7a18bc4ae62081021f4fd90d591a588cac931f77
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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/98947] [10 Regression] Incorrect warning when using a ternary operator to select one of two volatile variables to write to
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
` (3 preceding siblings ...)
2021-02-05 16:11 ` cvs-commit at gcc dot gnu.org
@ 2021-02-05 16:12 ` mpolacek at gcc dot gnu.org
2021-04-08 12:02 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-02-05 16:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98947
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[10/11 Regression] |[10 Regression] Incorrect
|Incorrect warning when |warning when using a
|using a ternary operator to |ternary operator to select
|select one of two volatile |one of two volatile
|variables to write to |variables to write to
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed on trunk so far.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/98947] [10 Regression] Incorrect warning when using a ternary operator to select one of two volatile variables to write to
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
` (4 preceding siblings ...)
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
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-04-08 12:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98947
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|10.3 |10.4
--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 10.3 is being released, retargeting bugs to GCC 10.4.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/98947] [10 Regression] Incorrect warning when using a ternary operator to select one of two volatile variables to write to
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
` (5 preceding siblings ...)
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
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-04-09 22:35 UTC (permalink / raw)
To: gcc-bugs
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)
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/98947] [10 Regression] Incorrect warning when using a ternary operator to select one of two volatile variables to write to
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
` (6 preceding siblings ...)
2021-04-09 22:35 ` cvs-commit at gcc dot gnu.org
@ 2021-04-09 22:35 ` mpolacek at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-04-09 22:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98947
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed in GCC 10.4 too.
^ permalink raw reply [flat|nested] 9+ messages in thread