This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/29739] New: -Wconversion produces invalid warnings.
- From: "jaco at kroon dot co dot za" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 6 Nov 2006 13:47:38 -0000
- Subject: [Bug c/29739] New: -Wconversion produces invalid warnings.
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Hi guys,
The following snippet of code should not produce a warning as far as I
understand:
int foo(short bar)
{
return bar;
}
int main()
{
short d = 0;
return foo(d);
}
Unfortunately, however, I get this when I try to compile this code:
jkroon@pitchblack ~/src $ gcc -Wconversion -o foo foo.c
foo.c: In function 'main':
foo.c:9: warning: passing argument 1 of 'foo' with different width due to
prototype
jkroon@pitchblack ~/src $
We use -Wconversion to catch assignments of signed values to unsigned variables
like such:
unsigned foo = -1;
Which it catches correctly as expected.
This problem also shows up when using char instead of short (at least, haven't
tested other types). If the type of bar gets changed to int in the parameter
list of foo the warning goes away.
This warning was orriginally noted when using the strtok_r function, which uses
a macro implementation in order to use more optimal variations for certain
cases, the branch that checks for a constant needle of length 1 and then uses a
variation that looks for a single char produces the same warning:
warning: passing argument 2 of '__strtok_r_1c' with different width due to
prototype
--
Summary: -Wconversion produces invalid warnings.
Product: gcc
Version: 4.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jaco at kroon dot co dot za
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29739