fwolff created this revision. fwolff added reviewers: Eugene.Zelenko, alexfh, Szelethus. fwolff added a project: clang-tools-extra. Herald added subscribers: carlosgalvezp, xazax.hun. fwolff requested review of this revision. Herald added a subscriber: cfe-commits.
Fixes PR#48086 <https://bugs.llvm.org/show_bug.cgi?id=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()`. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D114299 Files: clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp clang-tools-extra/test/clang-tidy/checkers/readability-redundant-declaration.cpp Index: clang-tools-extra/test/clang-tidy/checkers/readability-redundant-declaration.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/readability-redundant-declaration.cpp +++ clang-tools-extra/test/clang-tidy/checkers/readability-redundant-declaration.cpp @@ -66,8 +66,14 @@ struct Friendly { friend void best_friend(); friend void enemy(); + + template <typename T> + friend void generic_friend(); }; +template <typename T> +void generic_friend() {} + void enemy(); namespace macros { Index: clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp +++ clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp @@ -37,7 +37,7 @@ functionDecl(unless(anyOf( isDefinition(), isDefaulted(), doesDeclarationForceExternallyVisibleDefinition(), - hasParent(friendDecl())))))) + hasAncestor(friendDecl())))))) .bind("Decl"), this); }
Index: clang-tools-extra/test/clang-tidy/checkers/readability-redundant-declaration.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/readability-redundant-declaration.cpp +++ clang-tools-extra/test/clang-tidy/checkers/readability-redundant-declaration.cpp @@ -66,8 +66,14 @@ struct Friendly { friend void best_friend(); friend void enemy(); + + template <typename T> + friend void generic_friend(); }; +template <typename T> +void generic_friend() {} + void enemy(); namespace macros { Index: clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp +++ clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp @@ -37,7 +37,7 @@ functionDecl(unless(anyOf( isDefinition(), isDefaulted(), doesDeclarationForceExternallyVisibleDefinition(), - hasParent(friendDecl())))))) + hasAncestor(friendDecl())))))) .bind("Decl"), this); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits