For understanding this questions,please be sure to know the knowledge about the stateful meta programming,then we go.
Cite quotes about the point of instantiation of default arguments
[temp.point]/2
If a function template or member function of a class template is called in a way which uses the definition of a default argument of that function template or member function, the point of instantiation of the default argument is the point of instantiation of the function template or member function specialization.
If I understand correctly about the above quote,It means the POI of default argument is as the same as the POI of the function template that use the default argument(or if I misunderstand this bullet,please correct me).
Now,ready to consider below codes:
#include <iostream>
template<int N>
struct state {
friend auto call(state<N>);
};
template<int N>
struct add_state {
friend auto call(state<N>) {
return N;
}
static const int value = N;
};
template<typename T, int N>
T show(int = add_state<N>::value) {
return T{};
}
int main() {
show<int, 0>();
call(state<0>{});
}
Actually,the above code is well-formed(the result here godbolt).However,accroding to the above quote, the POI of add_state<0>
would be as the same as that of show<int, 0>()
,the POI of show<int, 0>()
either after function main
or at the end of translate unit(Perhaps,most compliers take the end of translate unit as a POI for function template),However at that point,the call of call(state<0>{});
could not find the definition of call(state<0>{})
,so it would be ill-formed.
the result of the above code proved that the POI of add_state<0>
must precede the call of call(state<0>{})
,only under this situation,the definition of call(state<0>{})
can be looked up.So it confuse me,How to interpret this question,I appreciate for correct interpretaions.
std::is_same_v<S<>, S<>>
beingfalse
), it should proabaly considered ill-formed in general. See the question and its only answer: stackoverflow.com/questions/44267673/… – CygnusX1