tmp/tmpxlnyqwe6/{from.md → to.md}
RENAMED
|
@@ -1,34 +1,37 @@
|
|
| 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
|
| 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*.
|
| 16 |
-
|
| 17 |
-
*
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 28 |
-
declare
|
| 29 |
-
unit, it shall not declare a name with internal linkage.
|
| 30 |
|
| 31 |
[*Example 1*:
|
| 32 |
|
| 33 |
Source file \`"a.h"\`
|
| 34 |
|
|
@@ -41,27 +44,24 @@ Translation unit #1
|
|
| 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:
|
| 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; //
|
| 57 |
```
|
| 58 |
|
| 59 |
— *end example*]
|
| 60 |
|
| 61 |
-
If
|
| 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 |
|
|
@@ -102,11 +102,11 @@ namespace N {
|
|
| 102 |
export using N::h; // error: #1 has internal linkage
|
| 103 |
```
|
| 104 |
|
| 105 |
— *end example*]
|
| 106 |
|
| 107 |
-
[*Note
|
| 108 |
|
| 109 |
These constraints do not apply to type names introduced by `typedef`
|
| 110 |
declarations and *alias-declaration*s.
|
| 111 |
|
| 112 |
[*Example 3*:
|
|
@@ -119,13 +119,13 @@ export using T = S; // OK, exports name T denoting type S
|
|
| 119 |
|
| 120 |
— *end example*]
|
| 121 |
|
| 122 |
— *end note*]
|
| 123 |
|
| 124 |
-
A redeclaration of an
|
| 125 |
-
|
| 126 |
-
|
| 127 |
|
| 128 |
[*Example 4*:
|
| 129 |
|
| 130 |
``` cpp
|
| 131 |
export module M;
|
|
@@ -135,19 +135,16 @@ 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 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 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 |
|
|
@@ -195,50 +192,24 @@ int main() {
|
|
| 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
|
| 234 |
|
| 235 |
``` cpp
|
| 236 |
export module M;
|
|
|
|
| 237 |
export namespace N {
|
| 238 |
int x; // OK
|
| 239 |
-
|
| 240 |
}
|
| 241 |
```
|
| 242 |
|
| 243 |
— *end example*]
|
| 244 |
|
|
|
|
| 1 |
## Export declaration <a id="module.interface">[[module.interface]]</a>
|
| 2 |
|
| 3 |
``` bnf
|
| 4 |
export-declaration:
|
| 5 |
+
export name-declaration
|
| 6 |
export '{' declaration-seqₒₚₜ '}'
|
| 7 |
export-keyword module-import-declaration
|
| 8 |
```
|
| 9 |
|
| 10 |
+
An *export-declaration* shall inhabit a namespace scope and appear 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 *name-declaration*, *declaration-seq* (if any), or
|
| 15 |
+
*module-import-declaration*. The *name-declaration* of an
|
| 16 |
+
*export-declaration* shall not declare a partial specialization
|
| 17 |
+
[[temp.decls.general]]. The *declaration-seq* of an *export-declaration*
|
| 18 |
+
shall not contain an *export-declaration* or
|
| 19 |
+
*module-import-declaration*.
|
| 20 |
|
| 21 |
+
[*Note 1*: An *export-declaration* does not establish a
|
| 22 |
+
scope. — *end note*]
|
| 23 |
+
|
| 24 |
+
A declaration is *exported* if it is declared within an
|
| 25 |
+
*export-declaration* and inhabits a namespace scope or it is
|
| 26 |
|
|
|
|
|
|
|
| 27 |
- a *namespace-definition* that contains an exported declaration, or
|
| 28 |
- a declaration within a header unit [[module.import]] that introduces
|
| 29 |
at least one name.
|
| 30 |
|
| 31 |
+
If an exported declaration is not within a header unit, it shall not
|
| 32 |
+
declare a name with internal linkage.
|
|
|
|
| 33 |
|
| 34 |
[*Example 1*:
|
| 35 |
|
| 36 |
Source file \`"a.h"\`
|
| 37 |
|
|
|
|
| 44 |
``` cpp
|
| 45 |
module;
|
| 46 |
#include "a.h" // error: declaration of x is not in the
|
| 47 |
// purview of a module interface unit
|
| 48 |
export module M;
|
| 49 |
+
export namespace {} // error: namespace has internal linkage
|
|
|
|
|
|
|
|
|
|
| 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; // OK
|
| 57 |
```
|
| 58 |
|
| 59 |
— *end example*]
|
| 60 |
|
| 61 |
+
If an exported declaration is a *using-declaration* [[namespace.udecl]]
|
| 62 |
+
and is 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 |
|
|
|
|
| 102 |
export using N::h; // error: #1 has internal linkage
|
| 103 |
```
|
| 104 |
|
| 105 |
— *end example*]
|
| 106 |
|
| 107 |
+
[*Note 2*:
|
| 108 |
|
| 109 |
These constraints do not apply to type names introduced by `typedef`
|
| 110 |
declarations and *alias-declaration*s.
|
| 111 |
|
| 112 |
[*Example 3*:
|
|
|
|
| 119 |
|
| 120 |
— *end example*]
|
| 121 |
|
| 122 |
— *end note*]
|
| 123 |
|
| 124 |
+
A redeclaration of an entity X is implicitly exported if X was
|
| 125 |
+
introduced by an exported declaration; otherwise it shall not be
|
| 126 |
+
exported.
|
| 127 |
|
| 128 |
[*Example 4*:
|
| 129 |
|
| 130 |
``` cpp
|
| 131 |
export module M;
|
|
|
|
| 135 |
export struct S; // error: exported declaration follows non-exported declaration
|
| 136 |
```
|
| 137 |
|
| 138 |
— *end example*]
|
| 139 |
|
| 140 |
+
[*Note 3*: Names introduced by exported declarations have either
|
| 141 |
+
external linkage or no linkage; see [[basic.link]]. Namespace-scope
|
| 142 |
+
declarations exported by a module can be found by name lookup in any
|
| 143 |
+
translation unit importing that module [[basic.lookup]]. Class and
|
| 144 |
+
enumeration member names can be found by name lookup in any context in
|
| 145 |
+
which a definition of the type is reachable. — *end note*]
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
[*Example 5*:
|
| 148 |
|
| 149 |
Interface unit of \`M\`
|
| 150 |
|
|
|
|
| 192 |
}
|
| 193 |
```
|
| 194 |
|
| 195 |
— *end example*]
|
| 196 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
[*Note 4*:
|
| 198 |
|
| 199 |
Declarations in an exported *namespace-definition* or in an exported
|
| 200 |
*linkage-specification* [[dcl.link]] are exported and subject to the
|
| 201 |
rules of exported declarations.
|
| 202 |
|
| 203 |
+
[*Example 6*:
|
| 204 |
|
| 205 |
``` cpp
|
| 206 |
export module M;
|
| 207 |
+
int g;
|
| 208 |
export namespace N {
|
| 209 |
int x; // OK
|
| 210 |
+
using ::g; // error: ::g has module linkage
|
| 211 |
}
|
| 212 |
```
|
| 213 |
|
| 214 |
— *end example*]
|
| 215 |
|