Bug 145919 - Fix absolute value warning in LocalizedStringsGtk.cpp
Summary: Fix absolute value warning in LocalizedStringsGtk.cpp
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Michael Catanzaro
URL:
Keywords:
Depends on:
Blocks: 145121
  Show dependency treegraph
 
Reported: 2015-06-12 04:14 PDT by Csaba Osztrogonác
Modified: 2015-06-19 18:25 PDT (History)
5 users (show)

See Also:


Attachments
Patch (1.61 KB, patch)
2015-06-19 16:52 PDT, Michael Catanzaro
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Csaba Osztrogonác 2015-06-12 04:14:11 PDT
../../Source/WebCore/platform/gtk/LocalizedStringsGtk.cpp:667:36: warning: using integer absolute value function 'abs' when argument is of floating point type [-Wabsolute-value]
    int seconds = static_cast<int>(abs(time));
                                   ^
../../Source/WebCore/platform/gtk/LocalizedStringsGtk.cpp:667:36: note: use function 'std::abs' instead
    int seconds = static_cast<int>(abs(time));
                                   ^~~
                                   std::abs
1 warning generated.


This code was introduced in http://trac.webkit.org/changeset/142463 ,
but it seems something is still wrong here.
Comment 1 Michael Catanzaro 2015-06-19 16:51:53 PDT
There are two things wrong:

* Clang warns when passing a float to ::abs() because ::abs() will truncate the value, returning an int. If you are passing in a float, there's a high probability you wants to use std::abs() to receive a float instead.
* The current code casts the result of ::abs(), an int, to an int, which is pointless. We could remove the cast, but that would not avoid the clang warning. This is a very strange case that a compiler warning requires us to use an unnecessary cast.
Comment 2 Michael Catanzaro 2015-06-19 16:52:07 PDT
Created attachment 255248 [details]
Patch
Comment 3 WebKit Commit Bot 2015-06-19 18:25:40 PDT
Comment on attachment 255248 [details]
Patch

Clearing flags on attachment: 255248

Committed r185786: <http://trac.webkit.org/changeset/185786>
Comment 4 WebKit Commit Bot 2015-06-19 18:25:44 PDT
All reviewed patches have been landed.  Closing bug.