Re: Odd warning on wide char compare

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Josh Boyer wrote:
> Hi All,
>
> At the risk of looking dumb, I'm really stumped by a warning I see in a
> simple testcase involving comparison of an unsigned int with >= L'\0'.
>
> I see in wchar.h, that the wctob function has:
>
> extern int __wctob_alias (wint_t __c) __asm ("wctob");
> __extern_inline int
> __NTH (wctob (wint_t __wc))
> { return (__builtin_constant_p (__wc) && __wc >= L'\0' && __wc <= L'\x7f'
> 	  ? (int) __wc : __wctob_alias (__wc)); }
>
> When I build the simple test program below with the following command
> line, I get a warning about the comparison.
>
> [jwboyer@hansolo ~]$ gcc -W -Wall -Wno-unused-parameter -Wsign-compare -D__USE_EXTERN_INLINES -std=gnu99 --save-temps foo.c
> foo.c: In function ‘foobar’:
> foo.c:8: warning: comparison of unsigned expression >= 0 is always true
> [jwboyer@hansolo ~]$
>
> Looking at the foo.i file, I see that the wctob code is indeed present
> yet it doesn't seem to produce a similar warning.  I tried playing around
> with attributes and options, but I can't seem to make identical code in
> the .c file not have that warning.
>
> Given that wint_t is typedefed to unsigned int in wchar.h, I would have
> expected a similar warning.  This happens with gcc 4.3.2 and gcc 4.4.
> I'm fairly sure I'm missing something here so any help would be appreciated.
>
> Thanks
> josh
>
> ---
>
> #include <stdlib.h>
> #include <stdio.h>
> #include <wchar.h>
>
>
> extern __inline __attribute__ ((__gnu_inline__)) int
> __attribute__ ((__nothrow__)) foobar(unsigned int baz)
> { return (__builtin_constant_p(baz) && baz >= L'\0' && baz <= L'\x7f'
> 		? (int) baz : 0); }
>
> int main(int argc, char **argv)
> {
> 	unsigned int bar = strtoul(argv[1], NULL, 0);
>
> 	/*if (foobar(bar)) */
> 		printf("size: %lu\n", sizeof(L'\0'));
> 		printf("value: %c\n", wctob(L'\0'));
> 		printf("size: %d\n", argc);
> 		printf("value: %u\n", bar);
>
> 	return 0;
> }
>
>
>   
Hey Josh,

you don't see any warnings because gcc suppresses warning messages for
system headers due to "the assumption that they usually do not indicate real
problems and would only make the compiler output harder to read." [taken
from man gcc --> -Wsystem-headers]. You could also see that in the
preprocessed file *.i by looking at those lines:

# 297 "/usr/include/wchar.h" 3 4

This number "3" tells the compiler (including preprocessor) to not emit
warnings for system headers (a full listing of flags for the # <line>
<function> <flags> directive could be found in the CPP user manual,
chapter 9 "preprocessor output")

Though, from my understanding of the man page option -Wsystem-headers,
after enabling this, you should get the warnings for system headers, but
I wasn't able to get them printed with my quite recent version of gcc. :-)

Maybe a bug? I haven't yet had the time to look at the code, but maybe
there's already some known issue ...

Andi



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux