10 Modules [module]

10.3 Import declaration [module.import]

module-import-declaration:
	export import module-name attribute-specifier-seq ;
	export import module-partition attribute-specifier-seq ;
	export import header-name attribute-specifier-seq ;
In a module unit, all module-import-declarations shall precede all other top-level-declarations in the top-level-declaration-seq of the translation-unit and of the private-module-fragment (if any).
A module-import-declaration imports a set of translation units determined as described below.
[Note
:
Namespace-scope names exported by the imported translation units become visible ([basic.scope.namespace]) in the importing translation unit and declarations within the imported translation units become reachable ([module.reach]) in the importing translation unit after the import declaration.
end note
]
A module-import-declaration that specifies a module-name M imports all module interface units of M.
A module-import-declaration that specifies a module-partition shall only appear after the module-declaration in a module unit of some module M.
Such a declaration imports the so-named module partition of M.
A module-import-declaration that specifies a header-name H imports a synthesized header unit, which is a translation unit formed by applying phases 1 to 7 of translation ([lex.phases]) to the source file or header nominated by H, which shall not contain a module-declaration.
[Note
:
All declarations within a header unit are implicitly exported ([module.interface]), and are attached to the global module ([module.unit]).
end note
]
An importable header is a member of an implementation-defined set of headers.
H shall identify an importable header.
Two module-import-declarations import the same header unit if and only if their header-names identify the same header or source file ([cpp.include]).
[Note
:
A module-import-declaration nominating a header-name is also recognized by the preprocessor, and results in macros defined at the end of phase 4 of translation of the header unit being made visible as described in [cpp.module].
end note
]
A declaration of a name with internal linkage is permitted within a header unit despite all declarations being implicitly exported ([module.interface]).
If such a declaration declares an entity that is odr-used outside the header unit, or by a template instantiation whose point of instantiation is outside the header unit, the program is ill-formed.
When a module-import-declaration imports a translation unit T, it also imports all translation units imported by exported module-import-declarations in T; such translation units are said to be exported by T.
When a module-import-declaration in a module unit imports another module unit of the same module, it also imports all translation units imported by all module-import-declarations in that module unit.
These rules may in turn lead to the importation of yet more translation units.
A module implementation unit shall not be exported.
[Example
:

Translation unit #1:

module M:Part;

Translation unit #2:

export module M;
export import :Part;    // error: exported partition :Part is an implementation unit
end example
]
A module implementation unit of a module M that is not a module partition shall not contain a module-import-declaration nominating M.
[Example
:
module M;
import M;               // error: cannot import M in its own unit
end example
]
A translation unit has an interface dependency on a module unit U if it contains a module-declaration or module-import-declaration that imports U or if it has an interface dependency on a module unit that has an interface dependency on U.
A translation unit shall not have an interface dependency on itself.
[Example
:

Interface unit of M1:

export module M1;
import M2;

Interface unit of M2:

export module M2;
import M3;

Interface unit of M3:

export module M3;
import M1;              // error: cyclic interface dependency 
end example
]