Title
Disambiguating original-namespace-definition and extension-namespace-definition
Status
cd4
Section
9.8.2 [namespace.def]
Submitter
Richard Smith

Created on 2013-10-04.00:00:00 last changed 95 months ago

Messages

Date: 2014-11-15.00:00:00

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

Date: 2014-07-15.00:00:00

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

      namespace-name:
        original-namespace-name identifier
        namespace-alias
      original-namespace-name:
        identifier
      namespace-definition:
        named-namespace-definition
        unnamed-namespace-definition
      named-namespace-definition:
        original-namespace-definition
        extension-namespace-definition
      original-namespace-definition:
        inlineopt namespace identifier { namespace-body }
      extension-namespace-definition:
        inlineopt namespace original-namespace-name { namespace-body }
      unnamed-namespace-definition:
        inlineopt namespace { namespace-body }
      namespace-body:
        declaration-seqopt

    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.
Date: 2021-02-24.00:00:00

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.

History
Date User Action Args
2017-02-06 00:00:00adminsetstatus: drwp -> cd4
2015-05-25 00:00:00adminsetstatus: dr -> drwp
2015-04-13 00:00:00adminsetmessages: + msg5368
2014-11-24 00:00:00adminsetstatus: tentatively ready -> dr
2014-10-13 00:00:00adminsetmessages: + msg5135
2014-10-13 00:00:00adminsetstatus: drafting -> tentatively ready
2014-03-03 00:00:00adminsetstatus: open -> drafting
2013-10-04 00:00:00admincreate