From Jason Turner

[module.context]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpc3fr5x01/{from.md → to.md} +101 -0
tmp/tmpc3fr5x01/{from.md → to.md} RENAMED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Instantiation context <a id="module.context">[[module.context]]</a>
2
+
3
+ The *instantiation context* is a set of points within the program that
4
+ determines which names are visible to argument-dependent name lookup
5
+ [[basic.lookup.argdep]] and which declarations are reachable
6
+ [[module.reach]] in the context of a particular declaration or template
7
+ instantiation.
8
+
9
+ During the implicit definition of a defaulted function ([[special]],
10
+ [[class.compare.default]]), the instantiation context is the union of
11
+ the instantiation context from the definition of the class and the
12
+ instantiation context of the program construct that resulted in the
13
+ implicit definition of the defaulted function.
14
+
15
+ During the implicit instantiation of a template whose point of
16
+ instantiation is specified as that of an enclosing specialization
17
+ [[temp.point]], the instantiation context is the union of the
18
+ instantiation context of the enclosing specialization and, if the
19
+ template is defined in a module interface unit of a module M and the
20
+ point of instantiation is not in a module interface unit of M, the point
21
+ at the end of the *declaration-seq* of the primary module interface unit
22
+ of M (prior to the *private-module-fragment*, if any).
23
+
24
+ During the implicit instantiation of a template that is implicitly
25
+ instantiated because it is referenced from within the implicit
26
+ definition of a defaulted function, the instantiation context is the
27
+ instantiation context of the defaulted function.
28
+
29
+ During the instantiation of any other template specialization, the
30
+ instantiation context comprises the point of instantiation of the
31
+ template.
32
+
33
+ In any other case, the instantiation context at a point within the
34
+ program comprises that point.
35
+
36
+ [*Example 1*:
37
+
38
+ Translation unit #1
39
+
40
+ ``` cpp
41
+ export module stuff;
42
+ export template<typename T, typename U> void foo(T, U u) { auto v = u; }
43
+ export template<typename T, typename U> void bar(T, U u) { auto v = *u; }
44
+ ```
45
+
46
+ Translation unit #2
47
+
48
+ ``` cpp
49
+ export module M1;
50
+ import "defn.h"; // provides struct X {}
51
+ import stuff;
52
+ export template<typename T> void f(T t) {
53
+ X x;
54
+ foo(t, x);
55
+ }
56
+ ```
57
+
58
+ Translation unit #3
59
+
60
+ ``` cpp
61
+ export module M2;
62
+ import "decl.h"; // provides struct X; (not a definition)
63
+ import stuff;
64
+ export template<typename T> void g(T t) {
65
+ X *x;
66
+ bar(t, x);
67
+ }
68
+ ```
69
+
70
+ Translation unit #4
71
+
72
+ ``` cpp
73
+ import M1;
74
+ import M2;
75
+ void test() {
76
+ f(0);
77
+ g(0);
78
+ }
79
+ ```
80
+
81
+ The call to `f(0)` is valid; the instantiation context of `foo<int, X>`
82
+ comprises
83
+
84
+ - the point at the end of translation unit \#1,
85
+ - the point at the end of translation unit \#2, and
86
+ - the point of the call to `f(0)`,
87
+
88
+ so the definition of `X` is reachable ([[module.reach]]).
89
+
90
+ It is unspecified whether the call to `g(0)` is valid: the instantiation
91
+ context of `bar<int, X>` comprises
92
+
93
+ - the point at the end of translation unit \#1,
94
+ - the point at the end of translation unit \#3, and
95
+ - the point of the call to `g(0)`,
96
+
97
+ so the definition of `X` need not be reachable, as described in
98
+ [[module.reach]].
99
+
100
+ — *end example*]
101
+