[Bug c/53001] -Wfloat-conversion should be available to warn about floating point errors

2013-09-20 Thread gcc at richardneill dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53001

--- Comment #10 from Richard Neill  ---
Thank you for adding this - I will certainly find it useful!

May I suggest that this warning be implicitly enabled by -Wextra, (even if it's
not enabled by -Wall) ?


[Bug c/53603] New: abs() doesn't warn if argument is double, not even with -Wall -Wextra

2012-06-07 Thread gcc at richardneill dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53603

 Bug #: 53603
   Summary: abs() doesn't warn if argument is double, not even
with -Wall -Wextra
Classification: Unclassified
   Product: gcc
   Version: 4.6.3
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: g...@richardneill.org


I think that using abs() with an argument which isn't an int, should to trigger
a warning... but it doesn't. Not even with -Wextra.

//Compile with Wall -Wextra
//I think that gcc could spot that abs() casts x to int, 
//and it could warn me that I did something stupid. 

#include 
#include 
int main(){
double x=44.33;
double y;
y = abs (x);
printf ("y is %f\n", y);
//get 44.00 , expect 44.33
return (0);
}


Please do consider trapping this: I spent 3 hours finding a bug caused by this
one: yes, it was my fault for writing sqrt(abs(a_double)) rather than
sqrt(fabs(a_double)), but the compiler could have warned me. This type of error
is quite insidious, because it can cause subtle errors in mathematical programs
that only occur sometimes!

Imho, gcc should warn, unless I'd written:
 y = abs( (int)x )


[Bug c/53603] abs() doesn't warn if argument is double, not even with -Wall -Wextra

2012-06-07 Thread gcc at richardneill dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53603

--- Comment #3 from Richard Neill  2012-06-07 
14:41:10 UTC ---
Thanks for your explanation. I didn't know about -Wconversion existing
independently of -Wextra. 

Might I suggest a couple of things that arise:

1. It seems a bit strange to me that there are warnings that are not enabled by 
-Wall -Wextra. The man page lists so many different types of warning: perhaps
it would be useful to mention (under -Wextra) which ones it does *not* enable?
Or maybe it would be worthwhile adding something like "-Wkitchensink" to mean:
yes, really do turn on all the warnings (except maybe for pedantic). 

2. Even -Wconversion misses the following:

  int a=7; int b=4;
  double y;  
  y = a/b;

I know why: a/b is a perfectly sensible integer division, and then y is being
assigned the integer value of 1, which is also a loss-freel conversion.
But, what I mean by "y=a/b" is "y is the floating point number obtained by
dividing a and b", not "do integer division of a/b and then promote to a
double"

3. As you say, -Wconversion is too noisy to include by default. But perhaps
there could be a distinction between straightforward assignment: 

   int a; 
   unsigned int b;
   a=b; 

and function calls with mismatched parameters:

   int a; 
   double d;
   int myfunction(int x){...}  ; 
   a = myfunction(d);

I'd suggest that when the latter happens, it's most probably a bug, whereas the
former is (often) deliberate. This might allow for some subsets of -Wconversion
to be included within -Wextra ? 

Thanks for your time.


[Bug c/51952] New: Wish: -Wextra should warn on result of integer division being assigned to a float

2012-01-22 Thread gcc at richardneill dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51952

 Bug #: 51952
   Summary: Wish: -Wextra should warn on result of integer
division being assigned to a float
Classification: Unclassified
   Product: gcc
   Version: 4.5.4
Status: UNCONFIRMED
  Severity: enhancement
  Priority: P3
 Component: c
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: g...@richardneill.org


I have several times mistakenly written code like the following:
   int a = 1; int b = 2;  float c;
   c = a/b;

when I obviously meant:
   c = (float)a/b;


What the language means by "c = a/b" is "do the integer division of a/b, then
cast to float and assign to c".  But what one might expect this to do is "c is
a float, which is calculated by dividing a and b".

Of course this is my fault, but it's rather a trap for the unwary. Therefore my
wish is that -Wextra should warn if there is an integer division on the RHS of
'=', and a float on the LHS.

At the moment, compiling the statement "c = a/b" triggers no errors, even when
using  -Wall -Wextra.

Thanks for your consideration.