ISO/IEC JTC1 SC22 WG21 P2109R0
Nathan Sidwell
Target audience: CWG, Plenary 2020-02-13

P2109R0: US084: Disallow "export import foo" outside of module interface

This paper resolves NB Comment US084:

export import foo; should not be allowed outside of module interface purview.

Both US033 and p1857 alter grammar and/or semantics of import declarations. The changes here presume both US033 and p1857 are accepted. p1857 introduced a problem with exported module-import-declarations. They ceased to be a thing. This wording also addresses that.


Change [module.interface] para 1 (10.2)

export-declaration :
    export declaration
    export { declaration-seqopt }
    export-keyword module-import-declaration
An export-declaration shall appear only at namespace scope and only in the purview of a module interface unit. An export-declaration shall not appear directly or indirectly within an unnamed namespace or a private-module-fragment. An export-declaration has the declarative effects of its declaration, or its declaration-seq (if any), or module-import-declaration. An export-declaration does not establish a scope and its declaration or declaration-seq shall not contain an export-declaration or module-import-declaration.

Para 2:

A declaration is exported if it is
— a namespace-scope declaration declared within an export-declaration, or
— a module-import-declaration declared with the export keyword (10.3)within an export-declaration, or
— a namespace-definition that contains an exported declaration, or
— a declaration within a header unit (10.3) that introduces at least one name.

Para 3:

An exported declaration that is not a module-import-declaration shall declare at least one name. If the declaration is not within a header unit, it shall not declare a name with internal linkage.

Change [module.import] para 1 (10.3), as already modified by us033 & p1857

    export-keywordopt import-keyword module-name attribute-specifier-seqopt ;
    export-keywordopt import-keyword module-partition attribute-specifier-seqopt ;
    export-keywordopt import-keyword header-name attribute-specifier-seqopt ;
A module-import-declaration shall only appear at global namespace scope. In a module unit, all module-import-declarations and export-declarations exporting module-import-declarations, shall precede all other declarations in the declaration-seq of the translation-unit and of the private-module-fragment (if any). The optional attribute-specifier-seq appertains to the module-import-declaration.