Global namespace abs-function with double argument

59 views Asked by At

While porting a program from Visual Studio to GCC, I bumped in a discrepancy in behavior related to global namespace abs function (not std::abs), which after code minimization can be shown in the following example:

#include <iostream>

int main() {
    std::cout << abs( -0.5 );
}

Here Visual Studio prints 0.5, but GCC just 0. It seems that only integer valued abs function is present in global namespace of GCC's libstdc++. Clang with libc++ behaves like Visual Studio printing 0.5. Online demo: https://gcc.godbolt.org/z/EWbW5sf7c

Do MSVC and Clang extend the standard defining more functions in the global namespace than required?

P.S. I can find some old related questions, e.g. Ambiguous overload call to abs(double), but the answer there speculates that the code as above ought not to compile at all.

0

There are 0 answers