Skip to content

Commit

Permalink
[include-fixer] do not index friend function declaration.
Browse files Browse the repository at this point in the history
Summary:
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`.

Reviewers: bkramer

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D21175

llvm-svn: 272261
  • Loading branch information
Eric Liu committed Jun 9, 2016
1 parent 8b5b61a commit 1899d54
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,14 @@ void FindAllSymbols::registerMatchers(MatchFinder *MatchFinder) {
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.
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,5 +433,26 @@ TEST_F(FindAllSymbolsTest, MacroTestWithIWYU) {
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

0 comments on commit 1899d54

Please sign in to comment.