In the code below, I define a trivial log function. In main I try not to call it; I call std::log. Nevertheless, my own log is called; and I see “log!” on screen. Does anyone know why? I use G++ 4.7 and clang++ 3.2.
#include <iostream>
#include <cmath>
double log(const double x) { std::cout << "log!\n"; return x; }
int main(int argc, char *argv[])
{
std::log(3.14);
return 0;
}
C++ Standard 17.6.1.2 paragraph 4 (emphasis mine):
g++ does it the latter way so that some of the same header files can be reused for C and C++. So g++ is allowed to declare and define
double log(double)in the global namespace.Section 17.6.4.3.3 paragraphs 3 and 4:
And up at the top of Section 17.6.4.3 paragraph 2:
You, on the other hand, may not declare or define
::login any way.It’s too bad the g++ toolchain doesn’t give you any error messages, though.