Friend function template becomes available if enclosing class template is
instantiated. Now the check for redefinition do not handle correctly such
function template and some redefinitions are not diagnosed. The reason is
the friend function templates in the instantiated class do not have
bodies, as they are not used yet and the search for redefinition does not
take into account.
The change modifies redefinition check so that it can find the friend
function template definitions in instantiated classes. The check is based
on the new function, 'FunctionTemplateDecl::isDefined'. In addition to the
checks made by 'isThisDeclarationADefinition' it checks if the given
declaration has uninstantiated body.
This doesn't look right; the OldTemplateDecl might be FOK_None but could still have a definition as a friend.
I'm not convinced this is the right place for this check. There are two different cases here:
I think check (2) belongs in the template instantiation code rather than here. In fact, at the end of TemplateDeclInstantiator::VisitFunctionDecl, there is an attempt to enforce the relevant rule; it just doesn't get all the cases right.