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);
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);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits