tmp/tmpzqll2a3b/{from.md → to.md}
RENAMED
|
@@ -12,74 +12,80 @@ the first token of the *pp-import*) `export` is an identifier defined as
|
|
| 12 |
an object-like macro.
|
| 13 |
|
| 14 |
The preprocessing tokens after the `import` preprocessing token in the
|
| 15 |
`import` *control-line* are processed just as in normal text (i.e., each
|
| 16 |
identifier currently defined as a macro name is replaced by its
|
| 17 |
-
replacement list of preprocessing tokens).
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
*
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
If a *pp-import* is produced by source file inclusion (including by the
|
| 26 |
rewrite produced when a `#include` directive names an importable header)
|
| 27 |
while processing the *group* of a *module-file*, the program is
|
| 28 |
ill-formed.
|
| 29 |
|
| 30 |
In all three forms of *pp-import*, the `import` and `export` (if it
|
| 31 |
exists) preprocessing tokens are replaced by the *import-keyword* and
|
| 32 |
*export-keyword* preprocessing tokens respectively.
|
| 33 |
|
| 34 |
-
[*Note
|
| 35 |
removed at the end of phase 4. — *end note*]
|
| 36 |
|
| 37 |
Additionally, in the second form of *pp-import*, a *header-name* token
|
| 38 |
is formed as if the *header-name-tokens* were the *pp-tokens* of a
|
| 39 |
`#include` directive. The *header-name-tokens* are replaced by the
|
| 40 |
*header-name* token.
|
| 41 |
|
| 42 |
-
[*Note
|
| 43 |
preprocessor and later phases of translation. — *end note*]
|
| 44 |
|
| 45 |
Each `#define` directive encountered when preprocessing each translation
|
| 46 |
unit in a program results in a distinct *macro definition*.
|
| 47 |
|
| 48 |
-
[*Note
|
| 49 |
by a `#define` directive. Implementations providing mechanisms to
|
| 50 |
predefine additional macros are encouraged to not treat them as being
|
| 51 |
introduced by a `#define` directive. — *end note*]
|
| 52 |
|
| 53 |
-
|
| 54 |
-
translation unit
|
| 55 |
-
definition has at most one point of definition in each translation unit
|
| 56 |
-
and at most one point of undefinition, as follows:
|
| 57 |
|
| 58 |
- The *point of definition* of a macro definition within a translation
|
| 59 |
-
unit
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
- The *point of undefinition* of a macro definition within a translation
|
| 66 |
unit is the first point at which a `#undef` directive naming the macro
|
| 67 |
occurs after its point of definition, or the first point of macro
|
| 68 |
-
import of a
|
| 69 |
-
|
| 70 |
|
| 71 |
A macro directive is *active* at a source location if it has a point of
|
| 72 |
definition in that translation unit preceding the location, and does not
|
| 73 |
have a point of undefinition in that translation unit preceding the
|
| 74 |
location.
|
| 75 |
|
| 76 |
If a macro would be replaced or redefined, and multiple macro
|
| 77 |
definitions are active for that macro name, the active macro definitions
|
| 78 |
shall all be valid redefinitions of the same macro [[cpp.replace]].
|
| 79 |
|
| 80 |
-
[*Note
|
| 81 |
a particular macro definition is active. — *end note*]
|
| 82 |
|
| 83 |
[*Example 1*:
|
| 84 |
|
| 85 |
Importable header \`"a.h"\`
|
|
@@ -107,13 +113,35 @@ Importable header \`"c.h"\`
|
|
| 107 |
```
|
| 108 |
|
| 109 |
Importable header \`"d.h"\`
|
| 110 |
|
| 111 |
``` cpp
|
| 112 |
-
import "a.h"; // point of definition of #1, #2, and #3, point of undefinition of #1 in "d.h"
|
| 113 |
import "c.h"; // point of definition of #4 and #5 in "d.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
int a = Y; // OK, active macro definitions #2 and #4 are valid redefinitions
|
| 115 |
int c = Z; // error: active macro definitions #3 and #5 are not valid redefinitions of Z
|
| 116 |
```
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
— *end example*]
|
| 119 |
|
|
|
|
| 12 |
an object-like macro.
|
| 13 |
|
| 14 |
The preprocessing tokens after the `import` preprocessing token in the
|
| 15 |
`import` *control-line* are processed just as in normal text (i.e., each
|
| 16 |
identifier currently defined as a macro name is replaced by its
|
| 17 |
+
replacement list of preprocessing tokens).
|
| 18 |
+
|
| 19 |
+
[*Note 1*: An `import` directive matching the first two forms of a
|
| 20 |
+
*pp-import* instructs the preprocessor to import macros from the header
|
| 21 |
+
unit [[module.import]] denoted by the *header-name*, as described
|
| 22 |
+
below. — *end note*]
|
| 23 |
+
|
| 24 |
+
The *point of macro import* for the first two forms of *pp-import* is
|
| 25 |
+
immediately after the *new-line* terminating the *pp-import*. The last
|
| 26 |
+
form of *pp-import* is only considered if the first two forms did not
|
| 27 |
+
match, and does not have a point of macro import.
|
| 28 |
|
| 29 |
If a *pp-import* is produced by source file inclusion (including by the
|
| 30 |
rewrite produced when a `#include` directive names an importable header)
|
| 31 |
while processing the *group* of a *module-file*, the program is
|
| 32 |
ill-formed.
|
| 33 |
|
| 34 |
In all three forms of *pp-import*, the `import` and `export` (if it
|
| 35 |
exists) preprocessing tokens are replaced by the *import-keyword* and
|
| 36 |
*export-keyword* preprocessing tokens respectively.
|
| 37 |
|
| 38 |
+
[*Note 2*: This makes the line no longer a directive so it is not
|
| 39 |
removed at the end of phase 4. — *end note*]
|
| 40 |
|
| 41 |
Additionally, in the second form of *pp-import*, a *header-name* token
|
| 42 |
is formed as if the *header-name-tokens* were the *pp-tokens* of a
|
| 43 |
`#include` directive. The *header-name-tokens* are replaced by the
|
| 44 |
*header-name* token.
|
| 45 |
|
| 46 |
+
[*Note 3*: This ensures that imports are treated consistently by the
|
| 47 |
preprocessor and later phases of translation. — *end note*]
|
| 48 |
|
| 49 |
Each `#define` directive encountered when preprocessing each translation
|
| 50 |
unit in a program results in a distinct *macro definition*.
|
| 51 |
|
| 52 |
+
[*Note 4*: A predefined macro name [[cpp.predefined]] is not introduced
|
| 53 |
by a `#define` directive. Implementations providing mechanisms to
|
| 54 |
predefine additional macros are encouraged to not treat them as being
|
| 55 |
introduced by a `#define` directive. — *end note*]
|
| 56 |
|
| 57 |
+
Each macro definition has at most one point of definition in each
|
| 58 |
+
translation unit and at most one point of undefinition, as follows:
|
|
|
|
|
|
|
| 59 |
|
| 60 |
- The *point of definition* of a macro definition within a translation
|
| 61 |
+
unit T is
|
| 62 |
+
- if the `#define` directive of the macro definition occurs within T,
|
| 63 |
+
the point at which that directive occurs, or otherwise,
|
| 64 |
+
- if the macro name is not lexically identical to a keyword
|
| 65 |
+
[[lex.key]] or to the *identifier*s `module` or `import`, the first
|
| 66 |
+
point of macro import in T of a header unit containing a point of
|
| 67 |
+
definition for the macro definition, if any.
|
| 68 |
+
|
| 69 |
+
In the latter case, the macro is said to be *imported* from the header
|
| 70 |
+
unit.
|
| 71 |
- The *point of undefinition* of a macro definition within a translation
|
| 72 |
unit is the first point at which a `#undef` directive naming the macro
|
| 73 |
occurs after its point of definition, or the first point of macro
|
| 74 |
+
import of a header unit containing a point of undefinition for the
|
| 75 |
+
macro definition, whichever (if any) occurs first.
|
| 76 |
|
| 77 |
A macro directive is *active* at a source location if it has a point of
|
| 78 |
definition in that translation unit preceding the location, and does not
|
| 79 |
have a point of undefinition in that translation unit preceding the
|
| 80 |
location.
|
| 81 |
|
| 82 |
If a macro would be replaced or redefined, and multiple macro
|
| 83 |
definitions are active for that macro name, the active macro definitions
|
| 84 |
shall all be valid redefinitions of the same macro [[cpp.replace]].
|
| 85 |
|
| 86 |
+
[*Note 5*: The relative order of *pp-import*s has no bearing on whether
|
| 87 |
a particular macro definition is active. — *end note*]
|
| 88 |
|
| 89 |
[*Example 1*:
|
| 90 |
|
| 91 |
Importable header \`"a.h"\`
|
|
|
|
| 113 |
```
|
| 114 |
|
| 115 |
Importable header \`"d.h"\`
|
| 116 |
|
| 117 |
``` cpp
|
|
|
|
| 118 |
import "c.h"; // point of definition of #4 and #5 in "d.h"
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
Importable header \`"e.h"\`
|
| 122 |
+
|
| 123 |
+
``` cpp
|
| 124 |
+
import "a.h"; // point of definition of #1, #2, and #3, point of undefinition of #1 in "e.h"
|
| 125 |
+
import "d.h"; // point of definition of #4 and #5 in "e.h"
|
| 126 |
int a = Y; // OK, active macro definitions #2 and #4 are valid redefinitions
|
| 127 |
int c = Z; // error: active macro definitions #3 and #5 are not valid redefinitions of Z
|
| 128 |
```
|
| 129 |
|
| 130 |
+
Module unit \`f\`
|
| 131 |
+
|
| 132 |
+
``` cpp
|
| 133 |
+
export module f;
|
| 134 |
+
export import "a.h";
|
| 135 |
+
|
| 136 |
+
int a = Y; // OK
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
Translation unit \`#1\`
|
| 140 |
+
|
| 141 |
+
``` cpp
|
| 142 |
+
import f;
|
| 143 |
+
int x = Y; // error: Y is neither a defined macro nor a declared name
|
| 144 |
+
```
|
| 145 |
+
|
| 146 |
— *end example*]
|
| 147 |
|