public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/53603] New: abs() doesn't warn if argument is double, not even with -Wall -Wextra
@ 2012-06-07 13:13 gcc at richardneill dot org
  2012-06-07 13:55 ` [Bug c/53603] " dominiq at lps dot ens.fr
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: gcc at richardneill dot org @ 2012-06-07 13:13 UTC (permalink / raw)
  To: gcc-bugs

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 )


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-06-07 14:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-07 13:13 [Bug c/53603] New: abs() doesn't warn if argument is double, not even with -Wall -Wextra gcc at richardneill dot org
2012-06-07 13:55 ` [Bug c/53603] " dominiq at lps dot ens.fr
2012-06-07 14:03 ` manu at gcc dot gnu.org
2012-06-07 14:41 ` gcc at richardneill dot org
2012-06-07 14:56 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).