[Bug c++/11856] Wrong warning regarding assert
o dot kullmann at swansea dot ac dot uk
gcc-bugzilla@gcc.gnu.org
Fri Aug 8 16:28:00 GMT 2003
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
More information about the Gcc-bugs
mailing list