clang 3.5 warnings for "using integer absolute value function 'abs' when argument is of floating point type [-Wabsolute-value]"

RESOLVED FIXED in mozilla35

Status

()

defect
RESOLVED FIXED
5 years ago
5 years ago

People

(Reporter: dholbert, Assigned: dholbert)

Tracking

Trunk
mozilla35
x86_64
Linux
Points:
---
Dependency tree / graph
Bug Flags:
in-testsuite -
qe-verify -

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

No description provided.
Using clang 3.5 on Ubuntu 14.10 final beta (which is a trunk-ish version of clang -- newer than 3.5 in Ubuntu 14.04), I get several warnings like this when building m-c, which break my build because they're in FAIL_ON_WARNINGS directories:

{
gfx/2d/Path.cpp:255:43: error: using integer absolute value function 'abs' when argument is of floating point type [-Werror,-Wabsolute-value]
 1:02.30     t = 2 * Float(sqrt(aTolerance / (3. * abs(s3))));
 1:02.30                                           ^
}

Here, s3 is float-typed, as the warning text says. In another instance, we get the same warning for an int64_t.

This happens because "abs" comes from C, and is documented here as just taking "int". Other types have their own differently-named functions "fabs", "fabsl", "labs", and "llabs" (in C):
  http://en.cppreference.com/w/c/numeric/math/abs

Fortunately, C++ has std::abs which seems to have versions for pretty much any numeric type:
  http://en.cppreference.com/w/cpp/numeric/math/abs
  http://en.cppreference.com/w/cpp/numeric/math/fabs
...which is why the warning-text recommends using it.
Summary: clang 3.5 warnings for → clang 3.5 warnings for "using integer absolute value function 'abs' when argument is of floating point type [-Wabsolute-value]"
Posted patch fix v1Splinter Review
Attachment #8496493 - Flags: review?(ehsan.akhgari)
Assignee: nobody → dholbert
Status: NEW → ASSIGNED
Attachment #8496493 - Flags: review?(ehsan.akhgari) → review+
https://hg.mozilla.org/mozilla-central/rev/7a4c925ca8d7
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla35
See Also: → 1089478
Flags: qe-verify-
Depends on: 1122586
You need to log in before you can comment on or make changes to this bug.