Bug 28488 - incorrect warning says signed and unsigned type in conditional expression
Summary: incorrect warning says signed and unsigned type in conditional expression
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.1.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-26 03:41 UTC by Brant Gurganus
Modified: 2006-07-26 11:47 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments
original source (130 bytes, text/plain)
2006-07-26 03:41 UTC, Brant Gurganus
Details
preprocessesed source (179 bytes, text/plain)
2006-07-26 03:42 UTC, Brant Gurganus
Details
generated assembly (247 bytes, text/plain)
2006-07-26 03:43 UTC, Brant Gurganus
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Brant Gurganus 2006-07-26 03:41:00 UTC
This warning indicates a signed/unsigned comparison, but there is no signed/unsigned comparison that I can see.

gurganbl@gurganbl ~ $ gcc -v -save-temps -Wall -Wextra -Werror conditional-sign-mismatch-bug.c
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /var/tmp/portage/gcc-4.1.1/work/gcc-4.1.1/configure --prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/4.1.1 --includedir=/usr/lib/gcc/i686-pc-linux-gnu/4.1.1/include --datadir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.1 --mandir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.1/man --infodir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.1/info --with-gxx-include-dir=/usr/lib/gcc/i686-pc-linux-gnu/4.1.1/include/g++-v4 --host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --disable-altivec --enable-nls --without-included-gettext --with-system-zlib --disable-checking --disable-werror --disable-libunwind-exceptions --disable-multilib --disable-libmudflap --disable-libssp --disable-libgcj --enable-languages=c,c++ --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu
Thread model: posix
gcc version 4.1.1 (Gentoo 4.1.1)
 /usr/libexec/gcc/i686-pc-linux-gnu/4.1.1/cc1 -E -quiet -v conditional-sign-mismatch-bug.c -mtune=pentiumpro -Wall -Wextra -Werror -fpch-preprocess -o conditional-sign-mismatch-bug.i
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/i686-pc-linux-gnu/4.1.1/include
 /usr/include
End of search list.
 /usr/libexec/gcc/i686-pc-linux-gnu/4.1.1/cc1 -fpreprocessed conditional-sign-mismatch-bug.i -quiet -dumpbase conditional-sign-mismatch-bug.c -mtune=pentiumpro -auxbase conditional-sign-mismatch-bug -Wall -Wextra -Werror -version -o conditional-sign-mismatch-bug.s
GNU C version 4.1.1 (Gentoo 4.1.1) (i686-pc-linux-gnu)
        compiled by GNU C version 4.1.1 (Gentoo 4.1.1).
GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=129574
Compiler executable checksum: 33e66c7a45cdf50541c0a56896affe02
cc1: warnings being treated as errors
conditional-sign-mismatch-bug.c: In function ‘main’:
conditional-sign-mismatch-bug.c:13: warning: signed and unsigned type in conditional expression
Comment 1 Brant Gurganus 2006-07-26 03:41:37 UTC
Created attachment 11940 [details]
original source
Comment 2 Brant Gurganus 2006-07-26 03:42:20 UTC
Created attachment 11941 [details]
preprocessesed source
Comment 3 Brant Gurganus 2006-07-26 03:43:07 UTC
Created attachment 11942 [details]
generated assembly
Comment 4 Richard Biener 2006-07-26 08:03:10 UTC
It says "warning: signed and unsigned type in conditional expression" and that
is the case:

        unsigned int found_len = 0 ? a - b : foo;

because a - b is signed and foo is unsigned.
Comment 5 Brant Gurganus 2006-07-26 11:42:14 UTC
That would be a problem in assignment, not in the conditional. Additionally, if I do unsigned int baz = 0;
signed int bar = -1;
baz = bar;

I get no warning. I agree with what you say about there being a problem and what the problem is, but it should give the same warning as for the above code. Currently, the ?: syntax gives a misleading warning since the problem is not in the conditional but in the assignment and strictly having the assignment problem is not generating a warning.
Comment 6 Andrew Pinski 2006-07-26 11:47:19 UTC
No, you are incorrect.  Anyways the warnings about ?: are to make sure that you know that they are different signedness, which might change the behavior slightly than what you are expecting.
unsigned int baz = 0;
signed int bar = -1;
baz = bar;

This is a different issue and I think is being fixed by the -Wcoercion work.