[module.unit] (original) (raw)
10 Modules [module]
10.1 Module units and purviews [module.unit]
A module unit is a translation unit that contains a module-declaration.
A named module is the collection of module units with the same module-name.
The identifiers module and importshall not appear as identifier_s_in a module-name or module-partition.
All module-names either beginning with an identifierconsisting of std followed by zero or more digits or containing a reserved identifier ([lex.name]) are reserved and shall not be specified in a module-declaration; no diagnostic is required.
If any identifier in a reserved module-nameis a reserved identifier, the module name is reserved for use by C++ implementations; otherwise it is reserved for future standardization.
A module interface unit is a module unit whosemodule-declaration starts with export-keyword; any other module unit is a module implementation unit.
A named module shall contain exactly one module interface unit with no module-partition, known as theprimary module interface unit of the module; no diagnostic is required.
A module partition is a module unit whose module-declaration contains a module-partition.
A named module shall not contain multiple module partitions with the same module-partition.
All module partitions of a module that are module interface units shall be directly or indirectly exported by the primary module interface unit ([module.import]).
No diagnostic is required for a violation of these rules.
[Note 1:
Module partitions can be imported only by other module units in the same module.
The division of a module into module units is not visible outside the module.
— _end note_]
[Example 1:
Translation unit #1:export module A;export import :Foo;export int baz();
Translation unit #2:export module A:Foo;import :Internals;export int foo() { return 2 * (bar() + 1); }
Translation unit #3:module A:Internals;int bar();
Translation unit #4:module A;import :Internals;int bar() { return baz() - 10; } int baz() { return 30; }
Module A contains four translation units:
- a primary module interface unit,
- a module partition A:Foo, which is a module interface unit forming part of the interface of module A,
- a module partition A:Internals, which does not contribute to the external interface of module A, and
- a module implementation unit providing a definition of bar and baz, which cannot be imported because it does not have a partition name.
— _end example_]
A module unit purview is the sequence of token_s_starting at the module-declarationand extending to the end of the translation unit.
The purviewof a named module M is the set of module unit purviews of M's module units.
The global module is the collection of allglobal-module-fragment_s_and all translation units that are not module units.
Declarations appearing in such a context are said to be in the purview of the global module.
[Note 2:
The global module has no name, no module interface unit, and is not introduced by any module-declaration.
— _end note_]
A module is either a named module or the global module.
A declaration is attached to a module as follows:
- Otherwise, the declaration is attached to the module in whose purview it appears.
A module-declarationthat contains neither an _export-keyword_nor a module-partitionimplicitly imports the primary module interface unit of the module as if by a module-import-declaration.
[Example 2:
Translation unit #1:module B:Y; int y();
Translation unit #2:export module B;import :Y; int n = y();
Translation unit #3:module B:X1; int &a = n;
Translation unit #4:module B:X2; import B;int &b = n;
Translation unit #5:module B; int &c = n; — _end example_]