In the following code main returns 2 while I expect it to return 0 (or at least 7)
extern struct S s;
template<typename T>
constexpr int global(T&) { return 0; }
template<typename T>
//constexpr
int func(T& t) { return global(t); }
int main()
{
return global(s) + 2*func(s) + 4*([](auto &a){return global(a);})(s);
}
static constexpr int global(S&) { return 1; }
This code is also on https://godbolt.org/z/RkkXwf
If I uncomment constexpr on func the result changes to the expected 0.
From what I understand the overload resolution should only consider functions before template instantiation point. But somehow it finds the one declared after this point for context that is neither constexpr nor generic lambda.
Why do these three lookups find different functions?