Contracts on member templates of class templates are broken in specific cases
When a guarded member template is defined outside of its containing class template and the user does not explicitly call/instantiate the unchecked function an access error is thrown:
template<typename T>
struct S
{
template<typename Q>
int f(int a) [[ pre: a > 0 ]];
};
template<typename T>
template<typename Q>
int S<T>::f(int a) [[ pre: a > 0 ]]
{
return -a;
}
int main(int, char**)
{
S<int> s;
s.f<double>(-10);
return 0;
}
generates:
mtct.cpp: In instantiation of ‘int S<T>::f(int) [with Q = double; T = int]’:
mtct.cpp:19:18: required from here
mtct.cpp:16:1: error: ‘int S<T>::__l3_mf_f(int) [with Q = double; T = int]’ is inaccessible within this context
16 | int main(int, char**)
| ^~~
mtct.cpp:11:5: note: declared here
11 | int S<T>::f(int a) [[ pre: a > 0 ]]
| ^~~~