This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-11-11


1795. Disambiguating original-namespace-definition and extension-namespace-definition

Section: 9.8.2  [namespace.def]     Status: CD4     Submitter: Richard Smith     Date: 2013-10-04

[Moved to DR at the November, 2014 meeting.]

According to 9.8.2 [namespace.def] paragraph 2,

The identifier in an original-namespace-definition shall not have been previously defined in the declarative region in which the original-namespace-definition appears.

Apparently the intent of this requirement is to say that, given the declarations

  namespace N { }
  namespace N { }

the second declaration is to be taken as an extension-namespace-definition and not an original-namespace-definition, since the general rules in _N4868_.6.4.1 [basic.scope.declarative] cover the case in which the identifier has been previously declared as something other than a namespace.

This use of “shall” for disambiguation is novel, however, and it would be better to replace it with a specific statement addressing disambiguation in paragraphs 2 and 3.

Proposed Resolution (July, 2014):

  1. Change 6.4.6 [basic.scope.namespace] paragraph 1 as follows:

  2. The declarative region of a namespace-definition is its namespace-body. The potential scope denoted by an original-namespace-name is the concatenation of the declarative regions established by each of the namespace-definitions in the same declarative region with that original-namespace-name. Entities declared in a namespace-body...
  3. Change 9.8.2 [namespace.def] paragraphs 1-4 as follows:

  4. The grammar for a namespace-definition is

    The identifier in an original-namespace-definition shall not have been previously defined in the declarative region in which the original-namespace-definition appears. The identifier in an original-namespace-definition is the name of the namespace. Subsequently in that declarative region, it is treated as an original-namespace-name.

    The original-namespace-name in an extension-namespace-definition shall have previously been defined in an original-namespace-definition in the same declarative region.

    Every namespace-definition shall appear in the global scope or in a namespace scope (6.4.6 [basic.scope.namespace]).

    In a named-namespace-definition, the identifier is the name of the namespace. If the identifier, when looked up (6.5.3 [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.

  5. Change 9.8.2 [namespace.def] paragraph 7 as follows:

  6. If the optional initial inline keyword appears in a namespace-definition for a particular namespace, that namespace is declared to be an inline namespace. The inline keyword may be used on an extension-namespace-definition a namespace-definition that extends a namespace only if it was previously used on the original-namespace-definition namespace-definition that initially declared the namespace-name for that namespace.
  7. Delete 9.8.3 [namespace.alias] paragraph 4:

  8. A namespace-name or namespace-alias shall not be declared as the name of any other entity in the same declarative region. A namespace-name defined at global scope shall not be declared as the name of any other entity in any global scope of the program. No diagnostic is required for a violation of this rule by declarations in different translation units.
  9. Change 9.8.4 [namespace.udir] paragraph 5 as follows:

  10. If a namespace is extended by an extension-namespace-definition after a using-directive for that namespace is given, the additional members of the extended namespace and the members of namespaces nominated by using-directives in the extension-namespace-definition extending namespace-definition can be used after the extension-namespace-definition extending namespace-definition.