[PATCH] D21175: [include-fixer] do not index friend function declaration.
Eric Liu via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 9 02:35:10 PDT 2016
ioeric created this revision.
ioeric added a reviewer: bkramer.
ioeric added a subscriber: cfe-commits.
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`.
http://reviews.llvm.org/D21175
Files:
include-fixer/find-all-symbols/FindAllSymbols.cpp
unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
Index: unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
===================================================================
--- unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
+++ 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
Index: include-fixer/find-all-symbols/FindAllSymbols.cpp
===================================================================
--- include-fixer/find-all-symbols/FindAllSymbols.cpp
+++ 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.
//
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21175.60147.patch
Type: text/x-patch
Size: 2118 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160609/6d609f04/attachment.bin>
More information about the cfe-commits
mailing list