Previous behavior was to instantiate constexpr function in the point where
it is used. It causes crash when compiling the following code:
template<typename T> constexpr T foo(T x) { return foo((int)x); }
The function template specialization foo<int> was instantiated because it
was used in the body of template foo<T> but definition of foo<T> is not
available yet.
With this change a constexpr function template specialization is instantiated
at the end of translation unit unless it is called in a constant expression
outside template definition.
This change also fixes PR33561.
It's not correct/reasonable to instantiate whenever an expression happens to be evaluated, in numerous ways:
Fundamentally, either constant expression evaluation needs to be side-effect free, or we need to distinguish between places where we happen to evaluate things and places where we evaluate things because the language requires them to be constant expressions. The current direction of CWG1581 is to make the "should we instantiate?" determination based solely on the syntactic context, which means that the constant expression evaluator should never trigger any instantiations.
In order to fix the case where a function/variable template specialization that is usable in a constant expression is defined after the point of use, I think we should check for pending instantiations of that function / variable template when we complete its definition, and perform those instantiations at that time.