In the C++ standard, N4618/[temp.deduct] (§14.8.2), the following example (§14.8.2/7) demonstrates how template parameter substitution is performed in lexical order:
template <class T> struct A { using X = typename T::X; };
template <class T> typename T::X f(typename A<T>::X);
template <class T> void f(...) { }
template <class T> auto g(typename A<T>::X) -> typename T::X;
template <class T> void g(...) { }
void h() {
f<int>(0);// OK, substituting return type causes deduction to fail
g<int>(0);// error, substituting parameter type instantiates A<int>
}
I was expecting requires-clauses content to be also evaluated before declaration content. I expected that the following modification would not generate any compilation error:
template <class T> struct A { using X = typename T::X; };
template <class T> typename T::X f(typename A<T>::X);
template <class T> void f(...) { }
template <class T>
requires false
auto g(typename A<T>::X) -> typename T::X;
template <class T>
requires true
void g(...) { }
void h() {
f<int>(0);// OK, substituting return type causes deduction to fail
g<int>(0);// error, substituting parameter type instantiates A<int>
}
Actually GCC tell me there is still an error. Is it the behaviour stated in the concept TS?
Yes. See the note in N4630 [temp.deduct]/5:
The satisfaction of constraints (14.10) associated with the function template specialization is determined during overload resolution (13.3), and not at the point of substitution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With