14 If a variable member of a namespace is defined outside of the scope of its namespace then any name that appears in the definition of the member (after the declarator-id) is looked up as if the definition of the member occurred in its namespace.
#include <iostream>
namespace N1
{
namespace N2
{
int i = 10;
}
using namespace N2;
namespace N3
{
extern int x;
}
inline namespace N4
{
int j = 20;
}
}
int i = 1;
int j = 2;
int N1::N3::x = i + j;
int main()
{
std::cout << "N1::N3::x = " << N1::N3::x << '\n';
}
The MS Visual C++ 2019 produces the following result
N1::N3::x = 30
So several questions arise. The first one is the program valid? That is are the variable declarations
int i = 1;
int j = 2;
are visible in the this declaration
int N1::N3::x = i + j;
?
That is if the definition «occurs» in the namespace (according to the quote) then the names are not visible. If I am wrong then should the value of the variable x be equal to 12? Is it a bug of the compiler that outputs the value of x equal to 30?
With best regards,
(Vlad from Moscow)