Author: kadir çetinkaya Date: 2023-11-13T16:35:52+01:00 New Revision: 379e890bd88573c66499de1e9e8d63954e3b6c31
URL: https://github.com/llvm/llvm-project/commit/379e890bd88573c66499de1e9e8d63954e3b6c31 DIFF: https://github.com/llvm/llvm-project/commit/379e890bd88573c66499de1e9e8d63954e3b6c31.diff LOG: [include-cleaner] Add handling for FriendDecls (#72125) Fixes https://github.com/llvm/llvm-project/issues/64382. Added: Modified: clang-tools-extra/include-cleaner/lib/WalkAST.cpp clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp index 307e0652f9ccaf8..6c4d9b7862d915b 100644 --- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp +++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp @@ -11,6 +11,7 @@ #include "clang/AST/ASTFwd.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" +#include "clang/AST/DeclFriend.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" @@ -243,6 +244,14 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> { return true; } + bool VisitFriendDecl(FriendDecl *D) { + // We already visit the TypeLoc properly, but need to special case the decl + // case. + if (auto *FD = D->getFriendDecl()) + report(D->getLocation(), FD); + return true; + } + bool VisitConceptReference(const ConceptReference *CR) { report(CR->getConceptNameLoc(), CR->getFoundDecl()); return true; diff --git a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp index 9b99d5a5c32bad3..bdfc24b8edee38f 100644 --- a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp +++ b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp @@ -550,5 +550,10 @@ TEST(WalkAST, Concepts) { // FIXME: Foo should be explicitly referenced. testWalk("template<typename T> concept Foo = true;", "void func() { ^Foo auto x = 1; }"); } + +TEST(WalkAST, FriendDecl) { + testWalk("void $explicit^foo();", "struct Bar { friend void ^foo(); };"); + testWalk("struct $explicit^Foo {};", "struct Bar { friend struct ^Foo; };"); +} } // namespace } // namespace clang::include_cleaner _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits