From Jason Turner

[temp.dep.candidate]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpgc95kzlh/{from.md → to.md} +205 -9
tmp/tmpgc95kzlh/{from.md → to.md} RENAMED
@@ -1,21 +1,217 @@
1
  #### Candidate functions <a id="temp.dep.candidate">[[temp.dep.candidate]]</a>
2
 
3
  For a function call where the *postfix-expression* is a dependent name,
4
- the candidate functions are found using the usual lookup rules (
5
- [[basic.lookup.unqual]], [[basic.lookup.argdep]]) except that:
 
6
 
7
- - For the part of the lookup using unqualified name lookup (
8
- [[basic.lookup.unqual]]), only function declarations from the template
9
- definition context are found.
10
- - For the part of the lookup using associated namespaces (
11
- [[basic.lookup.argdep]]), only function declarations found in either
12
- the template definition context or the template instantiation context
13
- are found.
14
 
15
  If the call would be ill-formed or would find a better match had the
16
  lookup within the associated namespaces considered all the function
17
  declarations with external linkage introduced in those namespaces in all
18
  translation units, not just considering those declarations found in the
19
  template definition and template instantiation contexts, then the
20
  program has undefined behavior.
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  #### Candidate functions <a id="temp.dep.candidate">[[temp.dep.candidate]]</a>
2
 
3
  For a function call where the *postfix-expression* is a dependent name,
4
+ the candidate functions are found using the usual lookup rules from the
5
+ template definition context ([[basic.lookup.unqual]],
6
+ [[basic.lookup.argdep]]).
7
 
8
+ [*Note 1*: For the part of the lookup using associated namespaces
9
+ [[basic.lookup.argdep]], function declarations found in the template
10
+ instantiation context are found by this lookup, as described in
11
+ [[basic.lookup.argdep]]. *end note*]
 
 
 
12
 
13
  If the call would be ill-formed or would find a better match had the
14
  lookup within the associated namespaces considered all the function
15
  declarations with external linkage introduced in those namespaces in all
16
  translation units, not just considering those declarations found in the
17
  template definition and template instantiation contexts, then the
18
  program has undefined behavior.
19
 
20
+ [*Example 1*:
21
+
22
+ Source file \`"X.h"\`
23
+
24
+ ``` cpp
25
+ namespace Q {
26
+ struct X { };
27
+ }
28
+ ```
29
+
30
+ Source file \`"G.h"\`
31
+
32
+ ``` cpp
33
+ namespace Q {
34
+ void g_impl(X, X);
35
+ }
36
+ ```
37
+
38
+ Module interface unit of \`M1\`
39
+
40
+ ``` cpp
41
+ module;
42
+ #include "X.h"
43
+ #include "G.h"
44
+ export module M1;
45
+ export template<typename T>
46
+ void g(T t) {
47
+ g_impl(t, Q::X{ }); // ADL in definition context finds Q::g_impl, g_impl not discarded
48
+ }
49
+ ```
50
+
51
+ Module interface unit of \`M2\`
52
+
53
+ ``` cpp
54
+ module;
55
+ #include "X.h"
56
+ export module M2;
57
+ import M1;
58
+ void h(Q::X x) {
59
+ g(x); // OK
60
+ }
61
+ ```
62
+
63
+ — *end example*]
64
+
65
+ [*Example 2*:
66
+
67
+ Module interface unit of \`Std\`
68
+
69
+ ``` cpp
70
+ export module Std;
71
+ export template<typename Iter>
72
+ void indirect_swap(Iter lhs, Iter rhs)
73
+ {
74
+ swap(*lhs, *rhs); // swap not found by unqualified lookup, can be found only via ADL
75
+ }
76
+ ```
77
+
78
+ Module interface unit of \`M\`
79
+
80
+ ``` cpp
81
+ export module M;
82
+ import Std;
83
+
84
+ struct S { /* ...*/ };
85
+ void swap(S&, S&); // #1
86
+
87
+ void f(S* p, S* q)
88
+ {
89
+ indirect_swap(p, q); // finds #1 via ADL in instantiation context
90
+ }
91
+ ```
92
+
93
+ — *end example*]
94
+
95
+ [*Example 3*:
96
+
97
+ Source file \`"X.h"\`
98
+
99
+ ``` cpp
100
+ struct X { /* ... */ };
101
+ X operator+(X, X);
102
+ ```
103
+
104
+ Module interface unit of \`F\`
105
+
106
+ ``` cpp
107
+ export module F;
108
+ export template<typename T>
109
+ void f(T t) {
110
+ t + t;
111
+ }
112
+ ```
113
+
114
+ Module interface unit of \`M\`
115
+
116
+ ``` cpp
117
+ module;
118
+ #include "X.h"
119
+ export module M;
120
+ import F;
121
+ void g(X x) {
122
+ f(x); // OK: instantiates f from F,
123
+ // operator+ is visible in instantiation context
124
+ }
125
+ ```
126
+
127
+ — *end example*]
128
+
129
+ [*Example 4*:
130
+
131
+ Module interface unit of \`A\`
132
+
133
+ ``` cpp
134
+ export module A;
135
+ export template<typename T>
136
+ void f(T t) {
137
+ cat(t, t); // #1
138
+ dog(t, t); // #2
139
+ }
140
+ ```
141
+
142
+ Module interface unit of \`B\`
143
+
144
+ ``` cpp
145
+ export module B;
146
+ import A;
147
+ export template<typename T, typename U>
148
+ void g(T t, U u) {
149
+ f(t);
150
+ }
151
+ ```
152
+
153
+ Source file \`"foo.h"\`, not an importable header
154
+
155
+ ``` cpp
156
+ struct foo {
157
+ friend int cat(foo, foo);
158
+ };
159
+ int dog(foo, foo);
160
+ ```
161
+
162
+ Module interface unit of \`C1\`
163
+
164
+ ``` cpp
165
+ module;
166
+ #include "foo.h" // dog not referenced, discarded
167
+ export module C1;
168
+ import B;
169
+ export template<typename T>
170
+ void h(T t) {
171
+ g(foo{ }, t);
172
+ }
173
+ ```
174
+
175
+ Translation unit
176
+
177
+ ``` cpp
178
+ import C1;
179
+ void i() {
180
+ h(0); // error: dog not found at #2
181
+ }
182
+ ```
183
+
184
+ Importable header \`"bar.h"\`
185
+
186
+ ``` cpp
187
+ struct bar {
188
+ friend int cat(bar, bar);
189
+ };
190
+ int dog(bar, bar);
191
+ ```
192
+
193
+ Module interface unit of \`C2\`
194
+
195
+ ``` cpp
196
+ module;
197
+ #include "bar.h" // imports header unit "bar.h"
198
+ export module C2;
199
+ import B;
200
+ export template<typename T>
201
+ void j(T t) {
202
+ g(bar{ }, t);
203
+ }
204
+ ```
205
+
206
+ Translation unit
207
+
208
+ ``` cpp
209
+ import C2;
210
+ void k() {
211
+ j(0); // OK, dog found in instantiation context:
212
+ // visible at end of module interface unit of C2
213
+ }
214
+ ```
215
+
216
+ — *end example*]
217
+