From Jason Turner

[temp.res.general]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp6f75zh0y/{from.md → to.md} +295 -0
tmp/tmp6f75zh0y/{from.md → to.md} RENAMED
@@ -0,0 +1,295 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### General <a id="temp.res.general">[[temp.res.general]]</a>
2
+
3
+ A name that appears in a declaration D of a template T is looked up from
4
+ where it appears in an unspecified declaration of T that either is D
5
+ itself or is reachable from D and from which no other declaration of T
6
+ that contains the usage of the name is reachable. If the name is
7
+ dependent (as specified in [[temp.dep]]), it is looked up for each
8
+ specialization (after substitution) because the lookup depends on a
9
+ template parameter.
10
+
11
+ [*Note 1*: Some dependent names are also looked up during parsing to
12
+ determine that they are dependent or to interpret following `<` tokens.
13
+ Uses of other names might be type-dependent or value-dependent
14
+ [[temp.dep.expr]], [[temp.dep.constexpr]]. A *using-declarator* is never
15
+ dependent in a specialization and is therefore replaced during lookup
16
+ for that specialization [[basic.lookup]]. — *end note*]
17
+
18
+ [*Example 1*:
19
+
20
+ ``` cpp
21
+ struct A { operator int(); };
22
+ template<class B, class T>
23
+ struct D : B {
24
+ T get() { return operator T(); } // conversion-function-id is dependent
25
+ };
26
+ int f(D<A, int> d) { return d.get(); } // OK, lookup finds A::operator int
27
+ ```
28
+
29
+ — *end example*]
30
+
31
+ [*Example 2*:
32
+
33
+ ``` cpp
34
+ void f(char);
35
+
36
+ template<class T> void g(T t) {
37
+ f(1); // f(char)
38
+ f(T(1)); // dependent
39
+ f(t); // dependent
40
+ dd++; // not dependent; error: declaration for dd not found
41
+ }
42
+
43
+ enum E { e };
44
+ void f(E);
45
+
46
+ double dd;
47
+ void h() {
48
+ g(e); // will cause one call of f(char) followed by two calls of f(E)
49
+ g('a'); // will cause three calls of f(char)
50
+ }
51
+ ```
52
+
53
+ — *end example*]
54
+
55
+ [*Example 3*:
56
+
57
+ ``` cpp
58
+ struct A {
59
+ struct B { ... };
60
+ int a;
61
+ int Y;
62
+ };
63
+
64
+ int a;
65
+
66
+ template<class T> struct Y : T {
67
+ struct B { ... };
68
+ B b; // The B defined in Y
69
+ void f(int i) { a = i; } // ::a
70
+ Y* p; // Y<T>
71
+ };
72
+
73
+ Y<A> ya;
74
+ ```
75
+
76
+ The members `A::B`, `A::a`, and `A::Y` of the template argument `A` do
77
+ not affect the binding of names in `Y<A>`.
78
+
79
+ — *end example*]
80
+
81
+ If the validity or meaning of the program would be changed by
82
+ considering a default argument or default template argument introduced
83
+ in a declaration that is reachable from the point of instantiation of a
84
+ specialization [[temp.point]] but is not found by lookup for the
85
+ specialization, the program is ill-formed, no diagnostic required.
86
+
87
+ ``` bnf
88
+ typename-specifier:
89
+ typename nested-name-specifier identifier
90
+ typename nested-name-specifier 'templateₒₚₜ ' simple-template-id
91
+ ```
92
+
93
+ The component names of a *typename-specifier* are its *identifier* (if
94
+ any) and those of its *nested-name-specifier* and *simple-template-id*
95
+ (if any). A *typename-specifier* denotes the type or class template
96
+ denoted by the *simple-type-specifier* [[dcl.type.simple]] formed by
97
+ omitting the keyword `typename`.
98
+
99
+ [*Note 2*: The usual qualified name lookup [[basic.lookup.qual]]
100
+ applies even in the presence of `typename`. — *end note*]
101
+
102
+ [*Example 4*:
103
+
104
+ ``` cpp
105
+ struct A {
106
+ struct X { };
107
+ int X;
108
+ };
109
+ struct B {
110
+ struct X { };
111
+ };
112
+ template<class T> void f(T t) {
113
+ typename T::X x;
114
+ }
115
+ void foo() {
116
+ A a;
117
+ B b;
118
+ f(b); // OK, T::X refers to B::X
119
+ f(a); // error: T::X refers to the data member A::X not the struct A::X
120
+ }
121
+ ```
122
+
123
+ — *end example*]
124
+
125
+ A qualified or unqualified name is said to be in a *type-only context*
126
+ if it is the terminal name of
127
+
128
+ - a *typename-specifier*, *nested-name-specifier*,
129
+ *elaborated-type-specifier*, *class-or-decltype*, or
130
+ - a *type-specifier* of a
131
+ - *new-type-id*,
132
+ - *defining-type-id*,
133
+ - *conversion-type-id*,
134
+ - *trailing-return-type*,
135
+ - default argument of a *type-parameter*, or
136
+ - *type-id* of a `static_cast`, `const_cast`, `reinterpret_cast`, or
137
+ `dynamic_cast`, or
138
+ - a *decl-specifier* of the *decl-specifier-seq* of a
139
+ - *simple-declaration* or a *function-definition* in namespace scope,
140
+ - *member-declaration*,
141
+ - *parameter-declaration* in a *member-declaration*,[^10] unless that
142
+ *parameter-declaration* appears in a default argument,
143
+ - *parameter-declaration* in a *declarator* of a function or function
144
+ template declaration whose *declarator-id* is qualified, unless that
145
+ *parameter-declaration* appears in a default argument,
146
+ - *parameter-declaration* in a *lambda-declarator* or
147
+ *requirement-parameter-list*, unless that *parameter-declaration*
148
+ appears in a default argument, or
149
+ - *parameter-declaration* of a (non-type) *template-parameter*.
150
+
151
+ [*Example 5*:
152
+
153
+ ``` cpp
154
+ template<class T> T::R f(); // OK, return type of a function declaration at global scope
155
+ template<class T> void f(T::R); // ill-formed, no diagnostic required: attempt to declare
156
+ // a void variable template
157
+ template<class T> struct S {
158
+ using Ptr = PtrTraits<T>::Ptr; // OK, in a defining-type-id
159
+ T::R f(T::P p) { // OK, class scope
160
+ return static_cast<T::R>(p); // OK, type-id of a static_cast
161
+ }
162
+ auto g() -> S<T*>::Ptr; // OK, trailing-return-type
163
+ };
164
+ template<typename T> void f() {
165
+ void (*pf)(T::X); // variable pf of type void* initialized with T::X
166
+ void g(T::X); // error: T::X at block scope does not denote a type
167
+ // (attempt to declare a void variable)
168
+ }
169
+ ```
170
+
171
+ — *end example*]
172
+
173
+ A *qualified-id* whose terminal name is dependent and that is in a
174
+ type-only context is considered to denote a type. A name that refers to
175
+ a *using-declarator* whose terminal name is dependent is interpreted as
176
+ a *typedef-name* if the *using-declarator* uses the keyword `typename`.
177
+
178
+ [*Example 6*:
179
+
180
+ ``` cpp
181
+ template <class T> void f(int i) {
182
+ T::x * i; // expression, not the declaration of a variable i
183
+ }
184
+
185
+ struct Foo {
186
+ typedef int x;
187
+ };
188
+
189
+ struct Bar {
190
+ static int const x = 5;
191
+ };
192
+
193
+ int main() {
194
+ f<Bar>(1); // OK
195
+ f<Foo>(1); // error: Foo::x is a type
196
+ }
197
+ ```
198
+
199
+ — *end example*]
200
+
201
+ The validity of a template may be checked prior to any instantiation.
202
+
203
+ [*Note 3*: Knowing which names are type names allows the syntax of
204
+ every template to be checked in this way. — *end note*]
205
+
206
+ The program is ill-formed, no diagnostic required, if:
207
+
208
+ - no valid specialization, ignoring *static_assert-declaration*s that
209
+ fail, can be generated for a template or a substatement of a constexpr
210
+ if statement [[stmt.if]] within a template and the template is not
211
+ instantiated, or
212
+ - any *constraint-expression* in the program, introduced or otherwise,
213
+ has (in its normal form) an atomic constraint A where no satisfaction
214
+ check of A could be well-formed and no satisfaction check of A is
215
+ performed, or
216
+ - every valid specialization of a variadic template requires an empty
217
+ template parameter pack, or
218
+ - a hypothetical instantiation of a template immediately following its
219
+ definition would be ill-formed due to a construct that does not depend
220
+ on a template parameter, or
221
+ - the interpretation of such a construct in the hypothetical
222
+ instantiation is different from the interpretation of the
223
+ corresponding construct in any actual instantiation of the template.
224
+
225
+ [*Note 4*:
226
+
227
+ This can happen in situations including the following:
228
+
229
+ - a type used in a non-dependent name is incomplete at the point at
230
+ which a template is defined but is complete at the point at which an
231
+ instantiation is performed, or
232
+ - lookup for a name in the template definition found a
233
+ *using-declaration*, but the lookup in the corresponding scope in the
234
+ instantiation does not find any declarations because the
235
+ *using-declaration* was a pack expansion and the corresponding pack is
236
+ empty, or
237
+ - an instantiation uses a default argument or default template argument
238
+ that had not been defined at the point at which the template was
239
+ defined, or
240
+ - constant expression evaluation [[expr.const]] within the template
241
+ instantiation uses
242
+ - the value of a const object of integral or unscoped enumeration type
243
+ or
244
+ - the value of a `constexpr` object or
245
+ - the value of a reference or
246
+ - the definition of a constexpr function,
247
+
248
+ and that entity was not defined when the template was defined, or
249
+ - a class template specialization or variable template specialization
250
+ that is specified by a non-dependent *simple-template-id* is used by
251
+ the template, and either it is instantiated from a partial
252
+ specialization that was not defined when the template was defined or
253
+ it names an explicit specialization that was not declared when the
254
+ template was defined.
255
+
256
+ — *end note*]
257
+
258
+ Otherwise, no diagnostic shall be issued for a template for which a
259
+ valid specialization can be generated.
260
+
261
+ [*Note 5*: If a template is instantiated, errors will be diagnosed
262
+ according to the other rules in this document. Exactly when these errors
263
+ are diagnosed is a quality of implementation issue. — *end note*]
264
+
265
+ [*Example 7*:
266
+
267
+ ``` cpp
268
+ int j;
269
+ template<class T> class X {
270
+ void f(T t, int i, char* p) {
271
+ t = i; // diagnosed if X::f is instantiated, and the assignment to t is an error
272
+ p = i; // may be diagnosed even if X::f is not instantiated
273
+ p = j; // may be diagnosed even if X::f is not instantiated
274
+ X<T>::g(t); // OK
275
+ X<T>::h(); // may be diagnosed even if X::f is not instantiated
276
+ }
277
+ void g(T t) {
278
+ +; // may be diagnosed even if X::g is not instantiated
279
+ }
280
+ };
281
+
282
+ template<class... T> struct A {
283
+ void operator++(int, T... t); // error: too many parameters
284
+ };
285
+ template<class... T> union X : T... { }; // error: union with base class
286
+ template<class... T> struct A : T..., T... { }; // error: duplicate base class
287
+ ```
288
+
289
+ — *end example*]
290
+
291
+ [*Note 6*: For purposes of name lookup, default arguments and
292
+ *noexcept-specifier*s of function templates and default arguments and
293
+ *noexcept-specifier*s of member functions of class templates are
294
+ considered definitions [[temp.decls]]. — *end note*]
295
+