Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=48086 | 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()`.
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D114299
functionDecl(unless(anyOf(
isDefinition(), isDefaulted(),
doesDeclarationForceExternallyVisibleDefinition(),
- hasParent(friendDecl()))))))
+ hasAncestor(friendDecl()))))))
.bind("Decl"),
this);
}
void enemy();
+template <typename>
+struct TemplateFriendly {
+ template <typename T>
+ friend void generic_friend();
+};
+
+template <typename T>
+void generic_friend() {}
+
+TemplateFriendly<int> template_friendly;
+
+template <typename>
+struct TemplateFriendly2 {
+ template <typename T>
+ friend void generic_friend2() {}
+};
+
+template <typename T>
+void generic_friend2();
+
+void generic_friend_caller() {
+ TemplateFriendly2<int> f;
+ generic_friend2<int>();
+}
+
+
namespace macros {
#define DECLARE(x) extern int x
#define DEFINE(x) extern int x; int x = 42