This testcase was breaking because is_same::operator() is only used in constexpr evaluation, so cgraph decides it isn't used and throws it away. Then mangling tries to use it for constexpr evaluation while re-instantiating F under get_mostly_instantiated_function_type, and sadness ensues. It occurred to me that we really ought to be able to avoid re-doing this instantiation, since DECL_TI_TEMPLATE of a function is a partially instantiated template that already has the type we want. And indeed this seems to work well, even fixing a bug in mangling. Tested x86_64-pc-linux-gnu, applying to trunk.