Fixes PR#48086. The problem is that the current matcher uses hasParent() to detect friend declarations, but for a template friend declaration, the immediate parent of the FunctionDecl is a FunctionTemplateDecl, not the FriendDecl. Therefore, I have replaced the matcher with hasAncestor().
Details
Details
Diff Detail
Diff Detail
Event Timeline
Comment Actions
Hmm, the test case you added passes without the patch applied: https://godbolt.org/z/T9TerMYGz
I think the issue is that the class needs to be an instantiated template type: https://godbolt.org/z/bhznPdsvf, and a second (interesting but contrived) test case would be:
template <typename> struct Friendly { template <typename T> friend void generic_friend() {} }; template <typename T> void generic_friend(); int main() { Friendly<int> f; generic_friend<int>(); }
(We do NOT want to diagnose the second declaration of generic_friend as being redundant -- it is necessary to make the definition visible.)
Comment Actions
You are right; I have fixed the test now, and I've also added your other example as a second test.
Comment Actions
I'm a bit worried about using hasAncestor() (that has a tendency to match in surprising nested locations), but I can't come up with a test case that would be an issue, so this LGTM.