From Jason Turner

[cpp.import]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp56dn0dq8/{from.md → to.md} +119 -0
tmp/tmp56dn0dq8/{from.md → to.md} RENAMED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Header unit importation <a id="cpp.import">[[cpp.import]]</a>
2
+
3
+ ``` bnf
4
+ pp-import:
5
+ exportₒₚₜ import header-name pp-tokensₒₚₜ ';' new-line
6
+ exportₒₚₜ import header-name-tokens pp-tokensₒₚₜ ';' new-line
7
+ exportₒₚₜ import pp-tokens ';' new-line
8
+ ```
9
+
10
+ A *pp-import* shall not appear in a context where `import` or (if it is
11
+ 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). An `import` directive
18
+ matching the first two forms of a *pp-import* instructs the preprocessor
19
+ to import macros from the header unit [[module.import]] denoted by the
20
+ *header-name*. The *point of macro import* for the first two forms of
21
+ *pp-import* is immediately after the *new-line* terminating the
22
+ *pp-import*. The last form of *pp-import* is only considered if the
23
+ first two forms did not match.
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 1*: This makes the line no longer a directive so it is not
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 2*: This ensures that imports are treated consistently by the
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 3*: A predefined macro name [[cpp.predefined]] is not introduced
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
+ Importing macros from a header unit makes macro definitions from a
54
+ translation unit visible in other translation units. Each macro
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 is the point at which its `#define` directive occurs (in the
60
+ translation unit containing the `#define` directive), or, if the macro
61
+ name is not lexically identical to a keyword [[lex.key]] or to the
62
+ *identifier*s `module` or `import`, the first point of macro import of
63
+ a translation unit containing a point of definition for the macro
64
+ definition, if any (in any other translation unit).
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 translation unit containing a point of undefinition for
69
+ the macro definition, whichever (if any) occurs first.
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 4*: The relative order of *pp-import*s has no bearing on whether
81
+ a particular macro definition is active. — *end note*]
82
+
83
+ [*Example 1*:
84
+
85
+ Importable header \`"a.h"\`
86
+
87
+ ``` cpp
88
+ #define X 123 // #1
89
+ #define Y 45 // #2
90
+ #define Z a // #3
91
+ #undef X // point of undefinition of #1 in "a.h"
92
+ ```
93
+
94
+ Importable header \`"b.h"\`
95
+
96
+ ``` cpp
97
+ import "a.h"; // point of definition of #1, #2, and #3, point of undefinition of #1 in "b.h"
98
+ #define X 456 // OK, #1 is not active
99
+ #define Y 6 // error: #2 is active
100
+ ```
101
+
102
+ Importable header \`"c.h"\`
103
+
104
+ ``` cpp
105
+ #define Y 45 // #4
106
+ #define Z c // #5
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
+