if I define a namespace log somewhere and make it accessible in the global scope, this will clash with double log(double) from the standard cmath header. Actually, most compilers seem to go along with it -- most versions of SunCC, MSVC, GCC -- but GCC 4.1.2 doesn't.
Unfortunately, there seems no way to resolve the ambiguity, as using declarations are not legal for namespace identifiers. Do you know any way I could write log::Log in the global namespace even if cmath is included?
Thanks.
EDIT: Would anybody know what the C++03 standard has to say about this? I would have thought that the scope operator sufficiently disambiguates the use of log in the code example below.
#include <cmath>
namespace foo
{
namespace log
{
struct Log { };
} // namespace log
} // namespace foo
using namespace foo;
int main()
{
log::Log x;
return 0;
}
// g++ (GCC) 4.1.2 20070115 (SUSE Linux)
// log.cpp: In function `int main()':
// log.cpp:20: error: reference to `log' is ambiguous
// /usr/include/bits/mathcalls.h:110: error: candidates are: double log(double)
// log.cpp:7: error: namespace foo::log { }
// log.cpp:20: error: expected `;' before `x'
foo::log::Logto prevent the ambiguousity?<c****>versions of C standard headers be located in thestdnamespace? Is it a v4.1 implementation bug (in g++ 4.4 this code works fine) or I remember this thing wrong?<name.h>C header, while including<cname>should put them only in thestdnamespace./usr/include/bits/mathcalls.hbut then the file<cmath>expectslogfor example to be in the global namespace (see line 356 in gcc's stdlib<cmath>, it readsusing ::log;. I wonder if one can play with all the defined macros in order to correct all this behavior. By the way, @MatteoItalia, I find this also in gcc 4.7, so if it was fixed in 4.4 the bug came back.