public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97544] New: -Wtype-limits triggered for comparison to template argument
@ 2020-10-23 14:05 erenon2 at gmail dot com
  2020-10-23 14:10 ` [Bug c++/97544] " jakub at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: erenon2 at gmail dot com @ 2020-10-23 14:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97544
           Summary: -Wtype-limits triggered for comparison to template
                    argument
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: erenon2 at gmail dot com
  Target Milestone: ---

The following code triggers -Wtype-limits:

template <unsigned N>
constexpr int f(unsigned i)
{
  return (i < N) ? 0 : 1;
}

int main()
{
  return f<0>(1);
}

On GCC 10.2 and trunk, it produces this warning:

<source>: In instantiation of 'constexpr int f(unsigned int) [with unsigned int
N = 0]':
<source>:4:13: warning: comparison of unsigned expression in '< 0' is always
false [-Wtype-limits]

    4 |   return (i < N) ? 0 : 1;

      |          ~~~^~~~

On GCC 10.1, there's no warning.
godbolt: https://gcc.godbolt.org/z/cqzq8P

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

end of thread, other threads:[~2020-10-23 15:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-23 14:05 [Bug c++/97544] New: -Wtype-limits triggered for comparison to template argument erenon2 at gmail dot com
2020-10-23 14:10 ` [Bug c++/97544] " jakub at gcc dot gnu.org
2020-10-23 14:19 ` redi at gcc dot gnu.org
2020-10-23 14:21 ` mpolacek at gcc dot gnu.org
2020-10-23 15:07 ` erenon2 at gmail dot com
2020-10-23 15:12 ` mpolacek 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).