public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "eyalroz1 at gmx dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/95148] -Wtype-limits always-false warning triggered despite comparison being avoided
Date: Wed, 26 Oct 2022 19:09:29 +0000	[thread overview]
Message-ID: <bug-95148-4-5pDSReTN8X@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-95148-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #4 from Eyal Rozenberg <eyalroz1 at gmx dot com> ---
(In reply to Jonathan Wakely from comment #3)

> > 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`.
> 
> Those semantics only apply at runtime.

But the semantics are known at compile time, and so are the argument values.

> > No less
> > importantly, the author of such a line in a program clearly specified
> > his/her intent here with this check. 
> 
> But `x && y` doesn't prevent y being instantiated, it only prevents it being
> evaluated at runtime.

You mean, it only prevents a comparison of an unsigned and signed values to
actually ever being carried out? Yeah :-)


> >   a.cpp:5:52: warning: comparison of unsigned expression < 0 is always false
> > [-Wtype-limits]
> 
> Both branches of the condition must be instantiated by the compiler, and so
> this warning (which happens in the front-end, not after optimizing the AST)
> gets triggered.

Well, that's a bug. If you're saying that the front-end produces the warning,
then delay it to a later stage, in which you can figure out whether the warning
is called for. 

clang doesn't produce this warning.

> I think to avoid this warning the front end would have to disable this
> particular warning for branches that depend on a compile-time constant. I
> don't know if that's currently possible in GCC.

Ok, I didn't say that the solution would be easy...

      parent reply	other threads:[~2022-10-26 19:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-15  9:25 [Bug c++/95148] New: " 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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-95148-4-5pDSReTN8X@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).