[Bug c++/90291] [8/9/10 Regression] Inline namespace erroneously extends another namespace

nathan at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri May 3 12:45:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90291

--- Comment #13 from Nathan Sidwell <nathan at gcc dot gnu.org> ---
I don't know where the DR information is available without a password (C++
physical meetings are public, see https://isocpp.org/std/

Here is the text of 2061:

2061. Inline namespace after simplifications
Section: 9.7.1  [namespace.def]     Status: CD4     Submitter: Richard Smith   
 Date: 2014-12-18     Priority: 0     Drafting: Maurer

[Adopted at the February, 2016 meeting.]

After the resolution of issue 1795, 9.7.1 [namespace.def] paragraph 3 now says:

    In a named-namespace-definition, the identifier is the name of the
namespace. If the identifier, when looked up (6.4.1 [basic.lookup.unqual]),
refers to a namespace-name (but not a namespace-alias) introduced in the
declarative region in which the named-namespace-definition appears, 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 appears to break code like the following:

  namespace A {
    inline namespace b {
      namespace C {
        template<typename T> void f();
      }
    }
  }

  namespace A {
    namespace C {
      template<> void f<int>() { }
    }
  }

because (by definition of “declarative region”) C cannot be used as an
unqualified name to refer to A::b::C within A if its declarative region is
A::b.

Proposed resolution (September, 2015):

Change 9.7.1 [namespace.def] paragraph 3 as follows:

    In a named-namespace-definition, the identifier is the name of the
namespace. If the identifier, when looked up (6.4.1 [basic.lookup.unqual]),
refers to a namespace-name (but not a namespace-alias) that was introduced in
the declarative region 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. 

[nathan: I.e. we do unqualified lookup for the name, ignoring using directives.
 That naturally descends into the immediate set of inline-namespaces.]


More information about the Gcc-bugs mailing list