Skip to content

Commit 379e890

Browse files
authored
[include-cleaner] Add handling for FriendDecls (llvm#72125)
Fixes llvm#64382.
1 parent 055f377 commit 379e890

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

clang-tools-extra/include-cleaner/lib/WalkAST.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "clang/AST/ASTFwd.h"
1212
#include "clang/AST/Decl.h"
1313
#include "clang/AST/DeclCXX.h"
14+
#include "clang/AST/DeclFriend.h"
1415
#include "clang/AST/DeclTemplate.h"
1516
#include "clang/AST/Expr.h"
1617
#include "clang/AST/ExprCXX.h"
@@ -243,6 +244,14 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
243244
return true;
244245
}
245246

247+
bool VisitFriendDecl(FriendDecl *D) {
248+
// We already visit the TypeLoc properly, but need to special case the decl
249+
// case.
250+
if (auto *FD = D->getFriendDecl())
251+
report(D->getLocation(), FD);
252+
return true;
253+
}
254+
246255
bool VisitConceptReference(const ConceptReference *CR) {
247256
report(CR->getConceptNameLoc(), CR->getFoundDecl());
248257
return true;

clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,5 +550,10 @@ TEST(WalkAST, Concepts) {
550550
// FIXME: Foo should be explicitly referenced.
551551
testWalk("template<typename T> concept Foo = true;", "void func() { ^Foo auto x = 1; }");
552552
}
553+
554+
TEST(WalkAST, FriendDecl) {
555+
testWalk("void $explicit^foo();", "struct Bar { friend void ^foo(); };");
556+
testWalk("struct $explicit^Foo {};", "struct Bar { friend struct ^Foo; };");
557+
}
553558
} // namespace
554559
} // namespace clang::include_cleaner

0 commit comments

Comments
 (0)