[clang-tools-extra] r272261 - [include-fixer] do not index friend function declaration.
Eric Liu via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 9 07:18:40 PDT 2016
Author: ioeric
Date: Thu Jun 9 09:18:40 2016
New Revision: 272261
URL: http://llvm.org/viewvc/llvm-project?rev=272261&view=rev
Log:
[include-fixer] do not index friend function declaration.
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
Modified:
clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp
clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
Modified: clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp?rev=272261&r1=272260&r2=272261&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp Thu Jun 9 09:18:40 2016
@@ -161,9 +161,14 @@ void FindAllSymbols::registerMatchers(Ma
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.
//
Modified: clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp?rev=272261&r1=272260&r2=272261&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp Thu Jun 9 09:18:40 2016
@@ -433,5 +433,26 @@ TEST_F(FindAllSymbolsTest, MacroTestWith
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
More information about the cfe-commits
mailing list