Title
Nested unnamed namespace of inline unnamed namespace
Status
open
Section
9.8.2.2 [namespace.unnamed]
Submitter
Nathan Sidwell

Created on 2021-11-22.00:00:00 last changed 5 days ago

Messages

Date: 2021-11-22.00:00:00

According to 9.8.2.2 [namespace.unnamed] paragraph 1,

An unnamed-namespace-definition behaves as if it were replaced by

    inlineopt namespace unique { /* empty body */ }
    using namespace unique ;
    namespace unique { namespace-body }

where inline appears if and only if it appears in the unnamed-namespace-definition and all occurrences of unique in a translation unit are replaced by the same identifier, and this identifier differs from all other identifiers in the translation unit.

The use of a single identifier for all occurrences of unique within a translation unit leads to problems when an inline unnamed namespace contains a nested unnamed namespace, e.g.,

    inline namespace {
      namespace { }
    }

In this case, the unnamed namespace cannot be reopened because the lookup for unique finds both the outer and inner namespaces and is thus ambiguous.

Suggested resolution:

Change 9.8.2.2 [namespace.unnamed] paragraph 1 as follows:

...where inline appears if and only if it appears in the unnamed-namespace-definition and all occurrences of unique in each scope in a translation unit are replaced by the same scope-specific identifier, and this identifier differs from all other identifiers in the translation unit.
History
Date User Action Args
2021-11-22 00:00:00admincreate