Date: Thu, 28 May 2020 03:23:42 +0300
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';
}
You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com
>Четверг, 28 мая 2020, 3:06 +03:00 от Vladimir Grigoriev via Std-Discussion <std-discussion_at_[hidden]>:
>
>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)
>
>You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com
>--
>Std-Discussion mailing list
>Std-Discussion_at_[hidden]
>https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>
#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';
}
You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com
>Четверг, 28 мая 2020, 3:06 +03:00 от Vladimir Grigoriev via Std-Discussion <std-discussion_at_[hidden]>:
>
>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)
>
>You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com
>--
>Std-Discussion mailing list
>Std-Discussion_at_[hidden]
>https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>
Received on 2020-05-27 19:26:51