![]() |
STD-DISCUSSION |
Subject: Re: Unqualified name lookup of names used in a definition of a member of a namespace.
From: Vladimir Grigoriev (vlad.moscow_at_[hidden])
Date: 2020-05-27 19:28:57
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_at_[hidden]>:
>Â
>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
>>Â
>Â
>--
>Std-Discussion mailing list
>Std-Discussion_at_[hidden]
>https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>Â
Â
STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org