From Jason Turner

[temp.over.link]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmppko1zf31/{from.md → to.md} +36 -23
tmp/tmppko1zf31/{from.md → to.md} RENAMED
@@ -33,17 +33,17 @@ names of the template parameters are significant only for establishing
33
  the relationship between the template parameters and the rest of the
34
  signature.
35
 
36
  [*Note 1*:
37
 
38
- Two distinct function templates may have identical function return types
39
  and function parameter lists, even if overload resolution alone cannot
40
  distinguish them.
41
 
42
  ``` cpp
43
  template<class T> void f();
44
- template<int I> void f(); // OK: overloads the first template
45
  // distinguishable with an explicit template argument list
46
  ```
47
 
48
  — *end note*]
49
 
@@ -80,25 +80,27 @@ another token that names the same template parameter in the other
80
  expression. Two unevaluated operands that do not involve template
81
  parameters are considered equivalent if two function definitions
82
  containing the expressions would satisfy the one-definition rule, except
83
  that the tokens used to name types and declarations may differ as long
84
  as they name the same entities, and the tokens used to form concept-ids
85
- may differ as long as the two *template-id*s are the same [[temp.type]].
 
86
 
87
  [*Note 3*: For instance, `A<42>` and `A<40+2>` name the same
88
  type. — *end note*]
89
 
90
  Two *lambda-expression*s are never considered equivalent.
91
 
92
  [*Note 4*: The intent is to avoid *lambda-expression*s appearing in the
93
  signature of a function template with external linkage. — *end note*]
94
 
95
  For determining whether two dependent names [[temp.dep]] are equivalent,
96
- only the name itself is considered, not the result of name lookup in the
97
- context of the template. If multiple declarations of the same function
98
- template differ in the result of this name lookup, the result for the
99
- first declaration is used.
 
100
 
101
  [*Example 3*:
102
 
103
  ``` cpp
104
  template <int I, int J> void f(A<I+J>); // #1
@@ -107,11 +109,11 @@ template <int K, int L> void f(A<K+L>); // same as #1
107
  template <class T> decltype(g(T())) h();
108
  int g(int);
109
  template <class T> decltype(g(T())) h() // redeclaration of h() uses the earlier lookup…
110
  { return g(T()); } // …{} although the lookup here does find g(int)
111
  int i = h<int>(); // template argument substitution fails; g(int)
112
- // was not in scope at the first declaration of h()
113
 
114
  // ill-formed, no diagnostic required: the two expressions are functionally equivalent but not equivalent
115
  template <int N> void foo(const char (*s)[([]{}, N)]);
116
  template <int N> void foo(const char (*s)[([]{}, N)]);
117
 
@@ -128,13 +130,25 @@ of template arguments, the evaluation of the expression results in the
128
  same value. Two unevaluated operands that are not equivalent are
129
  functionally equivalent if, for any given set of template arguments, the
130
  expressions perform the same operations in the same order with the same
131
  entities.
132
 
133
- [*Note 5*: For instance, one could have redundant
134
  parentheses. — *end note*]
135
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  Two *template-head*s are *equivalent* if their
137
  *template-parameter-list*s have the same length, corresponding
138
  *template-parameter*s are equivalent and are both declared with
139
  *type-constraint*s that are equivalent if either *template-parameter* is
140
  declared with a *type-constraint*, and if either *template-head* has a
@@ -154,25 +168,24 @@ When determining whether types or *type-constraint*s are equivalent, the
154
  rules above are used to compare expressions involving template
155
  parameters. Two *template-head*s are *functionally equivalent* if they
156
  accept and are satisfied by [[temp.constr.constr]] the same set of
157
  template argument lists.
158
 
159
- Two function templates are *equivalent* if they are declared in the same
160
- scope, have the same name, have equivalent *template-head*s, and have
161
- return types, parameter lists, and trailing *requires-clause*s (if any)
162
- that are equivalent using the rules described above to compare
163
- expressions involving template parameters. Two function templates are
164
- *functionally equivalent* if they are declared in the same scope, have
165
- the same name, accept and are satisfied by the same set of template
166
- argument lists, and have return types and parameter lists that are
167
- functionally equivalent using the rules described above to compare
168
- expressions involving template parameters. If the validity or meaning of
169
- the program depends on whether two constructs are equivalent, and they
170
- are functionally equivalent but not equivalent, the program is
171
- ill-formed, no diagnostic required.
172
 
173
- [*Note 6*:
 
 
 
 
 
 
 
 
174
 
175
  This rule guarantees that equivalent declarations will be linked with
176
  one another, while not requiring implementations to use heroic efforts
177
  to guarantee that functionally equivalent declarations will be treated
178
  as distinct. For example, the last two declarations are functionally
 
33
  the relationship between the template parameters and the rest of the
34
  signature.
35
 
36
  [*Note 1*:
37
 
38
+ Two distinct function templates can have identical function return types
39
  and function parameter lists, even if overload resolution alone cannot
40
  distinguish them.
41
 
42
  ``` cpp
43
  template<class T> void f();
44
+ template<int I> void f(); // OK, overloads the first template
45
  // distinguishable with an explicit template argument list
46
  ```
47
 
48
  — *end note*]
49
 
 
80
  expression. Two unevaluated operands that do not involve template
81
  parameters are considered equivalent if two function definitions
82
  containing the expressions would satisfy the one-definition rule, except
83
  that the tokens used to name types and declarations may differ as long
84
  as they name the same entities, and the tokens used to form concept-ids
85
+ [[temp.names]] may differ as long as the two *template-id*s are the same
86
+ [[temp.type]].
87
 
88
  [*Note 3*: For instance, `A<42>` and `A<40+2>` name the same
89
  type. — *end note*]
90
 
91
  Two *lambda-expression*s are never considered equivalent.
92
 
93
  [*Note 4*: The intent is to avoid *lambda-expression*s appearing in the
94
  signature of a function template with external linkage. — *end note*]
95
 
96
  For determining whether two dependent names [[temp.dep]] are equivalent,
97
+ only the name itself is considered, not the result of name lookup.
98
+
99
+ [*Note 5*: If such a dependent name is unqualified, it is looked up
100
+ from the first declaration of the function template
101
+ [[temp.dep.candidate]]. — *end note*]
102
 
103
  [*Example 3*:
104
 
105
  ``` cpp
106
  template <int I, int J> void f(A<I+J>); // #1
 
109
  template <class T> decltype(g(T())) h();
110
  int g(int);
111
  template <class T> decltype(g(T())) h() // redeclaration of h() uses the earlier lookup…
112
  { return g(T()); } // …{} although the lookup here does find g(int)
113
  int i = h<int>(); // template argument substitution fails; g(int)
114
+ // not considered at the first declaration of h()
115
 
116
  // ill-formed, no diagnostic required: the two expressions are functionally equivalent but not equivalent
117
  template <int N> void foo(const char (*s)[([]{}, N)]);
118
  template <int N> void foo(const char (*s)[([]{}, N)]);
119
 
 
130
  same value. Two unevaluated operands that are not equivalent are
131
  functionally equivalent if, for any given set of template arguments, the
132
  expressions perform the same operations in the same order with the same
133
  entities.
134
 
135
+ [*Note 6*: For instance, one could have redundant
136
  parentheses. — *end note*]
137
 
138
+ [*Example 4*:
139
+
140
+ ``` cpp
141
+ template<int I> concept C = true;
142
+ template<typename T> struct A {
143
+ void f() requires C<42>; // #1
144
+ void f() requires true; // OK, different functions
145
+ };
146
+ ```
147
+
148
+ — *end example*]
149
+
150
  Two *template-head*s are *equivalent* if their
151
  *template-parameter-list*s have the same length, corresponding
152
  *template-parameter*s are equivalent and are both declared with
153
  *type-constraint*s that are equivalent if either *template-parameter* is
154
  declared with a *type-constraint*, and if either *template-head* has a
 
168
  rules above are used to compare expressions involving template
169
  parameters. Two *template-head*s are *functionally equivalent* if they
170
  accept and are satisfied by [[temp.constr.constr]] the same set of
171
  template argument lists.
172
 
173
+ If the validity or meaning of the program depends on whether two
174
+ constructs are equivalent, and they are functionally equivalent but not
175
+ equivalent, the program is ill-formed, no diagnostic required.
176
+ Furthermore, if two function templates that do not correspond
 
 
 
 
 
 
 
 
 
177
 
178
+ - have the same name,
179
+ - have corresponding signatures [[basic.scope.scope]],
180
+ - would declare the same entity [[basic.link]] considering them to
181
+ correspond, and
182
+ - accept and are satisfied by the same set of template argument lists,
183
+
184
+ the program is ill-formed, no diagnostic required.
185
+
186
+ [*Note 7*:
187
 
188
  This rule guarantees that equivalent declarations will be linked with
189
  one another, while not requiring implementations to use heroic efforts
190
  to guarantee that functionally equivalent declarations will be treated
191
  as distinct. For example, the last two declarations are functionally