public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/11856] New: Wrong warning regarding assert
@ 2003-08-08 14:25 o dot kullmann at swansea dot ac dot uk
2003-08-08 14:36 ` [Bug c++/11856] " marcus at jet dot franken dot de
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: o dot kullmann at swansea dot ac dot uk @ 2003-08-08 14:25 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11856
Summary: Wrong warning regarding assert
Product: gcc
Version: 3.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: o dot kullmann at swansea dot ac dot uk
CC: gcc-bugs at gcc dot gnu dot org
<file AssertWarning.cpp>
----------------------------------------
#include <cassert>
void f(unsigned char c) {
assert(0 <= c and c <= 2);
}
int main() {
f(5);
}
----------------------------------------
yields:
> g++ AssertWarning.cpp
AssertWarning.cpp: In function `void f(unsigned char)':
AssertWarning.cpp:3: warning: comparison is always true due to limited range
of data type
which is wrong: Running it yields (as it should be):
> ./a.out
a.out: AssertWarning.cpp:3: void f(unsigned char): Assertion `0 <= c and c <=
2' failed.
Aborted.
Tested Versions: 3.3 and 3.2.1 (same behaviour).
(Platform: Linux (Suse 8.0))
I'm writing a generic library, and this warning shows up all over the
place, and since the warning messages typically are *very* long (due
to the deeply nested template names), the output of g++ is rendered
unreadable.
Since it doesn't seem to be possible to inhibit this warning message (!),
the only work around is to use
g++ -w
inhibiting *all* warnings.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/11856] Wrong warning regarding assert
2003-08-08 14:25 [Bug c++/11856] New: Wrong warning regarding assert o dot kullmann at swansea dot ac dot uk
@ 2003-08-08 14:36 ` marcus at jet dot franken dot de
2003-08-08 15:18 ` o dot kullmann at swansea dot ac dot uk
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: marcus at jet dot franken dot de @ 2003-08-08 14:36 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11856
------- Additional Comments From marcus at jet dot franken dot de 2003-08-08 14:36 -------
c<=0 is always true for unsigned characters, thats where the warning comes
from.
your code reduces to:
assert(c <= 2);
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/11856] Wrong warning regarding assert
2003-08-08 14:25 [Bug c++/11856] New: Wrong warning regarding assert o dot kullmann at swansea dot ac dot uk
2003-08-08 14:36 ` [Bug c++/11856] " marcus at jet dot franken dot de
@ 2003-08-08 15:18 ` o dot kullmann at swansea dot ac dot uk
2003-08-08 15:29 ` o dot kullmann at swansea dot ac dot uk
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: o dot kullmann at swansea dot ac dot uk @ 2003-08-08 15:18 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11856
------- Additional Comments From o dot kullmann at swansea dot ac dot uk 2003-08-08 15:17 -------
Subject: Re: Wrong warning regarding assert
On Fri, Aug 08, 2003 at 02:36:08PM -0000, marcus at jet dot franken dot de wrote:
> Date: 8 Aug 2003 14:36:08 -0000
> From: "marcus at jet dot franken dot de" <gcc-bugzilla@gcc.gnu.org>
> To: o.kullmann@swansea.ac.uk
> In-Reply-To: <20030808142556.11856.o.kullmann@swansea.ac.uk>
> Reply-To: gcc-bugzilla@gcc.gnu.org
> X-Bugzilla-Reason: Reporter
> X-SA-Exim-Mail-From: dberlin@gcc.gnu.org
> Subject: [Bug c++/11856] Wrong warning regarding assert
> X-Spam-Status: No, hits=-101.5 required=5.5
> tests=AWL,BAYES_30,IN_REP_TO,REFERENCES,USER_IN_WHITELIST
> version=2.55
> X-Spam-Level:
> X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp)
> X-SA-Exim-Version: 3.0 (built Sat May 17 23:48:01 PDT 2003)
> X-UIDL: !lB"!9IP"!iVl"!f/!"!
>
> PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11856
>
>
>
> ------- Additional Comments From marcus at jet dot franken dot de 2003-08-08 14:36 -------
> c>=0 is always true for unsigned characters, thats where the warning comes
> from.
>
> your code reduces to:
> assert(c <= 2);
>
>
I see; but the problem is that with generic code, where function f in fact is
a function template, the warning becomes a bad thing: The assertion c>=0
in general is necessary (for signed cases), but for all unsigned cases
we get a warning message (as I said, the typical monsters, pages and pages for
just one message).
My general observation is, that the warning system of g++ doesn't fit well with
generic programming, where all those trivial situations (which triggers a warning)
in fact often are essential.
So perhaps the solution is to inhibit all warnings. But intuitively this seems too
bold to me. I checked again the documentation of gcc/g++, but I couldn't find anything
to turn off the above assert warning. Perhaps for generic programming it would be a good
thing to be able to switch off all "triviality warnings".
Oliver
>
> ------- You are receiving this mail because: -------
> You reported the bug, or are watching the reporter.
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/11856] Wrong warning regarding assert
2003-08-08 14:25 [Bug c++/11856] New: Wrong warning regarding assert o dot kullmann at swansea dot ac dot uk
2003-08-08 14:36 ` [Bug c++/11856] " marcus at jet dot franken dot de
2003-08-08 15:18 ` o dot kullmann at swansea dot ac dot uk
@ 2003-08-08 15:29 ` o dot kullmann at swansea dot ac dot uk
2003-08-08 16:10 ` pinskia at gcc dot gnu dot org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: o dot kullmann at swansea dot ac dot uk @ 2003-08-08 15:29 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11856
------- Additional Comments From o dot kullmann at swansea dot ac dot uk 2003-08-08 15:29 -------
Subject: Re: Wrong warning regarding assert (addition)
> > ------- Additional Comments From marcus at jet dot franken dot de 2003-08-08 14:36 -------
> > c>=0 is always true for unsigned characters, thats where the warning comes
> > from.
> >
I'm sorry, but I missed the point:
In the gcc-info-documentation I have it says under option "-W":
`-W'
Print extra warning messages for these events:
* An unsigned value is compared against zero with `<' or `<='.
So I think the error here is that I get the *extra* warnings of "-W" without
specifying "-W".
Oliver
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/11856] Wrong warning regarding assert
2003-08-08 14:25 [Bug c++/11856] New: Wrong warning regarding assert o dot kullmann at swansea dot ac dot uk
` (2 preceding siblings ...)
2003-08-08 15:29 ` o dot kullmann at swansea dot ac dot uk
@ 2003-08-08 16:10 ` pinskia at gcc dot gnu dot org
2003-08-08 16:28 ` o dot kullmann at swansea dot ac dot uk
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-08-08 16:10 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11856
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-08-08 16:10 -------
With this code:
template <typename t>
void f(t c) {
assert(0 <= c and c <= 2);
}
int main() {
f<unsigned char>(5);
}
I only get a warning on instantiation.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/11856] Wrong warning regarding assert
2003-08-08 14:25 [Bug c++/11856] New: Wrong warning regarding assert o dot kullmann at swansea dot ac dot uk
` (3 preceding siblings ...)
2003-08-08 16:10 ` pinskia at gcc dot gnu dot org
@ 2003-08-08 16:28 ` o dot kullmann at swansea dot ac dot uk
2003-08-10 2:35 ` [Bug c++/11856] unsigned warning in template pinskia at gcc dot gnu dot org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: o dot kullmann at swansea dot ac dot uk @ 2003-08-08 16:28 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11856
------- Additional Comments From o dot kullmann at swansea dot ac dot uk 2003-08-08 16:28 -------
Subject: Re: Wrong warning regarding assert [Improved example]
> pinskia at gcc dot gnu dot org changed:
>
> What |Removed |Added
> ----------------------------------------------------------------------------
> Keywords| |diagnostic
>
>
> ------- Additional Comments From pinskia at gcc dot gnu dot org 2003-08-08 16:10 -------
> With this code:
> template <typename t>
> void f(t c) {
> assert(0 <= c and c <= 2);
> }
> int main() {
> f<unsigned char>(5);
> }
> I only get a warning on instantiation.
>
>
I see, I oversimplified the problem a bit. Here is a better example:
------------------------------
#include <cassert>
template <typename Int, Int D>
void f(Int x) {
assert(0 <= x and x <= D);
}
int main() {
f<unsigned char, 2>(5);
}
-----------------------------
> g++ AssertWarning.cpp
AssertWarning.cpp: In function `void f(Int) [with Int = unsigned char, Int D =
2]':
AssertWarning.cpp:7: instantiated from here
AssertWarning.cpp:4: warning: comparison is always true due to limited range of
data type
> ./a.out
a.out: AssertWarning.cpp:4: void f(Int) [with Int = unsigned char, Int D = 2]: Assertion `0 <= x and x <= D' failed.
Aborted.
Oliver
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/11856] unsigned warning in template
2003-08-08 14:25 [Bug c++/11856] New: Wrong warning regarding assert o dot kullmann at swansea dot ac dot uk
` (4 preceding siblings ...)
2003-08-08 16:28 ` o dot kullmann at swansea dot ac dot uk
@ 2003-08-10 2:35 ` pinskia at gcc dot gnu dot org
2003-08-10 2:36 ` pinskia at gcc dot gnu dot org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-08-10 2:35 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11856
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Last reconfirmed|0000-00-00 00:00:00 |2003-08-10 02:35:07
date| |
Summary|Wrong warning regarding |unsigned warning in template
|assert |
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-08-10 02:35 -------
I can confirm this on the mainline (20030809). I like this warning but this case looks
maybe too over warning but the warning is still true (usigned <= 0 is always true).
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/11856] unsigned warning in template
2003-08-08 14:25 [Bug c++/11856] New: Wrong warning regarding assert o dot kullmann at swansea dot ac dot uk
` (5 preceding siblings ...)
2003-08-10 2:35 ` [Bug c++/11856] unsigned warning in template pinskia at gcc dot gnu dot org
@ 2003-08-10 2:36 ` pinskia at gcc dot gnu dot org
2003-08-23 1:12 ` dhazeghi at yahoo dot com
2004-05-30 17:02 ` pinskia at gcc dot gnu dot org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-08-10 2:36 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11856
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-08-10 02:36 -------
I really meant unsigned >= 0 is always true.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/11856] unsigned warning in template
2003-08-08 14:25 [Bug c++/11856] New: Wrong warning regarding assert o dot kullmann at swansea dot ac dot uk
` (6 preceding siblings ...)
2003-08-10 2:36 ` pinskia at gcc dot gnu dot org
@ 2003-08-23 1:12 ` dhazeghi at yahoo dot com
2004-05-30 17:02 ` pinskia at gcc dot gnu dot org
8 siblings, 0 replies; 10+ messages in thread
From: dhazeghi at yahoo dot com @ 2003-08-23 1:12 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11856
dhazeghi at yahoo dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|3.4 |---
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/11856] unsigned warning in template
2003-08-08 14:25 [Bug c++/11856] New: Wrong warning regarding assert o dot kullmann at swansea dot ac dot uk
` (7 preceding siblings ...)
2003-08-23 1:12 ` dhazeghi at yahoo dot com
@ 2004-05-30 17:02 ` pinskia at gcc dot gnu dot org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-30 17:02 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-05-29 14:49 -------
*** Bug 15723 has been marked as a duplicate of this bug. ***
--
What |Removed |Added
----------------------------------------------------------------------------
CC| |igodard at pacbell dot net
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11856
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2004-05-29 14:49 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-08 14:25 [Bug c++/11856] New: Wrong warning regarding assert o dot kullmann at swansea dot ac dot uk
2003-08-08 14:36 ` [Bug c++/11856] " marcus at jet dot franken dot de
2003-08-08 15:18 ` o dot kullmann at swansea dot ac dot uk
2003-08-08 15:29 ` o dot kullmann at swansea dot ac dot uk
2003-08-08 16:10 ` pinskia at gcc dot gnu dot org
2003-08-08 16:28 ` o dot kullmann at swansea dot ac dot uk
2003-08-10 2:35 ` [Bug c++/11856] unsigned warning in template pinskia at gcc dot gnu dot org
2003-08-10 2:36 ` pinskia at gcc dot gnu dot org
2003-08-23 1:12 ` dhazeghi at yahoo dot com
2004-05-30 17:02 ` pinskia at gcc dot gnu dot 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).