public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/104486] New: if constexpr versus -Wtype-limits
@ 2022-02-10 14:35 drepper.fsp+rhbz at gmail dot com
2022-02-10 14:56 ` [Bug middle-end/104486] " redi at gcc dot gnu.org
2022-02-10 15:00 ` jakub at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: drepper.fsp+rhbz at gmail dot com @ 2022-02-10 14:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104486
Bug ID: 104486
Summary: if constexpr versus -Wtype-limits
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: drepper.fsp+rhbz at gmail dot com
Target Milestone: ---
One use of 'if constexpr' is to handle different type sizes. This is a simple
example:
#include <climits>
using some_type = int;
some_type f();
bool foo()
{
if constexpr (sizeof(some_type) == sizeof(int))
return f() == INT_MAX;
else if constexpr (sizeof(some_type) == sizeof(long))
return f() == LONG_MAX;
else
return f() == LONG_LONG_MAX;
}
Compiling this code with -Wtype-limits produces warnings:
g++ -std=gnu++20 -c u.cc -Wtype-limits
u.cc: In function ‘bool foo()’:
u.cc:12:16: warning: comparison is always false due to limited range of data
type [-Wtype-limits]
12 | return f() == LONG_MAX;
| ^
u.cc:14:16: warning: comparison is always false due to limited range of data
type [-Wtype-limits]
14 | return f() == LONG_LONG_MAX;
| ^
These statements are guarded by 'if constexpr' which causes the code in the
respective branch to not be active. The warnings should be disabled for those
code blocks. Again, the whole point of writing code like this is to avoid
overflow errors and the like.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug middle-end/104486] if constexpr versus -Wtype-limits
2022-02-10 14:35 [Bug middle-end/104486] New: if constexpr versus -Wtype-limits drepper.fsp+rhbz at gmail dot com
@ 2022-02-10 14:56 ` redi at gcc dot gnu.org
2022-02-10 15:00 ` jakub at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2022-02-10 14:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104486
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Last reconfirmed| |2022-02-10
Status|UNCONFIRMED |NEW
Keywords| |diagnostic
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug middle-end/104486] if constexpr versus -Wtype-limits
2022-02-10 14:35 [Bug middle-end/104486] New: if constexpr versus -Wtype-limits drepper.fsp+rhbz at gmail dot com
2022-02-10 14:56 ` [Bug middle-end/104486] " redi at gcc dot gnu.org
@ 2022-02-10 15:00 ` jakub at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-02-10 15:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104486
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org,
| |mpolacek at gcc dot gnu.org,
| |ppalka at gcc dot gnu.org
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Perhaps we should ignore the warning if in_discarded_stmt ?
Though it really matters where exactly the warning is reported, because
in_discarded_stmt isn't set when parsing a template with if constexpr in it
(after all, the condition might be dependent).
Other option would be to temporarily disable selected warnings around where we
set/restore in_discarded_stmt but also do it if processing_template_decl and
the condition isn't dependent and folds to false or true.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-02-10 15:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-10 14:35 [Bug middle-end/104486] New: if constexpr versus -Wtype-limits drepper.fsp+rhbz at gmail dot com
2022-02-10 14:56 ` [Bug middle-end/104486] " redi at gcc dot gnu.org
2022-02-10 15:00 ` jakub 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).