[PATCH] D21175: [include-fixer] do not index friend function declaration.
Eric Liu via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 9 07:25:22 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL272261: [include-fixer] do not index friend function declaration. (authored by ioeric).
Changed prior to commit:
http://reviews.llvm.org/D21175?vs=60147&id=60168#toc
Repository:
rL LLVM
http://reviews.llvm.org/D21175
Files:
clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp
clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
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
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.
//
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21175.60168.patch
Type: text/x-patch
Size: 2262 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160609/68a72f56/attachment.bin>
More information about the cfe-commits
mailing list