[PATCH] D94032: [ASTMatchers] Omit methods from explicit template instantations
Stephen Kelly via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 5 09:43:08 PST 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf22c0f40b5d6: [ASTMatchers] Omit methods from explicit template instantations (authored by stephenkelly).
Changed prior to commit:
https://reviews.llvm.org/D94032?vs=314451&id=314643#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D94032/new/
https://reviews.llvm.org/D94032
Files:
clang/lib/ASTMatchers/ASTMatchFinder.cpp
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===================================================================
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -2201,10 +2201,18 @@
TemplStruct() {}
~TemplStruct() {}
+ void outOfLine(T);
+
private:
T m_t;
};
+template<typename T>
+void TemplStruct<T>::outOfLine(T)
+{
+
+}
+
template<typename T>
T timesTwo(T input)
{
@@ -2277,7 +2285,7 @@
hasTemplateArgument(0, refersToType(asString("float"))));
EXPECT_TRUE(matches(Code, traverse(TK_AsIs, MTempl)));
// TODO: If we could match on explicit instantiations of function templates,
- // this would be EXPECT_TRUE.
+ // this would be EXPECT_TRUE. See Sema::ActOnExplicitInstantiation.
EXPECT_FALSE(
matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, MTempl)));
}
@@ -2324,6 +2332,14 @@
EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
}
+ {
+ // Instantiated, out-of-line methods are not matchable.
+ auto M =
+ cxxMethodDecl(hasName("outOfLine"), isDefinition(),
+ hasParameter(0, parmVarDecl(hasType(asString("float")))));
+ EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+ EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+ }
{
// Explicit specialization is written in source and it matches:
auto M = classTemplateSpecializationDecl(
Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===================================================================
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1158,6 +1158,8 @@
} else if (const auto *FD = dyn_cast<FunctionDecl>(DeclNode)) {
if (FD->isDefaulted())
ScopedChildren = true;
+ if (FD->isTemplateInstantiation())
+ ScopedTraversal = true;
}
ASTNodeNotSpelledInSourceScope RAII1(this, ScopedTraversal);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94032.314643.patch
Type: text/x-patch
Size: 2075 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210105/fcc81f50/attachment.bin>
More information about the cfe-commits
mailing list