public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/55986] New: RHS of logical operators may render LHS unevaluated in constant-expression
@ 2013-01-15 4:41 potswa at mac dot com
2013-01-15 4:48 ` [Bug c++/55986] " potswa at mac dot com
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: potswa at mac dot com @ 2013-01-15 4:41 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55986
Bug #: 55986
Summary: RHS of logical operators may render LHS unevaluated in
constant-expression
Classification: Unclassified
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: potswa@mac.com
This compiles without incident, despite using a non-constant object in a
constant-expression:
int i;
static_assert( i || true, "" );
static_assert( ! ( i && false ), "" );
It appears to be assuming that || and && are commutative, but short-circuiting
only works in one direction.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/55986] RHS of logical operators may render LHS unevaluated in constant-expression
2013-01-15 4:41 [Bug c++/55986] New: RHS of logical operators may render LHS unevaluated in constant-expression potswa at mac dot com
@ 2013-01-15 4:48 ` potswa at mac dot com
2013-01-15 4:49 ` potswa at mac dot com
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: potswa at mac dot com @ 2013-01-15 4:48 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55986
--- Comment #1 from David Krauss <potswa at mac dot com> 2013-01-15 04:47:53 UTC ---
Passing `-O2` additionally causes it to skip a condition like `(i == 0 || i !=
0)`, so it looks like a general issue with expression simplification bypassing
ODR-use.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/55986] RHS of logical operators may render LHS unevaluated in constant-expression
2013-01-15 4:41 [Bug c++/55986] New: RHS of logical operators may render LHS unevaluated in constant-expression potswa at mac dot com
2013-01-15 4:48 ` [Bug c++/55986] " potswa at mac dot com
@ 2013-01-15 4:49 ` potswa at mac dot com
2013-01-15 8:03 ` potswa at mac dot com
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: potswa at mac dot com @ 2013-01-15 4:49 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55986
--- Comment #2 from David Krauss <potswa at mac dot com> 2013-01-15 04:48:47 UTC ---
Passing `-O2` additionally causes it to skip a condition like `(i == 0 || i !=
0)`, so it looks like a general issue with expression simplification bypassing
use.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/55986] RHS of logical operators may render LHS unevaluated in constant-expression
2013-01-15 4:41 [Bug c++/55986] New: RHS of logical operators may render LHS unevaluated in constant-expression potswa at mac dot com
2013-01-15 4:48 ` [Bug c++/55986] " potswa at mac dot com
2013-01-15 4:49 ` potswa at mac dot com
@ 2013-01-15 8:03 ` potswa at mac dot com
2015-07-29 18:57 ` yaghmour.shafik at gmail dot com
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: potswa at mac dot com @ 2013-01-15 8:03 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55986
--- Comment #3 from David Krauss <potswa at mac dot com> 2013-01-15 08:02:55 UTC ---
Likewise this is allowed:
switch( 0 )
case i-i: ;
I think this is a purposeful language extension, which could use a switch to
disable. It would be nice if static_assert were always strict.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/55986] RHS of logical operators may render LHS unevaluated in constant-expression
2013-01-15 4:41 [Bug c++/55986] New: RHS of logical operators may render LHS unevaluated in constant-expression potswa at mac dot com
` (2 preceding siblings ...)
2013-01-15 8:03 ` potswa at mac dot com
@ 2015-07-29 18:57 ` yaghmour.shafik at gmail dot com
2015-10-21 15:28 ` yaghmour.shafik at gmail dot com
2021-07-28 4:07 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: yaghmour.shafik at gmail dot com @ 2015-07-29 18:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55986
Shafik Yaghmour <yaghmour.shafik at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |yaghmour.shafik at gmail dot com
--- Comment #4 from Shafik Yaghmour <yaghmour.shafik at gmail dot com> ---
This issue showed up recently in this Stackoverflow question:
http://stackoverflow.com/q/31526278/1708801
As far as I can tell there should at least be a diagnostic when using -pedantic
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/55986] RHS of logical operators may render LHS unevaluated in constant-expression
2013-01-15 4:41 [Bug c++/55986] New: RHS of logical operators may render LHS unevaluated in constant-expression potswa at mac dot com
` (3 preceding siblings ...)
2015-07-29 18:57 ` yaghmour.shafik at gmail dot com
@ 2015-10-21 15:28 ` yaghmour.shafik at gmail dot com
2021-07-28 4:07 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: yaghmour.shafik at gmail dot com @ 2015-10-21 15:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55986
--- Comment #5 from Shafik Yaghmour <yaghmour.shafik at gmail dot com> ---
It looks like this case from this Stackoverflow question
http://stackoverflow.com/q/32920229/1708801 is possibly related:
int main(int argc, char**)
{
constexpr int a = argc * 0;
}
gcc treats `argc * 0` as a constant expression a comment indicates this is due
to constant folding and it seems possible that gcc is constant folding `i ||
true` as well.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/55986] RHS of logical operators may render LHS unevaluated in constant-expression
2013-01-15 4:41 [Bug c++/55986] New: RHS of logical operators may render LHS unevaluated in constant-expression potswa at mac dot com
` (4 preceding siblings ...)
2015-10-21 15:28 ` yaghmour.shafik at gmail dot com
@ 2021-07-28 4:07 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-28 4:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55986
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Keywords| |accepts-invalid
Target Milestone|--- |6.0
Status|UNCONFIRMED |RESOLVED
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed in GCC 6 with r6-4886 (note this is expected because we delay
simplifications until after semantics anlysis now).
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-07-28 4:07 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-15 4:41 [Bug c++/55986] New: RHS of logical operators may render LHS unevaluated in constant-expression potswa at mac dot com
2013-01-15 4:48 ` [Bug c++/55986] " potswa at mac dot com
2013-01-15 4:49 ` potswa at mac dot com
2013-01-15 8:03 ` potswa at mac dot com
2015-07-29 18:57 ` yaghmour.shafik at gmail dot com
2015-10-21 15:28 ` yaghmour.shafik at gmail dot com
2021-07-28 4:07 ` pinskia 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).