Unverified Commit 379e890b authored by kadir çetinkaya's avatar kadir çetinkaya Committed by GitHub
Browse files

[include-cleaner] Add handling for FriendDecls (#72125)

parent 055f3773
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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 @@ public:
    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;
+5 −0
Original line number Diff line number Diff line
@@ -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