[libcxx] r203126 - Fix a couple of -Wabsolute-value warnings in the libc++ tests

Arthur O'Dwyer arthur.j.odwyer at gmail.com
Thu Mar 6 13:10:54 PST 2014


On Thu, Mar 6, 2014 at 1:03 PM, David Blaikie <dblaikie at gmail.com> wrote:
> On Thu, Mar 6, 2014 at 12:15 PM, Joerg Sonnenberger <joerg at britannica.bec.de> wrote:
>> On Thu, Mar 06, 2014 at 04:27:18PM -0000, Marshall Clow wrote:
>>>
>>> -    static_assert((std::is_same<decltype(fabsf(0)), float>::value), "");
>>> -    static_assert((std::is_same<decltype(fabsl(0)), long double>::value), "");
>>> -    assert(fabs(-1) == 1);
>>> +    static_assert((std::is_same<decltype(fabsf(0.f)), float>::value), "");
>>> +    static_assert((std::is_same<decltype(fabsl(0.L)), long double>::value), "");
>>> +    assert(fabs(-1.f) == 1);
>>
>> This looks bogus as in: it shouldn't warn here.
>
> What basis did you have in mind? That the constant is in the
> representable range for the function being called, even though it's
> not of the right type?

I guess it makes sense to warn about fabsf(int), because int->float
conversion can be lossy.
But surely fabs(int) and fabsl(int) are 100% fine!

On the other hand, I guess it doesn't much matter. This is a case
where Clang's warnings are a little spammy, but the fixit is still
correct and results in better-style code. (Perhaps a good candidate
for turning into a remark. ;))

–Arthur




More information about the cfe-commits mailing list