What other names might you consider when looking for a namespace name other than namespace names?
Bug Report 373: Searching by name with the names of the names in the pointer directive gives an example of why the wording matters:
namespace X {
namespace Y {
struct X {
void f()
{
using namespace X::Y;
namespace Z = X::Y;
}
};
}
}
Which one X
does the using namespace X::Y
structure or namespace refer to ? Without this formulation, 3.4.6
it would be ambiguous.
This actually leads to a change in the wording:
When looking up a namespace name in a using directive or in the definition of namespace-alias, only namespace names are considered.
to what we have today, because the original formulation did not cover the nested name specifier.
Ambiguity with nested name-specifier, if we look at a C ++ 11 project , the grammar in the 5.1.1
General section :
nested-name-specifier:
::opt type-name ::
::opt namespace-name ::
decltype-specifier ::
nested-name-specifier identifier ::
nested-name-specifier templateopt simple-template-id ::
and the following paragraphs, which I will not copy as they are large, do not limit the nested name-specifier namespace.
As far as I can tell, the 7.3.1
Namespace Definition section restricts the namespace name enough to prevent ambiguity.
source to share
Clang blocks test for namespace using
and alias directives
is exactly the answer to your question:
clang-cc -fsyntax-only -verify% s
struct ns1 {}; // This is not a namespace, although a namespace has ns1 as a name
void ns2();
int ns3 = 0;
namespace ns0 {
namespace ns1 {
struct test0 {};
}
namespace ns2 {
struct test1 {};
}
namespace ns3 {
struct test2 {};
}
}
using namespace ns0;
namespace test3 = ns1; // don't get confused
namespace test4 = ns2;
namespace test5 = ns3;
using namespace ns1; // don't get confused
using namespace ns2;
using namespace ns3;
test0 a;
test1 b;
test2 c;
This issue was also discussed in the n3160 bug report
source to share