From Jason Turner

[temp.dep.res]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp2e9hvt_o/{from.md → to.md} +222 -32
tmp/tmp2e9hvt_o/{from.md → to.md} RENAMED
@@ -1,16 +1,7 @@
1
  ### Dependent name resolution <a id="temp.dep.res">[[temp.dep.res]]</a>
2
 
3
- In resolving dependent names, names from the following sources are
4
- considered:
5
-
6
- - Declarations that are visible at the point of definition of the
7
- template.
8
- - Declarations from namespaces associated with the types of the function
9
- arguments both from the instantiation context ([[temp.point]]) and
10
- from the definition context.
11
-
12
  #### Point of instantiation <a id="temp.point">[[temp.point]]</a>
13
 
14
  For a function template specialization, a member function template
15
  specialization, or a specialization for a member function or static data
16
  member of a class template, if the specialization is implicitly
@@ -56,44 +47,243 @@ enclosing class template specialization.
56
 
57
  An explicit instantiation definition is an instantiation point for the
58
  specialization or specializations specified by the explicit
59
  instantiation.
60
 
61
- The instantiation context of an expression that depends on the template
62
- arguments is the set of declarations with external linkage declared
63
- prior to the point of instantiation of the template specialization in
64
- the same translation unit.
65
-
66
  A specialization for a function template, a member function template, or
67
  of a member function or static data member of a class template may have
68
  multiple points of instantiations within a translation unit, and in
69
- addition to the points of instantiation described above, for any such
70
- specialization that has a point of instantiation within the translation
71
- unit, the end of the translation unit is also considered a point of
72
- instantiation. A specialization for a class template has at most one
73
- point of instantiation within a translation unit. A specialization for
74
- any template may have points of instantiation in multiple translation
75
- units. If two different points of instantiation give a template
76
- specialization different meanings according to the one-definition rule (
77
- [[basic.def.odr]]), the program is ill-formed, no diagnostic required.
 
 
 
 
 
 
 
 
78
 
79
  #### Candidate functions <a id="temp.dep.candidate">[[temp.dep.candidate]]</a>
80
 
81
  For a function call where the *postfix-expression* is a dependent name,
82
- the candidate functions are found using the usual lookup rules (
83
- [[basic.lookup.unqual]], [[basic.lookup.argdep]]) except that:
 
84
 
85
- - For the part of the lookup using unqualified name lookup (
86
- [[basic.lookup.unqual]]), only function declarations from the template
87
- definition context are found.
88
- - For the part of the lookup using associated namespaces (
89
- [[basic.lookup.argdep]]), only function declarations found in either
90
- the template definition context or the template instantiation context
91
- are found.
92
 
93
  If the call would be ill-formed or would find a better match had the
94
  lookup within the associated namespaces considered all the function
95
  declarations with external linkage introduced in those namespaces in all
96
  translation units, not just considering those declarations found in the
97
  template definition and template instantiation contexts, then the
98
  program has undefined behavior.
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ### Dependent name resolution <a id="temp.dep.res">[[temp.dep.res]]</a>
2
 
 
 
 
 
 
 
 
 
 
3
  #### Point of instantiation <a id="temp.point">[[temp.point]]</a>
4
 
5
  For a function template specialization, a member function template
6
  specialization, or a specialization for a member function or static data
7
  member of a class template, if the specialization is implicitly
 
47
 
48
  An explicit instantiation definition is an instantiation point for the
49
  specialization or specializations specified by the explicit
50
  instantiation.
51
 
 
 
 
 
 
52
  A specialization for a function template, a member function template, or
53
  of a member function or static data member of a class template may have
54
  multiple points of instantiations within a translation unit, and in
55
+ addition to the points of instantiation described above,
56
+
57
+ - for any such specialization that has a point of instantiation within
58
+ the *declaration-seq* of the *translation-unit*, prior to the
59
+ *private-module-fragment* (if any), the point after the
60
+ *declaration-seq* of the *translation-unit* is also considered a point
61
+ of instantiation, and
62
+ - for any such specialization that has a point of instantiation within
63
+ the *private-module-fragment*, the end of the translation unit is also
64
+ considered a point of instantiation.
65
+
66
+ A specialization for a class template has at most one point of
67
+ instantiation within a translation unit. A specialization for any
68
+ template may have points of instantiation in multiple translation units.
69
+ If two different points of instantiation give a template specialization
70
+ different meanings according to the one-definition rule
71
+ [[basic.def.odr]], the program is ill-formed, no diagnostic required.
72
 
73
  #### Candidate functions <a id="temp.dep.candidate">[[temp.dep.candidate]]</a>
74
 
75
  For a function call where the *postfix-expression* is a dependent name,
76
+ the candidate functions are found using the usual lookup rules from the
77
+ template definition context ([[basic.lookup.unqual]],
78
+ [[basic.lookup.argdep]]).
79
 
80
+ [*Note 1*: For the part of the lookup using associated namespaces
81
+ [[basic.lookup.argdep]], function declarations found in the template
82
+ instantiation context are found by this lookup, as described in
83
+ [[basic.lookup.argdep]]. *end note*]
 
 
 
84
 
85
  If the call would be ill-formed or would find a better match had the
86
  lookup within the associated namespaces considered all the function
87
  declarations with external linkage introduced in those namespaces in all
88
  translation units, not just considering those declarations found in the
89
  template definition and template instantiation contexts, then the
90
  program has undefined behavior.
91
 
92
+ [*Example 1*:
93
+
94
+ Source file \`"X.h"\`
95
+
96
+ ``` cpp
97
+ namespace Q {
98
+ struct X { };
99
+ }
100
+ ```
101
+
102
+ Source file \`"G.h"\`
103
+
104
+ ``` cpp
105
+ namespace Q {
106
+ void g_impl(X, X);
107
+ }
108
+ ```
109
+
110
+ Module interface unit of \`M1\`
111
+
112
+ ``` cpp
113
+ module;
114
+ #include "X.h"
115
+ #include "G.h"
116
+ export module M1;
117
+ export template<typename T>
118
+ void g(T t) {
119
+ g_impl(t, Q::X{ }); // ADL in definition context finds Q::g_impl, g_impl not discarded
120
+ }
121
+ ```
122
+
123
+ Module interface unit of \`M2\`
124
+
125
+ ``` cpp
126
+ module;
127
+ #include "X.h"
128
+ export module M2;
129
+ import M1;
130
+ void h(Q::X x) {
131
+ g(x); // OK
132
+ }
133
+ ```
134
+
135
+ — *end example*]
136
+
137
+ [*Example 2*:
138
+
139
+ Module interface unit of \`Std\`
140
+
141
+ ``` cpp
142
+ export module Std;
143
+ export template<typename Iter>
144
+ void indirect_swap(Iter lhs, Iter rhs)
145
+ {
146
+ swap(*lhs, *rhs); // swap not found by unqualified lookup, can be found only via ADL
147
+ }
148
+ ```
149
+
150
+ Module interface unit of \`M\`
151
+
152
+ ``` cpp
153
+ export module M;
154
+ import Std;
155
+
156
+ struct S { /* ...*/ };
157
+ void swap(S&, S&); // #1
158
+
159
+ void f(S* p, S* q)
160
+ {
161
+ indirect_swap(p, q); // finds #1 via ADL in instantiation context
162
+ }
163
+ ```
164
+
165
+ — *end example*]
166
+
167
+ [*Example 3*:
168
+
169
+ Source file \`"X.h"\`
170
+
171
+ ``` cpp
172
+ struct X { /* ... */ };
173
+ X operator+(X, X);
174
+ ```
175
+
176
+ Module interface unit of \`F\`
177
+
178
+ ``` cpp
179
+ export module F;
180
+ export template<typename T>
181
+ void f(T t) {
182
+ t + t;
183
+ }
184
+ ```
185
+
186
+ Module interface unit of \`M\`
187
+
188
+ ``` cpp
189
+ module;
190
+ #include "X.h"
191
+ export module M;
192
+ import F;
193
+ void g(X x) {
194
+ f(x); // OK: instantiates f from F,
195
+ // operator+ is visible in instantiation context
196
+ }
197
+ ```
198
+
199
+ — *end example*]
200
+
201
+ [*Example 4*:
202
+
203
+ Module interface unit of \`A\`
204
+
205
+ ``` cpp
206
+ export module A;
207
+ export template<typename T>
208
+ void f(T t) {
209
+ cat(t, t); // #1
210
+ dog(t, t); // #2
211
+ }
212
+ ```
213
+
214
+ Module interface unit of \`B\`
215
+
216
+ ``` cpp
217
+ export module B;
218
+ import A;
219
+ export template<typename T, typename U>
220
+ void g(T t, U u) {
221
+ f(t);
222
+ }
223
+ ```
224
+
225
+ Source file \`"foo.h"\`, not an importable header
226
+
227
+ ``` cpp
228
+ struct foo {
229
+ friend int cat(foo, foo);
230
+ };
231
+ int dog(foo, foo);
232
+ ```
233
+
234
+ Module interface unit of \`C1\`
235
+
236
+ ``` cpp
237
+ module;
238
+ #include "foo.h" // dog not referenced, discarded
239
+ export module C1;
240
+ import B;
241
+ export template<typename T>
242
+ void h(T t) {
243
+ g(foo{ }, t);
244
+ }
245
+ ```
246
+
247
+ Translation unit
248
+
249
+ ``` cpp
250
+ import C1;
251
+ void i() {
252
+ h(0); // error: dog not found at #2
253
+ }
254
+ ```
255
+
256
+ Importable header \`"bar.h"\`
257
+
258
+ ``` cpp
259
+ struct bar {
260
+ friend int cat(bar, bar);
261
+ };
262
+ int dog(bar, bar);
263
+ ```
264
+
265
+ Module interface unit of \`C2\`
266
+
267
+ ``` cpp
268
+ module;
269
+ #include "bar.h" // imports header unit "bar.h"
270
+ export module C2;
271
+ import B;
272
+ export template<typename T>
273
+ void j(T t) {
274
+ g(bar{ }, t);
275
+ }
276
+ ```
277
+
278
+ Translation unit
279
+
280
+ ``` cpp
281
+ import C2;
282
+ void k() {
283
+ j(0); // OK, dog found in instantiation context:
284
+ // visible at end of module interface unit of C2
285
+ }
286
+ ```
287
+
288
+ — *end example*]
289
+