This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
> > shouldn't this code below generate warnings on "implicit narrowing > > conversion", on: > > 1) "i=f" assignment as well as > > 2) on conversion on return from float to int? > > The desire for a better -Wconversion has been known for years. I have a > notional specification for it, "warn for any implicit conversion that may > change a value", as discussed at > <http://www.srcf.ucam.org/~jsm28/gcc/#Wconversion>, arising from a > discussion on security-audit (there having been a spate of security > problems relating to implicit signed/unsigned conversions) > <http://archives.neohapsis.com/archives/linux/lsap/2000-q4/0153.html>, and > also discussed in bug 6614 and elsewhere. There are far more features > that would be nice to have than there is implementation time, and so far > no-one has contributed an implementation of this one. hmm that stuff is 4 years old. In that case how about the attached patch? It seems to work for me. It probably doesn't cover every case mentioned in the document but I suppose it is better than waiting another 4 years. //----------------------------------------------- [adam@mtdew gcc]$ cat test3.c int main() { double f; int i; i = f; return f; } //----------------------------------------------- [adam@mtdew gcc]$ /usr/local/gcc/bin/gcc -Wall -W -Wconversion test3.c test3.c: In function `main': test3.c:6: warning: real type implicitly converted to integer type test3.c:8: warning: real type implicitly converted to integer type [adam@mtdew gcc]$ /usr/local/gcc/bin/gcc -Wall -W test3.c [adam@mtdew gcc]$ /usr/local/gcc/bin/gcc --version gcc (GCC) 3.4.0 Copyright (C) 2004 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. //-----------------------------------------------
Attachment:
gcc-3.4.0-implicit.narrowing.conversion.diff
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |