From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15583 invoked by alias); 7 Jun 2012 13:13:01 -0000 Received: (qmail 15569 invoked by uid 22791); 7 Jun 2012 13:13:00 -0000 X-SWARE-Spam-Status: No, hits=-3.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,FRT_ADOBE2 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 07 Jun 2012 13:12:48 +0000 From: "gcc at richardneill dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/53603] New: abs() doesn't warn if argument is double, not even with -Wall -Wextra Date: Thu, 07 Jun 2012 13:13:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gcc at richardneill dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-06/txt/msg00395.txt.bz2 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 #include 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 )