[Bug c/63886] float will fit into int with abs - possible missing warning Wabsolute-value
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63886 Martin Sebor changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED CC||msebor at gcc dot gnu.org Known to work||9.0 Resolution|--- |FIXED Target Milestone|--- |9.0 Known to fail||5.4.0, 6.3.0, 7.3.0, 8.2.0 --- Comment #13 from Martin Sebor --- Yes, thanks Eric, the request has been implemented in GCC 9 and can be resolved as fixed. $ cat pr63886.c && gcc -S -Wall -Wextra pr63886.c # include extern void g(int); void f( float qw) { int n = abs(qw); g(n); } pr63886.c: In function ‘f’: pr63886.c:7:10: warning: using integer absolute value function ‘abs’ when argument is of floating point type ‘float’ [-Wabsolute-value] 7 | int n = abs(qw); | ^~~
[Bug c/63886] float will fit into int with abs - possible missing warning Wabsolute-value
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63886 --- Comment #12 from Eric Gallager --- I think someone added the -Wabsolute-value warning flag to GCC recently; is it ok to close this bug now?
[Bug c/63886] float will fit into int with abs - possible missing warning Wabsolute-value
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63886 --- Comment #11 from Eric Gallager --- (In reply to Manuel López-Ibáñez from comment #10) > (In reply to Eric Gallager from comment #8) > > (In reply to Andreas Schwab from comment #4) > > > float f = 3.1f; > > > > Isn't there already -Wunsuffixed-float-constants for warnings with that kind > > of fix? > > -Wfloat-conversion is not warning about the lack of suffix, but about the > fact that 3.1 does not fit into a double (3.5 does, so there is no warning). > > float f; > double d; > > f = 3.100088817841970012523233890533447265625; // > -Wfloat-conversion -Wunsuffixed-float-constants > d = 3.100088817841970012523233890533447265625; // > -Wunsuffixed-float-constants (not sure why!) > f = 3.5; // -Wunsuffixed-float-constants > d = 3.5; // -Wunsuffixed-float-constants (not sure why!) > f = 3.1f; // no warning > d = 3.1f; // no warning About the ones where you wrote "(not sure why!)", it's asking the programmer to add the nonstandard "d" suffix, which is a GNU extension. This has led projects to ignore the warning: https://lists.gnu.org/archive/html/bug-gzip/2011-11/msg00017.html But I suppose that's an issue for a separate bug.
[Bug c/63886] float will fit into int with abs - possible missing warning Wabsolute-value
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63886 Manuel López-Ibáñez changed: What|Removed |Added Keywords||easyhack --- Comment #10 from Manuel López-Ibáñez --- (In reply to Eric Gallager from comment #8) > (In reply to Andreas Schwab from comment #4) > > float f = 3.1f; > > Isn't there already -Wunsuffixed-float-constants for warnings with that kind > of fix? -Wfloat-conversion is not warning about the lack of suffix, but about the fact that 3.1 does not fit into a double (3.5 does, so there is no warning). float f; double d; f = 3.100088817841970012523233890533447265625; // -Wfloat-conversion -Wunsuffixed-float-constants d = 3.100088817841970012523233890533447265625; // -Wunsuffixed-float-constants (not sure why!) f = 3.5; // -Wunsuffixed-float-constants d = 3.5; // -Wunsuffixed-float-constants (not sure why!) f = 3.1f; // no warning d = 3.1f; // no warning
[Bug c/63886] float will fit into int with abs - possible missing warning Wabsolute-value
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63886 Manuel López-Ibáñez changed: What|Removed |Added CC||manu at gcc dot gnu.org --- Comment #9 from Manuel López-Ibáñez --- (In reply to David Binderman from comment #6) > (In reply to Marek Polacek from comment #5) > > Seems like there's nothing to do for this bug. > > Suggest there are two cases > > 1. double to float Note that 3.1 and 3.1f are not the same number: double d1 = 3.100088817841970012523233890533447265625e+0; float f1 = 3.09904632568359375e+0; and the former does not fit in 'float' (if it fits, we do not warn). > 2. double or float into any integer type. > > The one warning, produced by -Wfloat-conversion, could be > split into two warnings, as per the two cases. -Wfloat-to-int-conversion? Should it warn for vfloat = 16777217; ? If so, perhaps we need another name. > #1 isn't very useful, #2 seems useful to me. > > Then put case #1 into -Wall. case #2 ? I guess useful is in the eye of the beholder. The whole reason why I added -Wconversion more than 10 years ago was precisely to track lossy float-to-double and double-to-float conversions in a project of mine.
[Bug c/63886] float will fit into int with abs - possible missing warning Wabsolute-value
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63886 Andrew Pinski changed: What|Removed |Added Keywords||diagnostic Severity|normal |enhancement
[Bug c/63886] float will fit into int with abs - possible missing warning Wabsolute-value
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63886 Eric Gallager egall at gwmail dot gwu.edu changed: What|Removed |Added CC||egall at gwmail dot gwu.edu --- Comment #8 from Eric Gallager egall at gwmail dot gwu.edu --- (In reply to Andreas Schwab from comment #4) float f = 3.1f; Isn't there already -Wunsuffixed-float-constants for warnings with that kind of fix?
[Bug c/63886] float will fit into int with abs - possible missing warning Wabsolute-value
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63886 Marek Polacek mpolacek at gcc dot gnu.org changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED CC||mpolacek at gcc dot gnu.org Resolution|--- |INVALID --- Comment #5 from Marek Polacek mpolacek at gcc dot gnu.org --- Seems like there's nothing to do for this bug.
[Bug c/63886] float will fit into int with abs - possible missing warning Wabsolute-value
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63886 --- Comment #6 from David Binderman dcb314 at hotmail dot com --- (In reply to Marek Polacek from comment #5) Seems like there's nothing to do for this bug. Suggest there are two cases 1. double to float 2. double or float into any integer type. The one warning, produced by -Wfloat-conversion, could be split into two warnings, as per the two cases. #1 isn't very useful, #2 seems useful to me. Then put case #1 into -Wall.
[Bug c/63886] float will fit into int with abs - possible missing warning Wabsolute-value
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63886 Marek Polacek mpolacek at gcc dot gnu.org changed: What|Removed |Added Status|RESOLVED|UNCONFIRMED Resolution|INVALID |--- --- Comment #7 from Marek Polacek mpolacek at gcc dot gnu.org --- Reopening then.
[Bug c/63886] float will fit into int with abs - possible missing warning Wabsolute-value
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63886 --- Comment #1 from Marc Glisse glisse at gcc dot gnu.org --- warning: conversion to ‘int’ from ‘float’ may alter its value [-Wfloat-conversion]
[Bug c/63886] float will fit into int with abs - possible missing warning Wabsolute-value
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63886 --- Comment #2 from David Binderman dcb314 at hotmail dot com --- (In reply to Marc Glisse from comment #1) warning: conversion to ‘int’ from ‘float’ may alter its value [-Wfloat-conversion] Thanks for that. Given the obscurity of -Wfloat-conversion, maybe it is time for it to be included in -Wall, where more folks will notice it ?
[Bug c/63886] float will fit into int with abs - possible missing warning Wabsolute-value
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63886 --- Comment #3 from David Binderman dcb314 at hotmail dot com --- (In reply to David Binderman from comment #2) Given the obscurity of -Wfloat-conversion, maybe it is time for it to be included in -Wall, where more folks will notice it ? Scratch that. While -Wfloat-conversion does check fine for int into double, it also does the whole lot less useful, even though technically accurate double into float message. Like float f = 3.1; warning: conversion to ‘float’ alters ‘double’ constant value [-Wfloat-conversion] I'll proceed with -Wfloat-conversion, but I'll be stripping out (fgrep -v) these unwanted warnings.
[Bug c/63886] float will fit into int with abs - possible missing warning Wabsolute-value
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63886 --- Comment #4 from Andreas Schwab sch...@linux-m68k.org --- float f = 3.1f;