User:Ybab321/Modules

Changes
To do/check:
 * lex.phases.1.7 / translation phase 7: It is implementation-defined whether the sources for module units and header units on which the current translation unit has an interface dependency
 * lex.pptoken.3.3: Header names can be formed in s (also has-include expressions)
 * lex.name / keyword / module / import: and  are special identifiers
 * lex.key.1 / export: is no longer unused
 * basic.def.odr.1 / ODR: A variable/function/class/enum/template can be defined multiple times provided previous definitions are not necessarily reachable
 * basic.def.odr.11: Inline function definitions are only required to be reachable
 * basic.def.odr.12: Class definitions are only required to be reachable
 * basic.def.odr.13: Inline definitions can be appear multiple times provided previous definitions are not necessarily reachable
 * basic.scope.namespace.2 / namespace scope: The potential scope of declarations (with non-internal linkage) made in a namespace in an imported module includes the same namespace in the importing TU after the module import statement
 * basic.lookup.argdep.4 / ADL: Friend function (templates) are visible only if their definition is reachable in set of associated entities
 * basic.lookup.argdep.4: ADL for an associated namespace is extended to declarations in named modules interfaces that associated entities are attached to
 * basic.lookup.argdep.4: For dependent names, ADL for an associated namespace is extended to declarations visible to qualified name lookup in the same translation unit in a named module (with non-internal linkage) at any point in the instantiation context of the lookup
 * namespace.qual.2: / namespace members The initial namespace-qualified lookup set only includes declarations whose potential scope would include the namespace in which the name is declared at the location of the
 * basic.link.1 / linkage: Translation units are now structured by module fragments
 * basic.link.1: Note that a private module fragment may only be declared in a primary module interface unit, and must be the only unit of its module
 * basic.link.1: Note that a / statement is a except for when  follows the / token
 * basic.link.2: Named entities with module linkage can be referred to by names from other scopes of the same module unit or scopes of other module units of the same module
 * basic.link.3: Namespace scope non-inline non-template non-volatile const variable names aren't internal linkage if exported
 * basic.link.4: Namespace scope names that aren't internal linkage that are attached o a named module and aren't exported have module linkage
 * basic.link.6: Block scope function and extern variable names attached to a named module is ill-formed
 * basic.link.10: The same name in different scopes that have external or module linkage denote the same thing only if declared in declarations attached to the same module
 * basic.link.11: Multiple declarations of the same name with external linkage declaring the same entity but attached to different modules is ill-formed no diagnostic required
 * basic.link.11: A declaration that would redeclare a reachable declaration attached to a different module is ill-formed
 * basic.link.11: Declarations of an entity are attached to the same module and the entity is said to be attached to that module
 * basic.start.main.1 / cpp/language/main_function: The main function shall is required to be attached to the global module
 * basic.start.main.3: Declaring a function at global scope attached to a named module is ill-formed
 * dcl.inline.6 / inline specifier: Inline functions/variables need only have a definition reachable from the end of TUs that ODR-use them
 * dcl.inline.6: Module linkage has the properties external linkage w.r.t. the inline specifier
 * dcl.inline.7: An exported inline function/variable is required to be defined in the TU containing its exported declaration outside the
 * dcl.spec.auto.9 / return type deduction: An exported function with placeholder return type is required to be defined in the TU containing its exported declaration outside the
 * basic.namespace.2 / namespace: Namespace names with external linkage are exported if any of its definitions are exported or if it contains any export declarations
 * basic.namespace.2: Namespaces are never attached to a module and never have module linkage
 * temp.4 / templates: Can't have a template export declaration
 * temp.point.7/8 / binding rules: Extra points of instantiation of template specialisations are now the point before the and the end of the translation unit
 * cpp.include.6 / include: Implementations are permitted to replace s of importable headers with s
 * module
 * cpp.module
 * cpp.glob.frag
 * dcl.typedef: P1766: C style structs must now be C compatible

Done:
 * basic.def.odr.13.7 / ODR inline definition rule: does not apply to definitions attached to a named module

Syntax
@1@ Primary module interface unit declaration. Declares a module unit that can provide export declarations and can be imported from outside the named module. @2@ Module partition interface unit declaration. Declares a part of a module that can provide export declarations and can be imported by another module unit within the named module. @3@ Module implementation unit declaration. Declares a module unit that cannot be exported or imported. Implicitly imports (and cannot explicitly do so). @4@ Module partition implementation unit declaration. Declares a part of a module that cannot be exported or imported. @5@ Global module fragment declaration. Declares the part of a module unit that is part of the global module.

Explanation
A is a translation unit that contains a module declaration. A is a collection of  with the same, except for any. The global module is the collection of translation units that are not and the collection of  in.

All declarations are attached to a if they are declared in one except: Otherwise, declarations are attached to the global module.
 * Replaceable global allocation/deallocation function declarations
 * Namespace definitions with external linkage
 * Declarations in a language specification

Explanation
An export declaration has the declarative effect of its declaration(s) and additionally exports any declarations that:
 * are listed in the export declaration and have namespace scope, or
 * are namespace definitions that contain an exported declaration, or
 * are a declaration in a header unit that introduces at least one name.

Namespace scope names exported by a module are visible to name lookup in any translation unit importing that module. Class and enum member names are visible to name lookup in any context in which a definition of the type is reachable. Exported names have either external linkage or no linkage.

Unless in a header unit:
 * Names with internal linkage cannot be exported
 * Entities referred to by exported using declarations must have external linkage (not to be confused with type alias declarations)

If an export declaration redeclares an entity:
 * That entity must have been previously exported
 * The declaration cannot change the name of the entity's linkage

If a namespace definitions or language linkage specification is directly exported, declarations in its body are subject to the rules of exported declarations.

Syntax
@1@ Module import declaration. Imports all module interface units of the named module. @2@ Module partition import declaration. Imports the named module interface partition of the module unit in which the declaration appears. @3@ Header unit import declaration. Imports a synthesized header unit corresponding to the named header (or source file) if that header is importable.

Explanation
An import declarations imports a set of translation units, meaning names from other translation units are introduced into the importing translation unit, in particular:
 * Namespace scope names exported by imported translation units become visible
 * All declarations within the imported translation units become reachable

Import declarations can only be declared at global namespace scope. If an import declaration (including exported import declarations) is in a module unit, it must be declared before any non-import declarations in the translation unit and before any private module fragment.

A synthesized header unit is a translation unit formed by applying translation phases 1 to 7 to an importable header and exporting every declaration as attached to the global module. Importable headers cannot contain a module declaration, any non-inline functions, nor a variable whose name has external linkage; however, declarations of names with internal linkage are permitted and exported. All C++ standard library headers are importable except the C++ adaptations of C headers (,, etc.), otherwise it is implementation defined if a header is importable. If a is imported multiple times within the same translation unit, they import the same header unit, it is unspecified if a  imported by different translation units imports the same header unit (different s always import different header units).

All translation units imported by an imported translation unit, or by an a non-exported import declaration in another imported module unit of the same module, are imported transitively.

A translation unit has an on a translation unit  if it directly contains a declaration that imports  or if transitively it has an interface dependency on a translation unit that has an interface dependency on U. A translation unit cannot have an interface dependency on itself.

Misc.
A declaration D is from a declaration S in the same TU if any of the following:
 * S contains an id expression or namespace/type/template/concept name naming D and D is not a function (template) declaration
 * S contains an expression that names D and D is a function (template) declaration
 * S contains an expression E of the form   , where  either:
 * denotes a dependent name or
 * is an operator expression whose operator denotes a dependent name,
 * and D is found by name lookup for the corresponding name in an expression synthesized from E replacing each type-dependent argument/operand with a value of a placeholder type (auto) with no associated namespaces or entities


 * S contains an expression that takes the address of an overloaded function whose set of overloads contains D and for which the target type is dependent
 * There exists a declaration M that is from S, that is not a namespace definition, and any of the following:
 * D is from M (direct transitivity)
 * One of D and M redeclares the entity declared by the other, and D is neither a friend nor block-scope declaration (forward declaration transitivity)
 * D declares a namespace that M is a member of (namespace transitivity)
 * One of D and M declares a class (template) C and the other declares a member or friend of C (class transitivity)
 * One of D and M declares an enumeration E and the other declares an enumerator of E (enum transitivity)
 * D declares a function or variable and M is declared in D (including in the body of a lambda) (function transitivity)
 * One of D and M declares a template and the other declares specialization or instantiation of that template (template transitivity)
 * One of D and M declares a class or enumeration type and the other introduces a typedef name for linkage purposes for that type (C-style struct transitivity)