[module.reach] (original) (raw)

10 Modules [module]

10.7 Reachability [module.reach]

A translation unit U isnecessarily reachablefrom a point P ifU is a module interface unit on which the translation unit containing Phas an interface dependency, or the translation unit containing P imports U, in either case prior to P ([module.import]).

[Note 1:

While module interface units are reachable even when they are only transitively imported via a non-exported import declaration, namespace-scope names from such module interface units are not found by name lookup ([basic.lookup]).

— _end note_]

All translation units that are necessarily reachable arereachable.

Additional translation units on which the point within the program has an interface dependency may be considered reachable, but it is unspecified which are and under what circumstances.88

[Note 2:

It is advisable to avoid depending on the reachability of any additional translation units in programs intending to be portable.

— _end note_]

A declaration D isreachable from a point P if

A declaration is reachableif it is reachable from any point in the instantiation context ([module.context]).

[Note 3:

Whether a declaration is exported has no bearing on whether it is reachable.

— _end note_]

The accumulated properties of all reachable declarations of an entity within a context determine the behavior of the entity within that context.

[Note 4:

These reachable semantic properties include type completeness, type definitions, initializers, default arguments of functions or template declarations, attributes, names bound, etc.

Since default arguments are evaluated in the context of the call expression, the reachable semantic properties of the corresponding parameter types apply in that context.

[Example 1:

Translation unit #1:export module M:A;export struct B;

Translation unit #2:module M:B;struct B { operator int();};

Translation unit #3:module M:C;import :A; B b1;

Translation unit #4:export module M;export import :A;import :B; B b2;export void f(B b = B());

Translation unit #5:import M; B b3; void g() { f(); } — _end example_]

— _end note_]

[Note 5:

Declarations of an entity can be reachable even where they cannot be found by name lookup.

— _end note_]

[Example 2:

Translation unit #1:export module A;struct X {};export using Y = X;

Translation unit #2:import A; Y y; X x; — _end example_]