This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/59939] No warning on signedness changes caused by implicit conversion
- From: "chengniansun at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 25 Jan 2014 03:38:30 +0000
- Subject: [Bug c/59939] No warning on signedness changes caused by implicit conversion
- Auto-submitted: auto-generated
- References: <bug-59939-4 at http dot gcc dot gnu dot org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59939
--- Comment #5 from Chengnian Sun <chengniansun at gmail dot com> ---
(In reply to Andrew Pinski from comment #4)
> (In reply to Chengnian Sun from comment #3)
> > (In reply to Andrew Pinski from comment #1)
> > > IIRC this was done so that code which uses macros and have conditional code
> > > like:
> > >
> > > MACRO1 || fn1(a, b)
> >
> > Sorry, I do not understand. Can you elaborate more? Why it is related to
> > macros
> > and what is the rational behind this design.
>
> Lets say 1 was really MACRO1 defined by:
> #define MACRO1 0
> or
> #define MACRO1 1
>
> and you have some typedefs which
>
> And then you use that macro below and you get the warning.
Thanks for your reply. I am still not sure whether I got you correctly. I
thought after preprocessing, all the constant macros will be expanded.
Following your instructions, I replaced 1 with MACRO1 ("#define MACRO1 1", and
"MACRO1 || fn1(a, b)"), but Gcc still does not warn. I also checked old
versions of Gcc, and 4.2 warns.
--------------------------------------------------------------------------
$: cat s.c.v6.c
int a, b;
int fn1(unsigned, unsigned);
#define MACRO1 1
unsigned int fn2() {
return MACRO1 || fn1(a, b);
}
$: gcc-trunk -c -std=c89 -Wconversion s.c.v6.c
$: gcc-4.8 -c -std=c89 -Wconversion s.c.v6.c
$: gcc-4.7 -c -std=c89 -Wconversion s.c.v6.c
$: gcc-4.6 -c -std=c89 -Wconversion s.c.v6.c
$: gcc-4.5 -c -std=c89 -Wconversion s.c.v6.c
$: gcc-4.4 -c -std=c89 -Wconversion s.c.v6.c
$: gcc-4.3 -c -std=c89 -Wconversion s.c.v6.c
$: gcc-4.2 -c -std=c89 -Wconversion s.c.v6.c
s.c.v6.c: In function âfn2â:
s.c.v6.c:7: warning: passing argument 1 of âfn1â as unsigned due to prototype
s.c.v6.c:7: warning: passing argument 2 of âfn1â as unsigned due to prototype
$: gcc-4.1 -c -std=c89 -Wconversion s.c.v6.c
s.c.v6.c: In function âfn2â:
s.c.v6.c:7: warning: passing argument 1 of âfn1â as unsigned due to prototype
s.c.v6.c:7: warning: passing argument 2 of âfn1â as unsigned due to prototype
$: gcc-4.0 -c -std=c89 -Wconversion s.c.v6.c
s.c.v6.c: In function âfn2â:
s.c.v6.c:7: warning: passing argument 1 of âfn1â as unsigned due to prototype
s.c.v6.c:7: warning: passing argument 2 of âfn1â as unsigned due to prototype
$:
-----------------------------------------------------------------------------
However, if I define MACRO1 as 0, then all the versions of Gcc warn.
-----------------------------------------------------------------------------
$: cat s.c.v6.c
int a, b;
int fn1(unsigned, unsigned);
#define MACRO1 0
unsigned int fn2() {
return MACRO1 || fn1(a, b);
}
$: gcc-4.0 -c -std=c89 -Wconversion s.c.v6.c
s.c.v6.c: In function âfn2â:
s.c.v6.c:7: warning: passing argument 1 of âfn1â as unsigned due to prototype
s.c.v6.c:7: warning: passing argument 2 of âfn1â as unsigned due to prototype
$: gcc-4.1 -c -std=c89 -Wconversion s.c.v6.c
s.c.v6.c: In function âfn2â:
s.c.v6.c:7: warning: passing argument 1 of âfn1â as unsigned due to prototype
s.c.v6.c:7: warning: passing argument 2 of âfn1â as unsigned due to prototype
$: gcc-4.2 -c -std=c89 -Wconversion s.c.v6.c
s.c.v6.c: In function âfn2â:
s.c.v6.c:7: warning: passing argument 1 of âfn1â as unsigned due to prototype
s.c.v6.c:7: warning: passing argument 2 of âfn1â as unsigned due to prototype
$: gcc-4.3 -c -std=c89 -Wconversion s.c.v6.c
s.c.v6.c: In function âfn2â:
s.c.v6.c:7: warning: conversion to âunsigned intâ from âintâ may change the
sign of the result
s.c.v6.c:7: warning: conversion to âunsigned intâ from âintâ may change the
sign of the result
s.c.v6.c:7: warning: conversion to âunsigned intâ from âintâ may change the
sign of the result
$: gcc-4.4 -c -std=c89 -Wconversion s.c.v6.c
s.c.v6.c: In function âfn2â:
s.c.v6.c:7: warning: conversion to âunsigned intâ from âintâ may change the
sign of the result
s.c.v6.c:7: warning: conversion to âunsigned intâ from âintâ may change the
sign of the result
$: gcc-4.5 -c -std=c89 -Wconversion s.c.v6.c
s.c.v6.c: In function âfn2â:
s.c.v6.c:7:3: warning: conversion to âunsigned intâ from âintâ may change the
sign of the result
s.c.v6.c:7:3: warning: conversion to âunsigned intâ from âintâ may change the
sign of the result
$: gcc-4.6 -c -std=c89 -Wconversion s.c.v6.c
s.c.v6.c: In function âfn2â:
s.c.v6.c:7:3: warning: conversion to âunsigned intâ from âintâ may change the
sign of the result [-Wsign-conversion]
s.c.v6.c:7:3: warning: conversion to âunsigned intâ from âintâ may change the
sign of the result [-Wsign-conversion]
$: gcc-4.7 -c -std=c89 -Wconversion s.c.v6.c
s.c.v6.c: In function âfn2â:
s.c.v6.c:7:3: warning: conversion to âunsigned intâ from âintâ may change the
sign of the result [-Wsign-conversion]
s.c.v6.c:7:3: warning: conversion to âunsigned intâ from âintâ may change the
sign of the result [-Wsign-conversion]
$: gcc-4.8 -c -std=c89 -Wconversion s.c.v6.c
s.c.v6.c: In function âfn2â:
s.c.v6.c:7:3: warning: conversion to âunsigned intâ from âintâ may change the
sign of the result [-Wsign-conversion]
return MACRO1 || fn1(a, b);
^
s.c.v6.c:7:3: warning: conversion to âunsigned intâ from âintâ may change the
sign of the result [-Wsign-conversion]
$: gcc-trunk -c -std=c89 -Wconversion s.c.v6.c
s.c.v6.c: In function âfn2â:
s.c.v6.c:7:3: warning: conversion to âunsigned intâ from âintâ may change the
sign of the result [-Wsign-conversion]
return MACRO1 || fn1(a, b);
^
s.c.v6.c:7:3: warning: conversion to âunsigned intâ from âintâ may change the
sign of the result [-Wsign-conversion]