From Jason Turner

[module.interface]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmplcorbxes/{from.md → to.md} +246 -0
tmp/tmplcorbxes/{from.md → to.md} RENAMED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Export declaration <a id="module.interface">[[module.interface]]</a>
2
+
3
+ ``` bnf
4
+ export-declaration:
5
+ export declaration
6
+ export '{' declaration-seqₒₚₜ '}'
7
+ export-keyword module-import-declaration
8
+ ```
9
+
10
+ An *export-declaration* shall appear only at namespace scope and only in
11
+ the purview of a module interface unit. An *export-declaration* shall
12
+ not appear directly or indirectly within an unnamed namespace or a
13
+ *private-module-fragment*. An *export-declaration* has the declarative
14
+ effects of its *declaration*, *declaration-seq* (if any), or
15
+ *module-import-declaration*. An *export-declaration* does not establish
16
+ a scope and its *declaration* or *declaration-seq* shall not contain an
17
+ *export-declaration* or *module-import-declaration*.
18
+
19
+ A declaration is *exported* if it is
20
+
21
+ - a namespace-scope declaration declared within an *export-declaration*,
22
+ or
23
+ - a *namespace-definition* that contains an exported declaration, or
24
+ - a declaration within a header unit [[module.import]] that introduces
25
+ at least one name.
26
+
27
+ An exported declaration that is not a *module-import-declaration* shall
28
+ declare at least one name. If the declaration is not within a header
29
+ unit, it shall not declare a name with internal linkage.
30
+
31
+ [*Example 1*:
32
+
33
+ Source file \`"a.h"\`
34
+
35
+ ``` cpp
36
+ export int x;
37
+ ```
38
+
39
+ Translation unit #1
40
+
41
+ ``` cpp
42
+ module;
43
+ #include "a.h" // error: declaration of x is not in the
44
+ // purview of a module interface unit
45
+ export module M;
46
+ export namespace {} // error: does not introduce any names
47
+ export namespace {
48
+ int a1; // error: export of name with internal linkage
49
+ }
50
+ namespace {
51
+ export int a2; // error: export of name with internal linkage
52
+ }
53
+ export static int b; // error: b explicitly declared static
54
+ export int f(); // OK
55
+ export namespace N { } // OK
56
+ export using namespace N; // error: does not declare a name
57
+ ```
58
+
59
+ — *end example*]
60
+
61
+ If the declaration is a *using-declaration* [[namespace.udecl]] and is
62
+ not within a header unit, all entities to which all of the
63
+ *using-declarator*s ultimately refer (if any) shall have been introduced
64
+ with a name having external linkage.
65
+
66
+ [*Example 2*:
67
+
68
+ Source file \`"b.h"\`
69
+
70
+ ``` cpp
71
+ int f();
72
+ ```
73
+
74
+ Importable header \`"c.h"\`
75
+
76
+ ``` cpp
77
+ int g();
78
+ ```
79
+
80
+ Translation unit #1
81
+
82
+ ``` cpp
83
+ export module X;
84
+ export int h();
85
+ ```
86
+
87
+ Translation unit #2
88
+
89
+ ``` cpp
90
+ module;
91
+ #include "b.h"
92
+ export module M;
93
+ import "c.h";
94
+ import X;
95
+ export using ::f, ::g, ::h; // OK
96
+ struct S;
97
+ export using ::S; // error: S has module linkage
98
+ namespace N {
99
+ export int h();
100
+ static int h(int); // #1
101
+ }
102
+ export using N::h; // error: #1 has internal linkage
103
+ ```
104
+
105
+ — *end example*]
106
+
107
+ [*Note 1*:
108
+
109
+ These constraints do not apply to type names introduced by `typedef`
110
+ declarations and *alias-declaration*s.
111
+
112
+ [*Example 3*:
113
+
114
+ ``` cpp
115
+ export module M;
116
+ struct S;
117
+ export using T = S; // OK, exports name T denoting type S
118
+ ```
119
+
120
+ — *end example*]
121
+
122
+ — *end note*]
123
+
124
+ A redeclaration of an exported declaration of an entity is implicitly
125
+ exported. An exported redeclaration of a non-exported declaration of an
126
+ entity is ill-formed.
127
+
128
+ [*Example 4*:
129
+
130
+ ``` cpp
131
+ export module M;
132
+ struct S { int n; };
133
+ typedef S S;
134
+ export typedef S S; // OK, does not redeclare an entity
135
+ export struct S; // error: exported declaration follows non-exported declaration
136
+ ```
137
+
138
+ — *end example*]
139
+
140
+ A name is *exported* by a module if it is introduced or redeclared by an
141
+ exported declaration in the purview of that module.
142
+
143
+ [*Note 2*: Exported names have either external linkage or no linkage;
144
+ see [[basic.link]]. Namespace-scope names exported by a module are
145
+ visible to name lookup in any translation unit importing that module;
146
+ see [[basic.scope.namespace]]. Class and enumeration member names are
147
+ visible to name lookup in any context in which a definition of the type
148
+ is reachable. — *end note*]
149
+
150
+ [*Example 5*:
151
+
152
+ Interface unit of \`M\`
153
+
154
+ ``` cpp
155
+ export module M;
156
+ export struct X {
157
+ static void f();
158
+ struct Y { };
159
+ };
160
+
161
+ namespace {
162
+ struct S { };
163
+ }
164
+ export void f(S); // OK
165
+ struct T { };
166
+ export T id(T); // OK
167
+
168
+ export struct A; // A exported as incomplete
169
+
170
+ export auto rootFinder(double a) {
171
+ return [=](double x) { return (x + a/x)/2; };
172
+ }
173
+
174
+ export const int n = 5; // OK, n has external linkage
175
+ ```
176
+
177
+ Implementation unit of \`M\`
178
+
179
+ ``` cpp
180
+ module M;
181
+ struct A {
182
+ int value;
183
+ };
184
+ ```
185
+
186
+ Main program
187
+
188
+ ``` cpp
189
+ import M;
190
+ int main() {
191
+ X::f(); // OK, X is exported and definition of X is reachable
192
+ X::Y y; // OK, X::Y is exported as a complete type
193
+ auto f = rootFinder(2); // OK
194
+ return A{45}.value; // error: A is incomplete
195
+ }
196
+ ```
197
+
198
+ — *end example*]
199
+
200
+ [*Note 3*:
201
+
202
+ Redeclaring a name in an *export-declaration* cannot change the linkage
203
+ of the name [[basic.link]].
204
+
205
+ [*Example 6*:
206
+
207
+ Interface unit of \`M\`
208
+
209
+ ``` cpp
210
+ export module M;
211
+ static int f(); // #1
212
+ export int f(); // error: #1 gives internal linkage
213
+ struct S; // #2
214
+ export struct S; // error: #2 gives module linkage
215
+ namespace {
216
+ namespace N {
217
+ extern int x; // #3
218
+ }
219
+ }
220
+ export int N::x; // error: #3 gives internal linkage
221
+ ```
222
+
223
+ — *end example*]
224
+
225
+ — *end note*]
226
+
227
+ [*Note 4*:
228
+
229
+ Declarations in an exported *namespace-definition* or in an exported
230
+ *linkage-specification* [[dcl.link]] are exported and subject to the
231
+ rules of exported declarations.
232
+
233
+ [*Example 7*:
234
+
235
+ ``` cpp
236
+ export module M;
237
+ export namespace N {
238
+ int x; // OK
239
+ static_assert(1 == 1); // error: does not declare a name
240
+ }
241
+ ```
242
+
243
+ — *end example*]
244
+
245
+ — *end note*]
246
+