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.
It seems to me that we're getting something fundamentally wrong in the way we model friend function definitions where we've instantiated the declaration but not the definition. Here's a case we get wrong on the non-function-template side:
Line 3 should be ill-formed here due to redefinition, but we don't detect that because we don't believe that the declaration we instantiated on line 2 is a definition. That seems to be the heart of the problem.
Instead of adding this function, can you try changing FunctionDecl::isThisDeclarationADefinition to contain the above logic (that is: if this function is a friend that was instantiated from a definition, then it's a definition even if we don't have a body yet)?