You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a wording issue which led me to this problem, where I have (mis?)interpreted the wording and (falsely?) assumed that the following code is ill-formed:
template <typename T>
voidfun(T t) {
// foo and bar are not declared yet, but this is okay,// because they can be found through ADL for a class type Tfoo(t);
bar(t);
}
structA {};
voidfoo(A);
// implicitly instantiate fun<A>(A), with the point of instantiation being after call_funvoidcall_fun() {
fun(A{});
}
/* implicit instantiation should be here:template void fun<A>(A t) { foo(t); // OK, foo has been declared bar(t); // NOT OK, bar has not been declared yet}*/voidbar(A);
For a function template specialization, a member function template specialization, or a specialization for a member function or static data member of a class template, if the specialization is implicitly instantiated because it is referenced from within another template specialization and the context from which it is referenced depends on a template parameter, the point of instantiation of the specialization is the point of instantiation of the enclosing specialization. Otherwise, the point of instantiation for such a specialization immediately follows the namespace scope declaration or definition that refers to the specialization.
The relevant part is follows the namespace scope declaration or definition. There are two possible interpretations:
"follows the declaration or definition AT namespace scope"
"follows the declaration or definition OF THE namespace scope"
If we interpret it as 1., then the above code should indeed be ill-formed, because the instantiation of fun<A> follows call_fun. However, all compilers happily accept this code, so implementations must be interpreting this as 2., where the point of instantiation of fun<A> follows the global scope itself.
I am not certain which reading is truly correct, and it should be clarified by rephrasing it as 1. or 2..
The text was updated successfully, but these errors were encountered:
Motivation
There is a wording issue which led me to this problem, where I have (mis?)interpreted the wording and (falsely?) assumed that the following code is ill-formed:
See also: https://stackoverflow.com/q/76687729/5740428
The Wording Issue
- [temp.point]/1
The relevant part is
follows the namespace scope declaration or definition
. There are two possible interpretations:If we interpret it as 1., then the above code should indeed be ill-formed, because the instantiation of
fun<A>
followscall_fun
. However, all compilers happily accept this code, so implementations must be interpreting this as 2., where the point of instantiation offun<A>
follows the global scope itself.I am not certain which reading is truly correct, and it should be clarified by rephrasing it as 1. or 2..
The text was updated successfully, but these errors were encountered: