steveire created this revision. steveire added a reviewer: aaron.ballman. steveire requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Repository: rG LLVM Github Monorepo 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) { @@ -2278,6 +2286,7 @@ EXPECT_TRUE(matches(Code, traverse(TK_AsIs, MTempl))); // TODO: If we could match on explicit instantiations of function templates, // this would be EXPECT_TRUE. + // See Sema::ActOnExplicitInstantiation, EXPECT_FALSE( matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, MTempl))); } @@ -2324,6 +2333,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 @@ -1167,6 +1167,8 @@ } else if (const auto *FD = dyn_cast<FunctionDecl>(DeclNode)) { if (FD->isDefaulted()) ScopedChildren = true; + if (FD->isTemplateInstantiation()) + ScopedTraversal = true; } ASTNodeNotSpelledInSourceScope RAII1(this, ScopedTraversal);
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) { @@ -2278,6 +2286,7 @@ EXPECT_TRUE(matches(Code, traverse(TK_AsIs, MTempl))); // TODO: If we could match on explicit instantiations of function templates, // this would be EXPECT_TRUE. + // See Sema::ActOnExplicitInstantiation, EXPECT_FALSE( matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, MTempl))); } @@ -2324,6 +2333,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 @@ -1167,6 +1167,8 @@ } else if (const auto *FD = dyn_cast<FunctionDecl>(DeclNode)) { if (FD->isDefaulted()) ScopedChildren = true; + if (FD->isTemplateInstantiation()) + ScopedTraversal = true; } ASTNodeNotSpelledInSourceScope RAII1(this, ScopedTraversal);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits