C++ Logo

STD-DISCUSSION

Advanced search

Subject: Extending a namespace in an inline namespace that initially was defined in the enclosing namespace of the inline namespace
From: Vladimir Grigoriev (vlad.moscow_at_[hidden])
Date: 2019-10-23 13:11:47


In the section  Section 9.7.1 Namespace definition: if the C++ 20 Standard there is written

2 In a named-namespace-definition, the identifier is the name of the namespace. If the identifier, when looked up (6.4.1), refers to a namespace-name (but not a namespace-alias) that was introduced in the namespace in which the named-namespace-definition appears or that was introduced in a member of the inline namespace set of that namespace, the namespace-definition extends the previously-declared namespace. Otherwise, the identifier is introduced as a namespace-name into the declarative region in which the named-namespace definition appears.

This program is compiled successfully.

#include <iostream>
inline namespace N1
{
inline namespace N2
{
namespace N3
{
void f( int ) { std::cout << "f( int )\n"; }
}
}
namespace N3
{
void f( char ) { std::cout << "f( char )\n"; }
}
}
int main()
{
N3::f( 10 );
N2::N3::f( 'A' );
}

Is it a reasonable intention of the Standard that such a program would be well-formed?  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 list run by herb.sutter at gmail.com

Older Archives on Google Groups