I made a typo. I meant
 
namespace N1::N3
{i
 int x = i + j;
}
 
 
You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com
 
 
Четверг, 28 мая 2020, 3:24 +03:00 от Vladimir Grigoriev via Std-Discussion <std-discussion@lists.isocpp.org>:
 
It seems I have understood the quote. The quote menas that the shown program is equivalent to the following
 
#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;
namespace N1::N3
{i
x = i + j;
}
int main()
{
    std::cout << "N1::N3::x = " << N1::N3::x << '\n';
}
 
 
 
 
 
 
Четверг, 28 мая 2020, 3:06 +03:00 от Vladimir Grigoriev via Std-Discussion <std-discussion@lists.isocpp.org>:
 
According to the C++ 20 Standard (6.5.1 Unqualified name lookup)
 
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. 
 
Now let’s consider the following program
 
#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)
 
 
--
Std-Discussion mailing list
Std-Discussion@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion