Index: clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp =================================================================== --- clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp +++ clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp @@ -161,9 +161,14 @@ MatchFinder->addMatcher(CxxRecordDecl.bind("decl"), this); // Matchers for function declarations. - MatchFinder->addMatcher( - functionDecl(CommonFilter, anyOf(ExternCMatcher, CCMatcher)).bind("decl"), - this); + // We want to exclude friend declaration, but the `DeclContext` of a friend + // function declaration is not the class in which it is declared, so we need + // to explicitly check if the parent is a `friendDecl`. + MatchFinder->addMatcher(functionDecl(CommonFilter, + unless(hasParent(friendDecl())), + anyOf(ExternCMatcher, CCMatcher)) + .bind("decl"), + this); // Matcher for typedef and type alias declarations. // Index: clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp =================================================================== --- clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp +++ clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp @@ -433,5 +433,26 @@ EXPECT_TRUE(hasSymbol(Symbol)); } +TEST_F(FindAllSymbolsTest, NoFriendTest) { + static const char Code[] = R"( + class WorstFriend { + friend void Friend(); + friend class BestFriend; + }; + )"; + runFindAllSymbols(Code); + SymbolInfo Symbol = SymbolInfo("WorstFriend", SymbolInfo::SymbolKind::Class, + HeaderName, 2, {}); + EXPECT_TRUE(hasSymbol(Symbol)); + + Symbol = SymbolInfo("Friend", SymbolInfo::SymbolKind::Function, HeaderName, + 3, {}); + EXPECT_FALSE(hasSymbol(Symbol)); + + Symbol = SymbolInfo("BestFriend", SymbolInfo::SymbolKind::Class, HeaderName, + 4, {}); + EXPECT_FALSE(hasSymbol(Symbol)); +} + } // namespace find_all_symbols } // namespace clang