public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95148] New: -Wtype-limits always-false warning triggered despite comparison being avoided
@ 2020-05-15  9:25 eyalroz at technion dot ac.il
  2022-10-26  2:18 ` [Bug c++/95148] " egallager at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: eyalroz at technion dot ac.il @ 2020-05-15  9:25 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95148
           Summary: -Wtype-limits always-false warning triggered despite
                    comparison being avoided
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eyalroz at technion dot ac.il
  Target Milestone: ---

Consider the following program:

  #include <type_traits>

  int main() {
          unsigned x { 5 };
          return (std::is_signed<decltype(x)>::value and (x < 0)) ? 1 : 0;
  }

when compiling it with GCC versions 11.0 20200511, 10.1, 9.2.1, 8.3.0, I get
the warning:

  a.cpp:5:52: warning: comparison of unsigned expression < 0 is always false
[-Wtype-limits]

I should not be getting this warning, because when x is unsigned, the
comparison is never performed, due to the short-circuit semantics of `and`.
This can be easily determined by the compiler - and probably is. No less
importantly, the author of such a line in a program clearly specified his/her
intent here with this check. 

clang doesn't seem to issue a warn inf does come to pass.

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

end of thread, other threads:[~2022-10-26 19:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-15  9:25 [Bug c++/95148] New: -Wtype-limits always-false warning triggered despite comparison being avoided eyalroz at technion dot ac.il
2022-10-26  2:18 ` [Bug c++/95148] " egallager at gcc dot gnu.org
2022-10-26  8:47 ` vincent-gcc at vinc17 dot net
2022-10-26  9:49 ` redi at gcc dot gnu.org
2022-10-26 19:09 ` eyalroz1 at gmx dot com

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