Index: include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- include/clang/ASTMatchers/ASTMatchers.h +++ include/clang/ASTMatchers/ASTMatchers.h @@ -690,6 +690,19 @@ /// matches "{ 1, 2 }" and "{ 5, 6 }" const internal::VariadicDynCastAllOfMatcher initListExpr; +/// \brief Matches substitutions of non-type template parameters. +/// +/// Given +/// \code +/// template +/// struct A { static const int n = N; }; +/// struct B : public A<42> {}; +/// \endcode +/// initList() +/// matches "N" in the right-hand side of "static const int n = N;" +const internal::VariadicDynCastAllOfMatcher +substNonTypeTemplateParmExpr; + /// \brief Matches using declarations. /// /// Given Index: unittests/ASTMatchers/ASTMatchersTest.cpp =================================================================== --- unittests/ASTMatchers/ASTMatchersTest.cpp +++ unittests/ASTMatchers/ASTMatchersTest.cpp @@ -1017,6 +1017,17 @@ forRangeStmt())); } +TEST(Matcher, SubstNonTypeTemplateParm) { + EXPECT_FALSE(matches("template\n" + "struct A { static const int n = 0; };\n" + "struct B : public A<42> {};", + substNonTypeTemplateParmExpr())); + EXPECT_TRUE(matches("template\n" + "struct A { static const int n = N; };\n" + "struct B : public A<42> {};", + substNonTypeTemplateParmExpr())); +} + TEST(Matcher, UserDefinedLiteral) { EXPECT_TRUE(matches("constexpr char operator \"\" _inc (const char i) {" " return i + 1;"