From Jason Turner

[module]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpyvc556an/{from.md → to.md} +109 -131
tmp/tmpyvc556an/{from.md → to.md} RENAMED
@@ -115,15 +115,19 @@ global module.
115
  is not introduced by any *module-declaration*. — *end note*]
116
 
117
  A *module* is either a named module or the global module. A declaration
118
  is *attached* to a module as follows:
119
 
120
- - If the declaration
121
- - is a replaceable global allocation or deallocation function (
122
- [[new.delete.single]], [[new.delete.array]]), or
123
- - is a *namespace-definition* with external linkage, or
124
- - appears within a *linkage-specification*,
 
 
 
 
125
 
126
  it is attached to the global module.
127
  - Otherwise, the declaration is attached to the module in whose purview
128
  it appears.
129
 
@@ -174,35 +178,38 @@ int &c = n; // OK
174
 
175
  ## Export declaration <a id="module.interface">[[module.interface]]</a>
176
 
177
  ``` bnf
178
  export-declaration:
179
- export declaration
180
  export '{' declaration-seqₒₚₜ '}'
181
  export-keyword module-import-declaration
182
  ```
183
 
184
- An *export-declaration* shall appear only at namespace scope and only in
185
  the purview of a module interface unit. An *export-declaration* shall
186
  not appear directly or indirectly within an unnamed namespace or a
187
  *private-module-fragment*. An *export-declaration* has the declarative
188
- effects of its *declaration*, *declaration-seq* (if any), or
189
- *module-import-declaration*. An *export-declaration* does not establish
190
- a scope and its *declaration* or *declaration-seq* shall not contain an
191
- *export-declaration* or *module-import-declaration*.
 
 
192
 
193
- A declaration is *exported* if it is
 
 
 
 
194
 
195
- - a namespace-scope declaration declared within an *export-declaration*,
196
- or
197
  - a *namespace-definition* that contains an exported declaration, or
198
  - a declaration within a header unit [[module.import]] that introduces
199
  at least one name.
200
 
201
- An exported declaration that is not a *module-import-declaration* shall
202
- declare at least one name. If the declaration is not within a header
203
- unit, it shall not declare a name with internal linkage.
204
 
205
  [*Example 1*:
206
 
207
  Source file \`"a.h"\`
208
 
@@ -215,27 +222,24 @@ Translation unit #1
215
  ``` cpp
216
  module;
217
  #include "a.h" // error: declaration of x is not in the
218
  // purview of a module interface unit
219
  export module M;
220
- export namespace {} // error: does not introduce any names
221
- export namespace {
222
- int a1; // error: export of name with internal linkage
223
- }
224
  namespace {
225
  export int a2; // error: export of name with internal linkage
226
  }
227
  export static int b; // error: b explicitly declared static
228
  export int f(); // OK
229
  export namespace N { } // OK
230
- export using namespace N; // error: does not declare a name
231
  ```
232
 
233
  — *end example*]
234
 
235
- If the declaration is a *using-declaration* [[namespace.udecl]] and is
236
- not within a header unit, all entities to which all of the
237
  *using-declarator*s ultimately refer (if any) shall have been introduced
238
  with a name having external linkage.
239
 
240
  [*Example 2*:
241
 
@@ -276,11 +280,11 @@ namespace N {
276
  export using N::h; // error: #1 has internal linkage
277
  ```
278
 
279
  — *end example*]
280
 
281
- [*Note 1*:
282
 
283
  These constraints do not apply to type names introduced by `typedef`
284
  declarations and *alias-declaration*s.
285
 
286
  [*Example 3*:
@@ -293,13 +297,13 @@ export using T = S; // OK, exports name T denoting type S
293
 
294
  — *end example*]
295
 
296
  — *end note*]
297
 
298
- A redeclaration of an exported declaration of an entity is implicitly
299
- exported. An exported redeclaration of a non-exported declaration of an
300
- entity is ill-formed.
301
 
302
  [*Example 4*:
303
 
304
  ``` cpp
305
  export module M;
@@ -309,19 +313,16 @@ export typedef S S; // OK, does not redeclare an entity
309
  export struct S; // error: exported declaration follows non-exported declaration
310
  ```
311
 
312
  — *end example*]
313
 
314
- A name is *exported* by a module if it is introduced or redeclared by an
315
- exported declaration in the purview of that module.
316
-
317
- [*Note 2*: Exported names have either external linkage or no linkage;
318
- see [[basic.link]]. Namespace-scope names exported by a module are
319
- visible to name lookup in any translation unit importing that module;
320
- see [[basic.scope.namespace]]. Class and enumeration member names are
321
- visible to name lookup in any context in which a definition of the type
322
- is reachable. — *end note*]
323
 
324
  [*Example 5*:
325
 
326
  Interface unit of \`M\`
327
 
@@ -369,50 +370,24 @@ int main() {
369
  }
370
  ```
371
 
372
  — *end example*]
373
 
374
- [*Note 3*:
375
-
376
- Redeclaring a name in an *export-declaration* cannot change the linkage
377
- of the name [[basic.link]].
378
-
379
- [*Example 6*:
380
-
381
- Interface unit of \`M\`
382
-
383
- ``` cpp
384
- export module M;
385
- static int f(); // #1
386
- export int f(); // error: #1 gives internal linkage
387
- struct S; // #2
388
- export struct S; // error: #2 gives module linkage
389
- namespace {
390
- namespace N {
391
- extern int x; // #3
392
- }
393
- }
394
- export int N::x; // error: #3 gives internal linkage
395
- ```
396
-
397
- — *end example*]
398
-
399
- — *end note*]
400
-
401
  [*Note 4*:
402
 
403
  Declarations in an exported *namespace-definition* or in an exported
404
  *linkage-specification* [[dcl.link]] are exported and subject to the
405
  rules of exported declarations.
406
 
407
- [*Example 7*:
408
 
409
  ``` cpp
410
  export module M;
 
411
  export namespace N {
412
  int x; // OK
413
- static_assert(1 == 1); // error: does not declare a name
414
  }
415
  ```
416
 
417
  — *end example*]
418
 
@@ -425,26 +400,26 @@ module-import-declaration:
425
  import-keyword module-name attribute-specifier-seqₒₚₜ ';'
426
  import-keyword module-partition attribute-specifier-seqₒₚₜ ';'
427
  import-keyword header-name attribute-specifier-seqₒₚₜ ';'
428
  ```
429
 
430
- A *module-import-declaration* shall only appear at global namespace
431
- scope. In a module unit, all *module-import-declaration*s and
432
  *export-declaration*s exporting *module-import-declaration*s shall
433
- precede all other *declaration*s in the *declaration-seq* of the
434
  *translation-unit* and of the *private-module-fragment* (if any). The
435
  optional *attribute-specifier-seq* appertains to the
436
  *module-import-declaration*.
437
 
438
  A *module-import-declaration* *imports* a set of translation units
439
  determined as described below.
440
 
441
- [*Note 1*: Namespace-scope names exported by the imported translation
442
- units become visible [[basic.scope.namespace]] in the importing
443
- translation unit and declarations within the imported translation units
444
- become reachable [[module.reach]] in the importing translation unit
445
- after the import declaration. — *end note*]
446
 
447
  A *module-import-declaration* that specifies a *module-name* `M` imports
448
  all module interface units of `M`.
449
 
450
  A *module-import-declaration* that specifies a *module-partition* shall
@@ -477,11 +452,12 @@ headers that includes all importable C++ library headers [[headers]].
477
  header. — *end note*]
478
 
479
  [*Note 4*: A *module-import-declaration* nominating a *header-name* is
480
  also recognized by the preprocessor, and results in macros defined at
481
  the end of phase 4 of translation of the header unit being made visible
482
- as described in [[cpp.import]]. *end note*]
 
483
 
484
  A declaration of a name with internal linkage is permitted within a
485
  header unit despite all declarations being implicitly exported
486
  [[module.interface]].
487
 
@@ -495,12 +471,19 @@ When a *module-import-declaration* imports a translation unit T, it also
495
  imports all translation units imported by exported
496
  *module-import-declaration*s in T; such translation units are said to be
497
  *exported* by T. Additionally, when a *module-import-declaration* in a
498
  module unit of some module M imports another module unit U of M, it also
499
  imports all translation units imported by non-exported
500
- *module-import-declaration*s in the module unit purview of U.[^1] These
501
- rules may in turn lead to the importation of yet more translation units.
 
 
 
 
 
 
 
502
 
503
  A module implementation unit shall not be exported.
504
 
505
  [*Example 1*:
506
 
@@ -585,30 +568,28 @@ translation unit if:
585
  - D does not declare a function or function template and S contains an
586
  *id-expression*, *namespace-name*, *type-name*, *template-name*, or
587
  *concept-name* naming D, or
588
  - D declares a function or function template that is named by an
589
  expression [[basic.def.odr]] appearing in S, or
590
- - S contains an expression `E` of the form
591
- ``` bnf
592
- postfix-expression '(' expression-listₒₚₜ ')'
593
- ```
594
-
595
- whose *postfix-expression* denotes a dependent name, or for an
596
- operator expression whose operator denotes a dependent name, and D is
597
- found by name lookup for the corresponding name in an expression
598
- synthesized from `E` by replacing each type-dependent argument or
599
- operand with a value of a placeholder type with no associated
600
- namespaces or entities, or
601
- - S contains an expression that takes the address of an overloaded
602
- function [[over.over]] whose set of overloads contains D and for which
603
- the target type is dependent, or
604
  - there exists a declaration M that is not a *namespace-definition* for
605
  which M is decl-reachable from S and either
606
  - D is decl-reachable from M, or
607
  - D redeclares the entity declared by M or M redeclares the entity
608
- declared by D, and D is neither a friend declaration nor a
609
- block-scope declaration, or
610
  - D declares a namespace N and M is a member of N, or
611
  - one of M and D declares a class or class template C and the other
612
  declares a member or friend of C, or
613
  - one of D and M declares an enumeration E and the other declares an
614
  enumerator of E, or
@@ -620,11 +601,11 @@ translation unit if:
620
  introduces a typedef name for linkage purposes for that type.
621
 
622
  In this determination, it is unspecified
623
 
624
  - whether a reference to an *alias-declaration*, `typedef` declaration,
625
- *using-declaration*, or *namespace-alias-declaration* is replaced by
626
  the declarations they name prior to this determination,
627
  - whether a *simple-template-id* that does not denote a dependent type
628
  and whose *template-name* names an alias template is replaced by its
629
  denoted type prior to this determination,
630
  - whether a *decltype-specifier* that does not denote a dependent type
@@ -634,11 +615,11 @@ In this determination, it is unspecified
634
 
635
  A declaration `D` in a global module fragment of a module unit is
636
  *discarded* if `D` is not decl-reachable from any *declaration* in the
637
  *declaration-seq* of the *translation-unit*.
638
 
639
- [*Note 2*: A discarded declaration is neither reachable nor visible to
640
  name lookup outside the module unit, nor in template instantiations
641
  whose points of instantiation [[temp.point]] are outside the module
642
  unit, even when the instantiation context [[module.context]] includes
643
  the module unit. — *end note*]
644
 
@@ -739,18 +720,18 @@ unit that can affect the behavior of other translation units. A
739
  *private-module-fragment* allows a module to be represented as a single
740
  translation unit without making all of the contents of the module
741
  reachable to importers. The presence of a *private-module-fragment*
742
  affects:
743
 
744
- - the point by which the definition of an exported inline function is
745
  required [[dcl.inline]],
746
  - the point by which the definition of an exported function with a
747
  placeholder return type is required [[dcl.spec.auto]],
748
  - whether a declaration is required not to be an exposure
749
  [[basic.link]],
750
- - where definitions for inline functions and templates must appear (
751
- [[basic.def.odr]], [[dcl.inline]], [[temp.pre]]),
752
  - the instantiation contexts of templates instantiated before it
753
  [[module.context]], and
754
  - the reachability of declarations within it [[module.reach]].
755
 
756
  — *end note*]
@@ -759,16 +740,15 @@ affects:
759
 
760
  ``` cpp
761
  export module A;
762
  export inline void fn_e(); // error: exported inline function fn_e not defined
763
  // before private module fragment
764
- inline void fn_m(); // OK, module-linkage inline function
765
  static void fn_s();
766
  export struct X;
767
  export void g(X *x) {
768
  fn_s(); // OK, call to static function in same translation unit
769
- fn_m(); // OK, call to module-linkage inline function
770
  }
771
  export X *factory(); // OK
772
 
773
  module :private;
774
  struct X {}; // definition not reachable from importers of A
@@ -783,19 +763,18 @@ void fn_s() {}
783
  — *end example*]
784
 
785
  ## Instantiation context <a id="module.context">[[module.context]]</a>
786
 
787
  The *instantiation context* is a set of points within the program that
788
- determines which names are visible to argument-dependent name lookup
789
- [[basic.lookup.argdep]] and which declarations are reachable
790
- [[module.reach]] in the context of a particular declaration or template
791
- instantiation.
792
 
793
- During the implicit definition of a defaulted function ([[special]],
794
- [[class.compare.default]]), the instantiation context is the union of
795
- the instantiation context from the definition of the class and the
796
- instantiation context of the program construct that resulted in the
797
  implicit definition of the defaulted function.
798
 
799
  During the implicit instantiation of a template whose point of
800
  instantiation is specified as that of an enclosing specialization
801
  [[temp.point]], the instantiation context is the union of the
@@ -867,11 +846,11 @@ comprises
867
 
868
  - the point at the end of translation unit \#1,
869
  - the point at the end of translation unit \#2, and
870
  - the point of the call to `f(0)`,
871
 
872
- so the definition of `X` is reachable ([[module.reach]]).
873
 
874
  It is unspecified whether the call to `g(0)` is valid: the instantiation
875
  context of `bar<int, X>` comprises
876
 
877
  - the point at the end of translation unit \#1,
@@ -886,34 +865,36 @@ so the definition of `X` need not be reachable, as described in
886
  ## Reachability <a id="module.reach">[[module.reach]]</a>
887
 
888
  A translation unit U is *necessarily reachable* from a point P if U is a
889
  module interface unit on which the translation unit containing P has an
890
  interface dependency, or the translation unit containing P imports U, in
891
- either case prior to P ([[module.import]]).
892
 
893
  [*Note 1*: While module interface units are reachable even when they
894
  are only transitively imported via a non-exported import declaration,
895
- namespace-scope names from such module interface units are not visible
896
- to name lookup [[basic.scope.namespace]]. — *end note*]
897
 
898
- All translation units that are necessarily reachable are *reachable*. It
899
- is unspecified whether additional translation units on which the point
900
- within the program has an interface dependency are considered reachable,
901
- and under what circumstances. [^3]
902
 
903
  [*Note 2*: It is advisable to avoid depending on the reachability of
904
  any additional translation units in programs intending to be
905
  portable. — *end note*]
906
 
907
- A declaration D is *reachable* if, for any point P in the instantiation
908
- context [[module.context]],
909
 
910
  - D appears prior to P in the same translation unit, or
911
  - D is not discarded [[module.global.frag]], appears in a translation
912
  unit that is reachable from P, and does not appear within a
913
  *private-module-fragment*.
914
 
 
 
 
915
  [*Note 3*: Whether a declaration is exported has no bearing on whether
916
  it is reachable. — *end note*]
917
 
918
  The accumulated properties of all reachable declarations of an entity
919
  within a context determine the behavior of the entity within that
@@ -921,14 +902,13 @@ context.
921
 
922
  [*Note 4*:
923
 
924
  These reachable semantic properties include type completeness, type
925
  definitions, initializers, default arguments of functions or template
926
- declarations, attributes, visibility of class or enumeration member
927
- names to ordinary lookup, etc. Since default arguments are evaluated in
928
- the context of the call expression, the reachable semantic properties of
929
- the corresponding parameter types apply in that context.
930
 
931
  [*Example 1*:
932
 
933
  Translation unit #1
934
 
@@ -965,22 +945,21 @@ export void f(B b = B());
965
  ```
966
 
967
  Translation unit #5
968
 
969
  ``` cpp
970
- module X;
971
  import M;
972
  B b3; // error: no reachable definition of struct B
973
  void g() { f(); } // error: no reachable definition of struct B
974
  ```
975
 
976
  — *end example*]
977
 
978
  — *end note*]
979
 
980
- [*Note 5*: An entity can have reachable declarations even if it is not
981
- visible to name lookup. — *end note*]
982
 
983
  [*Example 2*:
984
 
985
  Translation unit #1
986
 
@@ -991,23 +970,22 @@ export using Y = X;
991
  ```
992
 
993
  Translation unit #2
994
 
995
  ``` cpp
996
- module B;
997
  import A;
998
  Y y; // OK, definition of X is reachable
999
  X x; // error: X not visible to unqualified lookup
1000
  ```
1001
 
1002
  — *end example*]
1003
 
1004
  <!-- Link reference definitions -->
1005
  [basic.def.odr]: basic.md#basic.def.odr
1006
  [basic.link]: basic.md#basic.link
 
1007
  [basic.lookup.argdep]: basic.md#basic.lookup.argdep
1008
- [basic.scope.namespace]: basic.md#basic.scope.namespace
1009
  [class.compare.default]: class.md#class.compare.default
1010
  [cpp.import]: cpp.md#cpp.import
1011
  [cpp.include]: cpp.md#cpp.include
1012
  [cpp.pre]: cpp.md#cpp.pre
1013
  [dcl.inline]: dcl.md#dcl.inline
@@ -1023,19 +1001,19 @@ X x; // error: X not visible to unqualified lookup
1023
  [module.interface]: #module.interface
1024
  [module.private.frag]: #module.private.frag
1025
  [module.reach]: #module.reach
1026
  [module.unit]: #module.unit
1027
  [namespace.udecl]: dcl.md#namespace.udecl
1028
- [new.delete.array]: support.md#new.delete.array
1029
- [new.delete.single]: support.md#new.delete.single
1030
  [over.over]: over.md#over.over
1031
  [special]: class.md#special
 
 
1032
  [temp.point]: temp.md#temp.point
1033
  [temp.pre]: temp.md#temp.pre
1034
 
1035
- [^1]: This is consistent with the rules for visibility of imported names
1036
- [[basic.scope.namespace]].
1037
 
1038
  [^2]: A declaration can appear within a *lambda-expression* in the
1039
  initializer of a variable.
1040
 
1041
  [^3]: Implementations are therefore not required to prevent the semantic
 
115
  is not introduced by any *module-declaration*. — *end note*]
116
 
117
  A *module* is either a named module or the global module. A declaration
118
  is *attached* to a module as follows:
119
 
120
+ - If the declaration is a non-dependent friend declaration that
121
+ nominates a function with a *declarator-id* that is a *qualified-id*
122
+ or *template-id* or that nominates a class other than with an
123
+ *elaborated-type-specifier* with neither a *nested-name-specifier* nor
124
+ a *simple-template-id*, it is attached to the module to which the
125
+ friend is attached [[basic.link]].
126
+ - Otherwise, if the declaration
127
+ - is a *namespace-definition* with external linkage or
128
+ - appears within a *linkage-specification* [[dcl.link]]
129
 
130
  it is attached to the global module.
131
  - Otherwise, the declaration is attached to the module in whose purview
132
  it appears.
133
 
 
178
 
179
  ## Export declaration <a id="module.interface">[[module.interface]]</a>
180
 
181
  ``` bnf
182
  export-declaration:
183
+ export name-declaration
184
  export '{' declaration-seqₒₚₜ '}'
185
  export-keyword module-import-declaration
186
  ```
187
 
188
+ An *export-declaration* shall inhabit a namespace scope and appear in
189
  the purview of a module interface unit. An *export-declaration* shall
190
  not appear directly or indirectly within an unnamed namespace or a
191
  *private-module-fragment*. An *export-declaration* has the declarative
192
+ effects of its *name-declaration*, *declaration-seq* (if any), or
193
+ *module-import-declaration*. The *name-declaration* of an
194
+ *export-declaration* shall not declare a partial specialization
195
+ [[temp.decls.general]]. The *declaration-seq* of an *export-declaration*
196
+ shall not contain an *export-declaration* or
197
+ *module-import-declaration*.
198
 
199
+ [*Note 1*: An *export-declaration* does not establish a
200
+ scope. — *end note*]
201
+
202
+ A declaration is *exported* if it is declared within an
203
+ *export-declaration* and inhabits a namespace scope or it is
204
 
 
 
205
  - a *namespace-definition* that contains an exported declaration, or
206
  - a declaration within a header unit [[module.import]] that introduces
207
  at least one name.
208
 
209
+ If an exported declaration is not within a header unit, it shall not
210
+ declare a name with internal linkage.
 
211
 
212
  [*Example 1*:
213
 
214
  Source file \`"a.h"\`
215
 
 
222
  ``` cpp
223
  module;
224
  #include "a.h" // error: declaration of x is not in the
225
  // purview of a module interface unit
226
  export module M;
227
+ export namespace {} // error: namespace has internal linkage
 
 
 
228
  namespace {
229
  export int a2; // error: export of name with internal linkage
230
  }
231
  export static int b; // error: b explicitly declared static
232
  export int f(); // OK
233
  export namespace N { } // OK
234
+ export using namespace N; // OK
235
  ```
236
 
237
  — *end example*]
238
 
239
+ If an exported declaration is a *using-declaration* [[namespace.udecl]]
240
+ and is not within a header unit, all entities to which all of the
241
  *using-declarator*s ultimately refer (if any) shall have been introduced
242
  with a name having external linkage.
243
 
244
  [*Example 2*:
245
 
 
280
  export using N::h; // error: #1 has internal linkage
281
  ```
282
 
283
  — *end example*]
284
 
285
+ [*Note 2*:
286
 
287
  These constraints do not apply to type names introduced by `typedef`
288
  declarations and *alias-declaration*s.
289
 
290
  [*Example 3*:
 
297
 
298
  — *end example*]
299
 
300
  — *end note*]
301
 
302
+ A redeclaration of an entity X is implicitly exported if X was
303
+ introduced by an exported declaration; otherwise it shall not be
304
+ exported.
305
 
306
  [*Example 4*:
307
 
308
  ``` cpp
309
  export module M;
 
313
  export struct S; // error: exported declaration follows non-exported declaration
314
  ```
315
 
316
  — *end example*]
317
 
318
+ [*Note 3*: Names introduced by exported declarations have either
319
+ external linkage or no linkage; see [[basic.link]]. Namespace-scope
320
+ declarations exported by a module can be found by name lookup in any
321
+ translation unit importing that module [[basic.lookup]]. Class and
322
+ enumeration member names can be found by name lookup in any context in
323
+ which a definition of the type is reachable. *end note*]
 
 
 
324
 
325
  [*Example 5*:
326
 
327
  Interface unit of \`M\`
328
 
 
370
  }
371
  ```
372
 
373
  — *end example*]
374
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
375
  [*Note 4*:
376
 
377
  Declarations in an exported *namespace-definition* or in an exported
378
  *linkage-specification* [[dcl.link]] are exported and subject to the
379
  rules of exported declarations.
380
 
381
+ [*Example 6*:
382
 
383
  ``` cpp
384
  export module M;
385
+ int g;
386
  export namespace N {
387
  int x; // OK
388
+ using ::g; // error: ::g has module linkage
389
  }
390
  ```
391
 
392
  — *end example*]
393
 
 
400
  import-keyword module-name attribute-specifier-seqₒₚₜ ';'
401
  import-keyword module-partition attribute-specifier-seqₒₚₜ ';'
402
  import-keyword header-name attribute-specifier-seqₒₚₜ ';'
403
  ```
404
 
405
+ A *module-import-declaration* shall inhabit the global namespace scope.
406
+ In a module unit, all *module-import-declaration*s and
407
  *export-declaration*s exporting *module-import-declaration*s shall
408
+ appear before all other *declaration*s in the *declaration-seq* of the
409
  *translation-unit* and of the *private-module-fragment* (if any). The
410
  optional *attribute-specifier-seq* appertains to the
411
  *module-import-declaration*.
412
 
413
  A *module-import-declaration* *imports* a set of translation units
414
  determined as described below.
415
 
416
+ [*Note 1*: Namespace-scope declarations exported by the imported
417
+ translation units can be found by name lookup [[basic.lookup]] in the
418
+ importing translation unit and declarations within the imported
419
+ translation units become reachable [[module.reach]] in the importing
420
+ translation unit after the import declaration. — *end note*]
421
 
422
  A *module-import-declaration* that specifies a *module-name* `M` imports
423
  all module interface units of `M`.
424
 
425
  A *module-import-declaration* that specifies a *module-partition* shall
 
452
  header. — *end note*]
453
 
454
  [*Note 4*: A *module-import-declaration* nominating a *header-name* is
455
  also recognized by the preprocessor, and results in macros defined at
456
  the end of phase 4 of translation of the header unit being made visible
457
+ as described in [[cpp.import]]. Any other *module-import-declaration*
458
+ does not make macros visible. — *end note*]
459
 
460
  A declaration of a name with internal linkage is permitted within a
461
  header unit despite all declarations being implicitly exported
462
  [[module.interface]].
463
 
 
471
  imports all translation units imported by exported
472
  *module-import-declaration*s in T; such translation units are said to be
473
  *exported* by T. Additionally, when a *module-import-declaration* in a
474
  module unit of some module M imports another module unit U of M, it also
475
  imports all translation units imported by non-exported
476
+ *module-import-declaration*s in the module unit purview of U.[^1]
477
+
478
+ These rules can in turn lead to the importation of yet more translation
479
+ units.
480
+
481
+ [*Note 6*: Such indirect importation does not make macros available,
482
+ because a translation unit is a sequence of tokens in translation phase
483
+ 7 [[lex.phases]]. Macros can be made available by directly importing
484
+ header units as described in [[cpp.import]]. — *end note*]
485
 
486
  A module implementation unit shall not be exported.
487
 
488
  [*Example 1*:
489
 
 
568
  - D does not declare a function or function template and S contains an
569
  *id-expression*, *namespace-name*, *type-name*, *template-name*, or
570
  *concept-name* naming D, or
571
  - D declares a function or function template that is named by an
572
  expression [[basic.def.odr]] appearing in S, or
573
+ - S contains a dependent call `E` [[temp.dep]] and D is found by any
574
+ name lookup performed for an expression synthesized from `E` by
575
+ replacing each type-dependent argument or operand with a value of a
576
+ placeholder type with no associated namespaces or entities, or
577
+ \[*Note 2*: This includes the lookup for `operator==` performed when
578
+ considering rewriting an `!=` expression, the lookup for `operator<=>`
579
+ performed when considering rewriting a relational comparison, and the
580
+ lookup for `operator!=` when considering whether an `operator==` is a
581
+ rewrite target. *end note*]
582
+ - S contains an expression that takes the address of an overload set
583
+ [[over.over]] that contains D and for which the target type is
584
+ dependent, or
 
 
585
  - there exists a declaration M that is not a *namespace-definition* for
586
  which M is decl-reachable from S and either
587
  - D is decl-reachable from M, or
588
  - D redeclares the entity declared by M or M redeclares the entity
589
+ declared by D, and D neither is a friend declaration nor inhabits a
590
+ block scope, or
591
  - D declares a namespace N and M is a member of N, or
592
  - one of M and D declares a class or class template C and the other
593
  declares a member or friend of C, or
594
  - one of D and M declares an enumeration E and the other declares an
595
  enumerator of E, or
 
601
  introduces a typedef name for linkage purposes for that type.
602
 
603
  In this determination, it is unspecified
604
 
605
  - whether a reference to an *alias-declaration*, `typedef` declaration,
606
+ *using-declaration*, or *namespace-alias-definition* is replaced by
607
  the declarations they name prior to this determination,
608
  - whether a *simple-template-id* that does not denote a dependent type
609
  and whose *template-name* names an alias template is replaced by its
610
  denoted type prior to this determination,
611
  - whether a *decltype-specifier* that does not denote a dependent type
 
615
 
616
  A declaration `D` in a global module fragment of a module unit is
617
  *discarded* if `D` is not decl-reachable from any *declaration* in the
618
  *declaration-seq* of the *translation-unit*.
619
 
620
+ [*Note 3*: A discarded declaration is neither reachable nor visible to
621
  name lookup outside the module unit, nor in template instantiations
622
  whose points of instantiation [[temp.point]] are outside the module
623
  unit, even when the instantiation context [[module.context]] includes
624
  the module unit. — *end note*]
625
 
 
720
  *private-module-fragment* allows a module to be represented as a single
721
  translation unit without making all of the contents of the module
722
  reachable to importers. The presence of a *private-module-fragment*
723
  affects:
724
 
725
+ - the point by which the definition of an inline function or variable is
726
  required [[dcl.inline]],
727
  - the point by which the definition of an exported function with a
728
  placeholder return type is required [[dcl.spec.auto]],
729
  - whether a declaration is required not to be an exposure
730
  [[basic.link]],
731
+ - where definitions for inline functions and templates must appear
732
+ [[basic.def.odr]], [[dcl.inline]], [[temp.pre]],
733
  - the instantiation contexts of templates instantiated before it
734
  [[module.context]], and
735
  - the reachability of declarations within it [[module.reach]].
736
 
737
  — *end note*]
 
740
 
741
  ``` cpp
742
  export module A;
743
  export inline void fn_e(); // error: exported inline function fn_e not defined
744
  // before private module fragment
745
+ inline void fn_m(); // error: non-exported inline function fn_m not defined
746
  static void fn_s();
747
  export struct X;
748
  export void g(X *x) {
749
  fn_s(); // OK, call to static function in same translation unit
 
750
  }
751
  export X *factory(); // OK
752
 
753
  module :private;
754
  struct X {}; // definition not reachable from importers of A
 
763
  — *end example*]
764
 
765
  ## Instantiation context <a id="module.context">[[module.context]]</a>
766
 
767
  The *instantiation context* is a set of points within the program that
768
+ determines which declarations are found by argument-dependent name
769
+ lookup [[basic.lookup.argdep]] and which are reachable [[module.reach]]
770
+ in the context of a particular declaration or template instantiation.
 
771
 
772
+ During the implicit definition of a defaulted function
773
+ [[special]], [[class.compare.default]], the instantiation context is the
774
+ union of the instantiation context from the definition of the class and
775
+ the instantiation context of the program construct that resulted in the
776
  implicit definition of the defaulted function.
777
 
778
  During the implicit instantiation of a template whose point of
779
  instantiation is specified as that of an enclosing specialization
780
  [[temp.point]], the instantiation context is the union of the
 
846
 
847
  - the point at the end of translation unit \#1,
848
  - the point at the end of translation unit \#2, and
849
  - the point of the call to `f(0)`,
850
 
851
+ so the definition of `X` is reachable [[module.reach]].
852
 
853
  It is unspecified whether the call to `g(0)` is valid: the instantiation
854
  context of `bar<int, X>` comprises
855
 
856
  - the point at the end of translation unit \#1,
 
865
  ## Reachability <a id="module.reach">[[module.reach]]</a>
866
 
867
  A translation unit U is *necessarily reachable* from a point P if U is a
868
  module interface unit on which the translation unit containing P has an
869
  interface dependency, or the translation unit containing P imports U, in
870
+ either case prior to P [[module.import]].
871
 
872
  [*Note 1*: While module interface units are reachable even when they
873
  are only transitively imported via a non-exported import declaration,
874
+ namespace-scope names from such module interface units are not found by
875
+ name lookup [[basic.lookup]]. — *end note*]
876
 
877
+ All translation units that are necessarily reachable are *reachable*.
878
+ Additional translation units on which the point within the program has
879
+ an interface dependency may be considered reachable, but it is
880
+ unspecified which are and under what circumstances.[^3]
881
 
882
  [*Note 2*: It is advisable to avoid depending on the reachability of
883
  any additional translation units in programs intending to be
884
  portable. — *end note*]
885
 
886
+ A declaration D is *reachable from* a point P if
 
887
 
888
  - D appears prior to P in the same translation unit, or
889
  - D is not discarded [[module.global.frag]], appears in a translation
890
  unit that is reachable from P, and does not appear within a
891
  *private-module-fragment*.
892
 
893
+ A declaration is *reachable* if it is reachable from any point in the
894
+ instantiation context [[module.context]].
895
+
896
  [*Note 3*: Whether a declaration is exported has no bearing on whether
897
  it is reachable. — *end note*]
898
 
899
  The accumulated properties of all reachable declarations of an entity
900
  within a context determine the behavior of the entity within that
 
902
 
903
  [*Note 4*:
904
 
905
  These reachable semantic properties include type completeness, type
906
  definitions, initializers, default arguments of functions or template
907
+ declarations, attributes, names bound, etc. Since default arguments are
908
+ evaluated in the context of the call expression, the reachable semantic
909
+ properties of the corresponding parameter types apply in that context.
 
910
 
911
  [*Example 1*:
912
 
913
  Translation unit #1
914
 
 
945
  ```
946
 
947
  Translation unit #5
948
 
949
  ``` cpp
 
950
  import M;
951
  B b3; // error: no reachable definition of struct B
952
  void g() { f(); } // error: no reachable definition of struct B
953
  ```
954
 
955
  — *end example*]
956
 
957
  — *end note*]
958
 
959
+ [*Note 5*: Declarations of an entity can be reachable even where they
960
+ cannot be found by name lookup. — *end note*]
961
 
962
  [*Example 2*:
963
 
964
  Translation unit #1
965
 
 
970
  ```
971
 
972
  Translation unit #2
973
 
974
  ``` cpp
 
975
  import A;
976
  Y y; // OK, definition of X is reachable
977
  X x; // error: X not visible to unqualified lookup
978
  ```
979
 
980
  — *end example*]
981
 
982
  <!-- Link reference definitions -->
983
  [basic.def.odr]: basic.md#basic.def.odr
984
  [basic.link]: basic.md#basic.link
985
+ [basic.lookup]: basic.md#basic.lookup
986
  [basic.lookup.argdep]: basic.md#basic.lookup.argdep
 
987
  [class.compare.default]: class.md#class.compare.default
988
  [cpp.import]: cpp.md#cpp.import
989
  [cpp.include]: cpp.md#cpp.include
990
  [cpp.pre]: cpp.md#cpp.pre
991
  [dcl.inline]: dcl.md#dcl.inline
 
1001
  [module.interface]: #module.interface
1002
  [module.private.frag]: #module.private.frag
1003
  [module.reach]: #module.reach
1004
  [module.unit]: #module.unit
1005
  [namespace.udecl]: dcl.md#namespace.udecl
 
 
1006
  [over.over]: over.md#over.over
1007
  [special]: class.md#special
1008
+ [temp.decls.general]: temp.md#temp.decls.general
1009
+ [temp.dep]: temp.md#temp.dep
1010
  [temp.point]: temp.md#temp.point
1011
  [temp.pre]: temp.md#temp.pre
1012
 
1013
+ [^1]: This is consistent with the lookup rules for imported names
1014
+ [[basic.lookup]].
1015
 
1016
  [^2]: A declaration can appear within a *lambda-expression* in the
1017
  initializer of a variable.
1018
 
1019
  [^3]: Implementations are therefore not required to prevent the semantic