This is the mail archive of the gcc-bugs@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]

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


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: unassigned@gcc.gnu.org
        ReportedBy: gcc@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 <stdio.h>
#include <stdlib.h>
int main(){
        double x=44.33;
        double y;
        y = abs (x);
        printf ("y is %f\n", y);
        //get 44.000000 , expect 44.330000
        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 )


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]