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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Modules <a id="module">[[module]]</a>
|
| 2 |
+
|
| 3 |
+
## Module units and purviews <a id="module.unit">[[module.unit]]</a>
|
| 4 |
+
|
| 5 |
+
``` bnf
|
| 6 |
+
module-declaration:
|
| 7 |
+
export-keywordₒₚₜ module-keyword module-name module-partitionₒₚₜ attribute-specifier-seqₒₚₜ ';'
|
| 8 |
+
```
|
| 9 |
+
|
| 10 |
+
``` bnf
|
| 11 |
+
module-name:
|
| 12 |
+
module-name-qualifierₒₚₜ identifier
|
| 13 |
+
```
|
| 14 |
+
|
| 15 |
+
``` bnf
|
| 16 |
+
module-partition:
|
| 17 |
+
':' module-name-qualifierₒₚₜ identifier
|
| 18 |
+
```
|
| 19 |
+
|
| 20 |
+
``` bnf
|
| 21 |
+
module-name-qualifier:
|
| 22 |
+
identifier '.'
|
| 23 |
+
module-name-qualifier identifier '.'
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
A *module unit* is a translation unit that contains a
|
| 27 |
+
*module-declaration*. A *named module* is the collection of module units
|
| 28 |
+
with the same *module-name*. The identifiers `module` and `import` shall
|
| 29 |
+
not appear as *identifier*s in a *module-name* or *module-partition*.
|
| 30 |
+
All *module-name*s either beginning with an *identifier* consisting of
|
| 31 |
+
`std` followed by zero or more *digit*s or containing a reserved
|
| 32 |
+
identifier [[lex.name]] are reserved and shall not be specified in a
|
| 33 |
+
*module-declaration*; no diagnostic is required. If any *identifier* in
|
| 34 |
+
a reserved *module-name* is a reserved identifier, the module name is
|
| 35 |
+
reserved for use by C++ implementations; otherwise it is reserved for
|
| 36 |
+
future standardization. The optional *attribute-specifier-seq*
|
| 37 |
+
appertains to the *module-declaration*.
|
| 38 |
+
|
| 39 |
+
A *module interface unit* is a module unit whose *module-declaration*
|
| 40 |
+
starts with *export-keyword*; any other module unit is a *module
|
| 41 |
+
implementation unit*. A named module shall contain exactly one module
|
| 42 |
+
interface unit with no *module-partition*, known as the *primary module
|
| 43 |
+
interface unit* of the module; no diagnostic is required.
|
| 44 |
+
|
| 45 |
+
A *module partition* is a module unit whose *module-declaration*
|
| 46 |
+
contains a *module-partition*. A named module shall not contain multiple
|
| 47 |
+
module partitions with the same *module-partition*. All module
|
| 48 |
+
partitions of a module that are module interface units shall be directly
|
| 49 |
+
or indirectly exported by the primary module interface unit
|
| 50 |
+
[[module.import]]. No diagnostic is required for a violation of these
|
| 51 |
+
rules.
|
| 52 |
+
|
| 53 |
+
[*Note 1*: Module partitions can be imported only by other module units
|
| 54 |
+
in the same module. The division of a module into module units is not
|
| 55 |
+
visible outside the module. — *end note*]
|
| 56 |
+
|
| 57 |
+
[*Example 1*:
|
| 58 |
+
|
| 59 |
+
Translation unit #1
|
| 60 |
+
|
| 61 |
+
``` cpp
|
| 62 |
+
export module A;
|
| 63 |
+
export import :Foo;
|
| 64 |
+
export int baz();
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
Translation unit #2
|
| 68 |
+
|
| 69 |
+
``` cpp
|
| 70 |
+
export module A:Foo;
|
| 71 |
+
import :Internals;
|
| 72 |
+
export int foo() { return 2 * (bar() + 1); }
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
Translation unit #3
|
| 76 |
+
|
| 77 |
+
``` cpp
|
| 78 |
+
module A:Internals;
|
| 79 |
+
int bar();
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
Translation unit #4
|
| 83 |
+
|
| 84 |
+
``` cpp
|
| 85 |
+
module A;
|
| 86 |
+
import :Internals;
|
| 87 |
+
int bar() { return baz() - 10; }
|
| 88 |
+
int baz() { return 30; }
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
Module `A` contains four translation units:
|
| 92 |
+
|
| 93 |
+
- a primary module interface unit,
|
| 94 |
+
- a module partition `A:Foo`, which is a module interface unit forming
|
| 95 |
+
part of the interface of module `A`,
|
| 96 |
+
- a module partition `A:Internals`, which does not contribute to the
|
| 97 |
+
external interface of module `A`, and
|
| 98 |
+
- a module implementation unit providing a definition of `bar` and
|
| 99 |
+
`baz`, which cannot be imported because it does not have a partition
|
| 100 |
+
name.
|
| 101 |
+
|
| 102 |
+
— *end example*]
|
| 103 |
+
|
| 104 |
+
A *module unit purview* is the sequence of *token*s starting at the
|
| 105 |
+
*module-declaration* and extending to the end of the translation unit.
|
| 106 |
+
The *purview* of a named module `M` is the set of module unit purviews
|
| 107 |
+
of `M`’s module units.
|
| 108 |
+
|
| 109 |
+
The *global module* is the collection of all *global-module-fragment*s
|
| 110 |
+
and all translation units that are not module units. Declarations
|
| 111 |
+
appearing in such a context are said to be in the *purview* of the
|
| 112 |
+
global module.
|
| 113 |
+
|
| 114 |
+
[*Note 2*: The global module has no name, no module interface unit, and
|
| 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 |
+
|
| 130 |
+
A *module-declaration* that contains neither an *export-keyword* nor a
|
| 131 |
+
*module-partition* implicitly imports the primary module interface unit
|
| 132 |
+
of the module as if by a *module-import-declaration*.
|
| 133 |
+
|
| 134 |
+
[*Example 2*:
|
| 135 |
+
|
| 136 |
+
Translation unit #1
|
| 137 |
+
|
| 138 |
+
``` cpp
|
| 139 |
+
module B:Y; // does not implicitly import B
|
| 140 |
+
int y();
|
| 141 |
+
```
|
| 142 |
+
|
| 143 |
+
Translation unit #2
|
| 144 |
+
|
| 145 |
+
``` cpp
|
| 146 |
+
export module B;
|
| 147 |
+
import :Y; // OK, does not create interface dependency cycle
|
| 148 |
+
int n = y();
|
| 149 |
+
```
|
| 150 |
+
|
| 151 |
+
Translation unit #3
|
| 152 |
+
|
| 153 |
+
``` cpp
|
| 154 |
+
module B:X1; // does not implicitly import B
|
| 155 |
+
int &a = n; // error: n not visible here
|
| 156 |
+
```
|
| 157 |
+
|
| 158 |
+
Translation unit #4
|
| 159 |
+
|
| 160 |
+
``` cpp
|
| 161 |
+
module B:X2; // does not implicitly import B
|
| 162 |
+
import B;
|
| 163 |
+
int &b = n; // OK
|
| 164 |
+
```
|
| 165 |
+
|
| 166 |
+
Translation unit #5
|
| 167 |
+
|
| 168 |
+
``` cpp
|
| 169 |
+
module B; // implicitly imports B
|
| 170 |
+
int &c = n; // OK
|
| 171 |
+
```
|
| 172 |
+
|
| 173 |
+
— *end example*]
|
| 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 |
+
|
| 209 |
+
``` cpp
|
| 210 |
+
export int x;
|
| 211 |
+
```
|
| 212 |
+
|
| 213 |
+
Translation unit #1
|
| 214 |
+
|
| 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 |
+
|
| 242 |
+
Source file \`"b.h"\`
|
| 243 |
+
|
| 244 |
+
``` cpp
|
| 245 |
+
int f();
|
| 246 |
+
```
|
| 247 |
+
|
| 248 |
+
Importable header \`"c.h"\`
|
| 249 |
+
|
| 250 |
+
``` cpp
|
| 251 |
+
int g();
|
| 252 |
+
```
|
| 253 |
+
|
| 254 |
+
Translation unit #1
|
| 255 |
+
|
| 256 |
+
``` cpp
|
| 257 |
+
export module X;
|
| 258 |
+
export int h();
|
| 259 |
+
```
|
| 260 |
+
|
| 261 |
+
Translation unit #2
|
| 262 |
+
|
| 263 |
+
``` cpp
|
| 264 |
+
module;
|
| 265 |
+
#include "b.h"
|
| 266 |
+
export module M;
|
| 267 |
+
import "c.h";
|
| 268 |
+
import X;
|
| 269 |
+
export using ::f, ::g, ::h; // OK
|
| 270 |
+
struct S;
|
| 271 |
+
export using ::S; // error: S has module linkage
|
| 272 |
+
namespace N {
|
| 273 |
+
export int h();
|
| 274 |
+
static int h(int); // #1
|
| 275 |
+
}
|
| 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*:
|
| 287 |
+
|
| 288 |
+
``` cpp
|
| 289 |
+
export module M;
|
| 290 |
+
struct S;
|
| 291 |
+
export using T = S; // OK, exports name T denoting type S
|
| 292 |
+
```
|
| 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;
|
| 306 |
+
struct S { int n; };
|
| 307 |
+
typedef S S;
|
| 308 |
+
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 |
+
|
| 328 |
+
``` cpp
|
| 329 |
+
export module M;
|
| 330 |
+
export struct X {
|
| 331 |
+
static void f();
|
| 332 |
+
struct Y { };
|
| 333 |
+
};
|
| 334 |
+
|
| 335 |
+
namespace {
|
| 336 |
+
struct S { };
|
| 337 |
+
}
|
| 338 |
+
export void f(S); // OK
|
| 339 |
+
struct T { };
|
| 340 |
+
export T id(T); // OK
|
| 341 |
+
|
| 342 |
+
export struct A; // A exported as incomplete
|
| 343 |
+
|
| 344 |
+
export auto rootFinder(double a) {
|
| 345 |
+
return [=](double x) { return (x + a/x)/2; };
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
export const int n = 5; // OK, n has external linkage
|
| 349 |
+
```
|
| 350 |
+
|
| 351 |
+
Implementation unit of \`M\`
|
| 352 |
+
|
| 353 |
+
``` cpp
|
| 354 |
+
module M;
|
| 355 |
+
struct A {
|
| 356 |
+
int value;
|
| 357 |
+
};
|
| 358 |
+
```
|
| 359 |
+
|
| 360 |
+
Main program
|
| 361 |
+
|
| 362 |
+
``` cpp
|
| 363 |
+
import M;
|
| 364 |
+
int main() {
|
| 365 |
+
X::f(); // OK, X is exported and definition of X is reachable
|
| 366 |
+
X::Y y; // OK, X::Y is exported as a complete type
|
| 367 |
+
auto f = rootFinder(2); // OK
|
| 368 |
+
return A{45}.value; // error: A is incomplete
|
| 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 |
+
|
| 419 |
+
— *end note*]
|
| 420 |
+
|
| 421 |
+
## Import declaration <a id="module.import">[[module.import]]</a>
|
| 422 |
+
|
| 423 |
+
``` bnf
|
| 424 |
+
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
|
| 451 |
+
only appear after the *module-declaration* in a module unit of some
|
| 452 |
+
module `M`. Such a declaration imports the so-named module partition of
|
| 453 |
+
`M`.
|
| 454 |
+
|
| 455 |
+
A *module-import-declaration* that specifies a *header-name* `H` imports
|
| 456 |
+
a synthesized *header unit*, which is a translation unit formed by
|
| 457 |
+
applying phases 1 to 7 of translation [[lex.phases]] to the source file
|
| 458 |
+
or header nominated by `H`, which shall not contain a
|
| 459 |
+
*module-declaration*.
|
| 460 |
+
|
| 461 |
+
[*Note 2*: All declarations within a header unit are implicitly
|
| 462 |
+
exported [[module.interface]], and are attached to the global module
|
| 463 |
+
[[module.unit]]. — *end note*]
|
| 464 |
+
|
| 465 |
+
An *importable header* is a member of an *implementation-defined* set of
|
| 466 |
+
headers that includes all importable C++ library headers [[headers]].
|
| 467 |
+
`H` shall identify an importable header. Given two such
|
| 468 |
+
*module-import-declaration*s:
|
| 469 |
+
|
| 470 |
+
- if their *header-name*s identify different headers or source files
|
| 471 |
+
[[cpp.include]], they import distinct header units;
|
| 472 |
+
- otherwise, if they appear in the same translation unit, they import
|
| 473 |
+
the same header unit;
|
| 474 |
+
- otherwise, it is unspecified whether they import the same header unit.
|
| 475 |
+
\[*Note 3*: It is therefore possible that multiple copies exist of
|
| 476 |
+
entities declared with internal linkage in an importable
|
| 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 |
+
|
| 488 |
+
[*Note 5*: A definition that appears in multiple translation units
|
| 489 |
+
cannot in general refer to such names [[basic.def.odr]]. — *end note*]
|
| 490 |
+
|
| 491 |
+
A header unit shall not contain a definition of a non-inline function or
|
| 492 |
+
variable whose name has external linkage.
|
| 493 |
+
|
| 494 |
+
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 |
+
|
| 507 |
+
Translation unit #1
|
| 508 |
+
|
| 509 |
+
``` cpp
|
| 510 |
+
module M:Part;
|
| 511 |
+
```
|
| 512 |
+
|
| 513 |
+
Translation unit #2
|
| 514 |
+
|
| 515 |
+
``` cpp
|
| 516 |
+
export module M;
|
| 517 |
+
export import :Part; // error: exported partition :Part is an implementation unit
|
| 518 |
+
```
|
| 519 |
+
|
| 520 |
+
— *end example*]
|
| 521 |
+
|
| 522 |
+
A module implementation unit of a module `M` that is not a module
|
| 523 |
+
partition shall not contain a *module-import-declaration* nominating
|
| 524 |
+
`M`.
|
| 525 |
+
|
| 526 |
+
[*Example 2*:
|
| 527 |
+
|
| 528 |
+
``` cpp
|
| 529 |
+
module M;
|
| 530 |
+
import M; // error: cannot import M in its own unit
|
| 531 |
+
```
|
| 532 |
+
|
| 533 |
+
— *end example*]
|
| 534 |
+
|
| 535 |
+
A translation unit has an *interface dependency* on a translation unit
|
| 536 |
+
`U` if it contains a declaration (possibly a *module-declaration*) that
|
| 537 |
+
imports `U` or if it has an interface dependency on a translation unit
|
| 538 |
+
that has an interface dependency on `U`. A translation unit shall not
|
| 539 |
+
have an interface dependency on itself.
|
| 540 |
+
|
| 541 |
+
[*Example 3*:
|
| 542 |
+
|
| 543 |
+
Interface unit of \`M1\`
|
| 544 |
+
|
| 545 |
+
``` cpp
|
| 546 |
+
export module M1;
|
| 547 |
+
import M2;
|
| 548 |
+
```
|
| 549 |
+
|
| 550 |
+
Interface unit of \`M2\`
|
| 551 |
+
|
| 552 |
+
``` cpp
|
| 553 |
+
export module M2;
|
| 554 |
+
import M3;
|
| 555 |
+
```
|
| 556 |
+
|
| 557 |
+
Interface unit of \`M3\`
|
| 558 |
+
|
| 559 |
+
``` cpp
|
| 560 |
+
export module M3;
|
| 561 |
+
import M1; // error: cyclic interface dependency M3 → M1 → M2 → M3
|
| 562 |
+
```
|
| 563 |
+
|
| 564 |
+
— *end example*]
|
| 565 |
+
|
| 566 |
+
## Global module fragment <a id="module.global.frag">[[module.global.frag]]</a>
|
| 567 |
+
|
| 568 |
+
``` bnf
|
| 569 |
+
global-module-fragment:
|
| 570 |
+
module-keyword ';' declaration-seqₒₚₜ
|
| 571 |
+
```
|
| 572 |
+
|
| 573 |
+
[*Note 1*: Prior to phase 4 of translation, only preprocessing
|
| 574 |
+
directives can appear in the *declaration-seq*
|
| 575 |
+
[[cpp.pre]]. — *end note*]
|
| 576 |
+
|
| 577 |
+
A *global-module-fragment* specifies the contents of the *global module
|
| 578 |
+
fragment* for a module unit. The global module fragment can be used to
|
| 579 |
+
provide declarations that are attached to the global module and usable
|
| 580 |
+
within the module unit.
|
| 581 |
+
|
| 582 |
+
A declaration D is *decl-reachable* from a declaration S in the same
|
| 583 |
+
translation unit if:
|
| 584 |
+
|
| 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
|
| 615 |
+
- D declares a function or variable and M is declared in D, [^2] or
|
| 616 |
+
- one of M and D declares a template and the other declares a partial
|
| 617 |
+
or explicit specialization or an implicit or explicit instantiation
|
| 618 |
+
of that template, or
|
| 619 |
+
- one of M and D declares a class or enumeration type and the other
|
| 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
|
| 631 |
+
is replaced by its denoted type prior to this determination, and
|
| 632 |
+
- whether a non-value-dependent constant expression is replaced by the
|
| 633 |
+
result of constant evaluation prior to this determination.
|
| 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 |
+
|
| 645 |
+
[*Example 1*:
|
| 646 |
+
|
| 647 |
+
``` cpp
|
| 648 |
+
const int size = 2;
|
| 649 |
+
int ary1[size]; // unspecified whether size is decl-reachable from ary1
|
| 650 |
+
constexpr int identity(int x) { return x; }
|
| 651 |
+
int ary2[identity(2)]; // unspecified whether identity is decl-reachable from ary2
|
| 652 |
+
|
| 653 |
+
template<typename> struct S;
|
| 654 |
+
template<typename, int> struct S2;
|
| 655 |
+
constexpr int g(int);
|
| 656 |
+
|
| 657 |
+
template<typename T, int N>
|
| 658 |
+
S<S2<T, g(N)>> f(); // S, S2, g, and :: are decl-reachable from f
|
| 659 |
+
|
| 660 |
+
template<int N>
|
| 661 |
+
void h() noexcept(g(N) == N); // g and :: are decl-reachable from h
|
| 662 |
+
```
|
| 663 |
+
|
| 664 |
+
— *end example*]
|
| 665 |
+
|
| 666 |
+
[*Example 2*:
|
| 667 |
+
|
| 668 |
+
Source file \`"foo.h"\`
|
| 669 |
+
|
| 670 |
+
``` cpp
|
| 671 |
+
namespace N {
|
| 672 |
+
struct X {};
|
| 673 |
+
int d();
|
| 674 |
+
int e();
|
| 675 |
+
inline int f(X, int = d()) { return e(); }
|
| 676 |
+
int g(X);
|
| 677 |
+
int h(X);
|
| 678 |
+
}
|
| 679 |
+
```
|
| 680 |
+
|
| 681 |
+
Module \`M\` interface
|
| 682 |
+
|
| 683 |
+
``` cpp
|
| 684 |
+
module;
|
| 685 |
+
#include "foo.h"
|
| 686 |
+
export module M;
|
| 687 |
+
template<typename T> int use_f() {
|
| 688 |
+
N::X x; // N::X, N, and :: are decl-reachable from use_f
|
| 689 |
+
return f(x, 123); // N::f is decl-reachable from use_f,
|
| 690 |
+
// N::e is indirectly decl-reachable from use_f
|
| 691 |
+
// because it is decl-reachable from N::f, and
|
| 692 |
+
// N::d is decl-reachable from use_f
|
| 693 |
+
// because it is decl-reachable from N::f
|
| 694 |
+
// even though it is not used in this call
|
| 695 |
+
}
|
| 696 |
+
template<typename T> int use_g() {
|
| 697 |
+
N::X x; // N::X, N, and :: are decl-reachable from use_g
|
| 698 |
+
return g((T(), x)); // N::g is not decl-reachable from use_g
|
| 699 |
+
}
|
| 700 |
+
template<typename T> int use_h() {
|
| 701 |
+
N::X x; // N::X, N, and :: are decl-reachable from use_h
|
| 702 |
+
return h((T(), x)); // N::h is not decl-reachable from use_h, but
|
| 703 |
+
// N::h is decl-reachable from use_h<int>
|
| 704 |
+
}
|
| 705 |
+
int k = use_h<int>();
|
| 706 |
+
// use_h<int> is decl-reachable from k, so
|
| 707 |
+
// N::h is decl-reachable from k
|
| 708 |
+
```
|
| 709 |
+
|
| 710 |
+
Module \`M\` implementation
|
| 711 |
+
|
| 712 |
+
``` cpp
|
| 713 |
+
module M;
|
| 714 |
+
int a = use_f<int>(); // OK
|
| 715 |
+
int b = use_g<int>(); // error: no viable function for call to g;
|
| 716 |
+
// g is not decl-reachable from purview of
|
| 717 |
+
// module M's interface, so is discarded
|
| 718 |
+
int c = use_h<int>(); // OK
|
| 719 |
+
```
|
| 720 |
+
|
| 721 |
+
— *end example*]
|
| 722 |
+
|
| 723 |
+
## Private module fragment <a id="module.private.frag">[[module.private.frag]]</a>
|
| 724 |
+
|
| 725 |
+
``` bnf
|
| 726 |
+
private-module-fragment:
|
| 727 |
+
module-keyword ':' private ';' declaration-seqₒₚₜ
|
| 728 |
+
```
|
| 729 |
+
|
| 730 |
+
A *private-module-fragment* shall appear only in a primary module
|
| 731 |
+
interface unit [[module.unit]]. A module unit with a
|
| 732 |
+
*private-module-fragment* shall be the only module unit of its module;
|
| 733 |
+
no diagnostic is required.
|
| 734 |
+
|
| 735 |
+
[*Note 1*:
|
| 736 |
+
|
| 737 |
+
A *private-module-fragment* ends the portion of the module interface
|
| 738 |
+
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*]
|
| 757 |
+
|
| 758 |
+
[*Example 1*:
|
| 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
|
| 775 |
+
X *factory() {
|
| 776 |
+
return new X ();
|
| 777 |
+
}
|
| 778 |
+
void fn_e() {}
|
| 779 |
+
void fn_m() {}
|
| 780 |
+
void fn_s() {}
|
| 781 |
+
```
|
| 782 |
+
|
| 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
|
| 802 |
+
instantiation context of the enclosing specialization and, if the
|
| 803 |
+
template is defined in a module interface unit of a module M and the
|
| 804 |
+
point of instantiation is not in a module interface unit of M, the point
|
| 805 |
+
at the end of the *declaration-seq* of the primary module interface unit
|
| 806 |
+
of M (prior to the *private-module-fragment*, if any).
|
| 807 |
+
|
| 808 |
+
During the implicit instantiation of a template that is implicitly
|
| 809 |
+
instantiated because it is referenced from within the implicit
|
| 810 |
+
definition of a defaulted function, the instantiation context is the
|
| 811 |
+
instantiation context of the defaulted function.
|
| 812 |
+
|
| 813 |
+
During the instantiation of any other template specialization, the
|
| 814 |
+
instantiation context comprises the point of instantiation of the
|
| 815 |
+
template.
|
| 816 |
+
|
| 817 |
+
In any other case, the instantiation context at a point within the
|
| 818 |
+
program comprises that point.
|
| 819 |
+
|
| 820 |
+
[*Example 1*:
|
| 821 |
+
|
| 822 |
+
Translation unit #1
|
| 823 |
+
|
| 824 |
+
``` cpp
|
| 825 |
+
export module stuff;
|
| 826 |
+
export template<typename T, typename U> void foo(T, U u) { auto v = u; }
|
| 827 |
+
export template<typename T, typename U> void bar(T, U u) { auto v = *u; }
|
| 828 |
+
```
|
| 829 |
+
|
| 830 |
+
Translation unit #2
|
| 831 |
+
|
| 832 |
+
``` cpp
|
| 833 |
+
export module M1;
|
| 834 |
+
import "defn.h"; // provides struct X {}
|
| 835 |
+
import stuff;
|
| 836 |
+
export template<typename T> void f(T t) {
|
| 837 |
+
X x;
|
| 838 |
+
foo(t, x);
|
| 839 |
+
}
|
| 840 |
+
```
|
| 841 |
+
|
| 842 |
+
Translation unit #3
|
| 843 |
+
|
| 844 |
+
``` cpp
|
| 845 |
+
export module M2;
|
| 846 |
+
import "decl.h"; // provides struct X; (not a definition)
|
| 847 |
+
import stuff;
|
| 848 |
+
export template<typename T> void g(T t) {
|
| 849 |
+
X *x;
|
| 850 |
+
bar(t, x);
|
| 851 |
+
}
|
| 852 |
+
```
|
| 853 |
+
|
| 854 |
+
Translation unit #4
|
| 855 |
+
|
| 856 |
+
``` cpp
|
| 857 |
+
import M1;
|
| 858 |
+
import M2;
|
| 859 |
+
void test() {
|
| 860 |
+
f(0);
|
| 861 |
+
g(0);
|
| 862 |
+
}
|
| 863 |
+
```
|
| 864 |
+
|
| 865 |
+
The call to `f(0)` is valid; the instantiation context of `foo<int, X>`
|
| 866 |
+
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,
|
| 878 |
+
- the point at the end of translation unit \#3, and
|
| 879 |
+
- the point of the call to `g(0)`,
|
| 880 |
+
|
| 881 |
+
so the definition of `X` need not be reachable, as described in
|
| 882 |
+
[[module.reach]].
|
| 883 |
+
|
| 884 |
+
— *end example*]
|
| 885 |
+
|
| 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
|
| 920 |
+
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 |
+
|
| 935 |
+
``` cpp
|
| 936 |
+
export module M:A;
|
| 937 |
+
export struct B;
|
| 938 |
+
```
|
| 939 |
+
|
| 940 |
+
Translation unit #2
|
| 941 |
+
|
| 942 |
+
``` cpp
|
| 943 |
+
module M:B;
|
| 944 |
+
struct B {
|
| 945 |
+
operator int();
|
| 946 |
+
};
|
| 947 |
+
```
|
| 948 |
+
|
| 949 |
+
Translation unit #3
|
| 950 |
+
|
| 951 |
+
``` cpp
|
| 952 |
+
module M:C;
|
| 953 |
+
import :A;
|
| 954 |
+
B b1; // error: no reachable definition of struct B
|
| 955 |
+
```
|
| 956 |
+
|
| 957 |
+
Translation unit #4
|
| 958 |
+
|
| 959 |
+
``` cpp
|
| 960 |
+
export module M;
|
| 961 |
+
export import :A;
|
| 962 |
+
import :B;
|
| 963 |
+
B b2;
|
| 964 |
+
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 |
+
|
| 987 |
+
``` cpp
|
| 988 |
+
export module A;
|
| 989 |
+
struct X {};
|
| 990 |
+
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
|
| 1014 |
+
[dcl.link]: dcl.md#dcl.link
|
| 1015 |
+
[dcl.spec.auto]: dcl.md#dcl.spec.auto
|
| 1016 |
+
[headers]: library.md#headers
|
| 1017 |
+
[lex.name]: lex.md#lex.name
|
| 1018 |
+
[lex.phases]: lex.md#lex.phases
|
| 1019 |
+
[module]: #module
|
| 1020 |
+
[module.context]: #module.context
|
| 1021 |
+
[module.global.frag]: #module.global.frag
|
| 1022 |
+
[module.import]: #module.import
|
| 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
|
| 1042 |
+
effects of additional translation units involved in the compilation
|
| 1043 |
+
from being observed.
|