Fixed #5097 (TemplateSimplifier::expandTemplate assertion failure)