Strange C++ function pointer test

Marc Glisse marc.glisse@inria.fr
Thu Dec 31 11:37:00 GMT 2015


On Thu, 31 Dec 2015, Jonathan Wakely wrote:

>> There are other overloads of 'abs' declared in math.h / cmath (only in
>> namespace std in the second case, and there are bugs (or standard issues)
>> about having them in the global namespace for the first one).
>
> That's not quite accurate, C++11 was altered slightly to reflect reality.
>
> <cmath> is required to declare std::abs and it's unspecified whether
> it also declares it as ::abs.
>
> <math.h> is required to declare ::abs and it's unspecified whether it
> also declares it as std::abs.

$ cat a.cc
#include <math.h>
int main(){
   abs(3.5);
}

$ g++-snapshot a.cc -c -Wall -W
a.cc: In function 'int main()':
a.cc:3:10: error: 'abs' was not declared in this scope
    abs(3.5);
           ^

That's what I called "bug" in my message (there are a few bugzilla PRs for 
this). It would probably work on Solaris.

And I seem to remember there are at least 2 open LWG issues on the topic, 
one saying that the C++11 change didn't go far enough to match reality, 
since it still documents C headers differently from the C standard, and 
one saying that all overloads of abs should be declared as soon as one is 
(yes, they contradict each other).

-- 
Marc Glisse



More information about the Gcc mailing list