C++ ISO draft 2020(6.4.6 Namespace Scope) quotes in the first paragraph(bolded by me):
The declarative region of a namespace-definition is its namespace-body . Entities declared in a namespace-body are said to be members of the namespace, and names introduced by these declarations into the declarative region of the namespace are said to be member names of the namespace. A namespace member name has namespace scope. Its potential scope includes its namespace from the name’s point of declaration (6.4.2) onwards; and for each using-directive (9.8.3) that nominates the member’s namespace, the member’s potential scope includes that portion of the potential scope of the using-directive that follows the member’s point of declaration.
I thought it wouldn't have a difference between unnamed and named namespace, but the following code has problems:
#include <iostream>
namespace A {int a = 1;}
namespace {int b = 1;}
void main() {
std::cout << a; // identifier "a" is undefined
std::cout << b;
}
Cppreference gives the reason for this problem:
The potential scope of a name declared in an unnamed namespace or in an inline namespace includes the potential scope that name would have if it were declared in the enclosing namespace.
But based on my understanding of the first quote of this question, this error shouldn't occur. What happened here?
namespace { /*body*/ }behaves, by definition, asnamespace UniqueName {} using namespace UniqueName; namespace UniqueName { /*body*/ }whereUniqueNameis some invented identifier unique to the translation unit. The difference between the two namespaces in your example is this implicitusingdirective.acould be found by unqualified lookup, without specifying its namespace, namespaces would have been rather pointless. Why do you believe the error shouldn't occur? How do you arrive at this conclusion from the passage you quote?namespace N { int x;} namespace N {int y;}