r212001 - Add a matcher for SubstNonTypeTemplateParmExpr.
Alexander Kornienko
alexfh at google.com
Sun Jun 29 15:18:54 PDT 2014
Author: alexfh
Date: Sun Jun 29 17:18:53 2014
New Revision: 212001
URL: http://llvm.org/viewvc/llvm-project?rev=212001&view=rev
Log:
Add a matcher for SubstNonTypeTemplateParmExpr.
Reviewers: klimek, djasper
Reviewed By: djasper
Subscribers: klimek, aemerson, cfe-commits
Differential Revision: http://reviews.llvm.org/D4327
Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=212001&r1=212000&r2=212001&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Sun Jun 29 17:18:53 2014
@@ -686,10 +686,23 @@ exprWithCleanups;
/// struct B { int x, y; };
/// B b = { 5, 6 };
/// \endcode
-/// initList()
+/// initListExpr()
/// matches "{ 1, 2 }" and "{ 5, 6 }"
const internal::VariadicDynCastAllOfMatcher<Stmt, InitListExpr> initListExpr;
+/// \brief Matches substitutions of non-type template parameters.
+///
+/// Given
+/// \code
+/// template <int N>
+/// struct A { static const int n = N; };
+/// struct B : public A<42> {};
+/// \endcode
+/// substNonTypeTemplateParmExpr()
+/// matches "N" in the right-hand side of "static const int n = N;"
+const internal::VariadicDynCastAllOfMatcher<Stmt, SubstNonTypeTemplateParmExpr>
+substNonTypeTemplateParmExpr;
+
/// \brief Matches using declarations.
///
/// Given
Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=212001&r1=212000&r2=212001&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Sun Jun 29 17:18:53 2014
@@ -1017,6 +1017,17 @@ TEST(Matcher, ForRange) {
forRangeStmt()));
}
+TEST(Matcher, SubstNonTypeTemplateParm) {
+ EXPECT_FALSE(matches("template<int N>\n"
+ "struct A { static const int n = 0; };\n"
+ "struct B : public A<42> {};",
+ substNonTypeTemplateParmExpr()));
+ EXPECT_TRUE(matches("template<int N>\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;"
More information about the cfe-commits
mailing list