Oliv
Oliv

Reputation: 18051

Are require-clauses evaluated after parameter substitution inside declarations?

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?

Upvotes: 3

Views: 71

Answers (1)

T.C.
T.C.

Reputation: 137330

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.

Upvotes: 2

Related Questions