Consider the code:
template<typename T> class Foo{}; namespace X { class X{}; } using namespace X; // now both class X and namespace X are visible Foo<X::X> f() { return {}; } int main() {}
gcc5.2 compiles the code without any errors. However, clang spits out the error:
error: "X" is not a class, namespace or enumeration Foo f ()error: reference to "X" is ambiguous
error: "X" is not a class, namespace or enumeration Foo f ()
error: reference to "X" is ambiguous
Is the code syntactically valid according to the C ++ standard? Or is it just a gcc error? Removing a qualified name X::Xand using it Foo<X>instead makes the gcc choke also
X::X
Foo<X>
error: template argument 1 is not valid Foo f ()
[namespace.udir] / 6:
, .
X X::X , . , X; , , . ( X, ).
X
::X . Lookup . [Namespace.qual]/2:
::X
X m S (X, m) : S 0 (X, m) - m X X (7.3.1). S 0 (X, m) , S (X, m) S 0 (X, m); [...]
m
X - , m - "X". , , .
, , , , .
#include <iostream> #include <string> namespace test { void function1(void){std::cout << "Function inside the namespace" << std::endl;} class test { public: static void function1(void){std::cout << "Function inside the class" << std::endl;} }; }; using namespace test; int main() { function1(); test::function1(); test::test::function1(); }
(GCC 4.9.2)
"Function inside the namespace" "Function inside the namespace" "Function inside the class"
Source: https://habr.com/ru/post/1612991/More articles:CSS background image animation, high CPU usage - cssError deploying ASP.NET 5 application to Heroku using dotnet-buildpack - asp.netVariable declarations with the same name - javascriptIs it possible to define composition patterns in functions or functors? - compositionHow to implement a simple OpenCV operation in the OpenCV Kurento module - c ++Low levels of pre-training with OpenGL - c ++Invalid shared_ptr template argument - c ++Как отправить сообщение GCM с Java Appengine - google-app-engineHow to access variables in Javascript files using babel? - javascriptCopying one file to multiple remote hosts in parallel with SFTP - pythonAll Articles