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

* [Bug c++/97544] -Wtype-limits triggered for comparison to template argument
  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 ` jakub at gcc dot gnu.org
  2020-10-23 14:19 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-10-23 14:10 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Why do you think the warning is wrong?

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

* [Bug c++/97544] -Wtype-limits triggered for comparison to template argument
  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
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2020-10-23 14:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It's right, but it's not helpful. There are other instantiations of the
template where the condition isn't always true, and users shouldn't have to
write the condition as (N != 0 && i < N) just to silence this warning.

G++ used to have loads of these warnings in templates, and most of them have
been suppressed because we've usually decided that it's not helpful to warn
about template code where some instantiations result in "always true"
comparisons.

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

* [Bug c++/97544] -Wtype-limits triggered for comparison to template argument
  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
  4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-10-23 14:21 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
So it's probably a dup of my bug 96742.

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

* [Bug c++/97544] -Wtype-limits triggered for comparison to template argument
  2020-10-23 14:05 [Bug c++/97544] New: -Wtype-limits triggered for comparison to template argument erenon2 at gmail dot com
                   ` (2 preceding siblings ...)
  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
  4 siblings, 0 replies; 6+ messages in thread
From: erenon2 at gmail dot com @ 2020-10-23 15:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Benedek Thaler <erenon2 at gmail dot com> ---
FTR, Using (N != 0 && i < N) does not silence the warning.
https://gcc.godbolt.org/z/WqaT3G

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

* [Bug c++/97544] -Wtype-limits triggered for comparison to template argument
  2020-10-23 14:05 [Bug c++/97544] New: -Wtype-limits triggered for comparison to template argument erenon2 at gmail dot com
                   ` (3 preceding siblings ...)
  2020-10-23 15:07 ` erenon2 at gmail dot com
@ 2020-10-23 15:12 ` mpolacek at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-10-23 15:12 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Sorry, I'll make sure the warning is suppressed in this case.

*** This bug has been marked as a duplicate of bug 96742 ***

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