diff options
-rw-r--r-- | include/clang/ASTMatchers/ASTMatchers.h | 12 | ||||
-rw-r--r-- | unittests/ASTMatchers/ASTMatchersTest.cpp | 7 |
2 files changed, 19 insertions, 0 deletions
diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h index 712b324d75..b26bc62c99 100644 --- a/include/clang/ASTMatchers/ASTMatchers.h +++ b/include/clang/ASTMatchers/ASTMatchers.h @@ -546,6 +546,18 @@ const internal::VariadicDynCastAllOfMatcher< Stmt, CXXConstructExpr> constructExpr; +/// \brief Matches implicit and explicit this expressions. +/// +/// Example matches the implicit this expression in "return i". +/// (matcher = thisExpr()) +/// \code +/// struct foo { +/// int i; +/// int f() { return i; } +/// }; +/// \endcode +const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThisExpr> thisExpr; + /// \brief Matches nodes where temporaries are created. /// /// Example matches FunctionTakesString(GetStringByValue()) diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index 5c97f3abac..a97e90d74c 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -1333,6 +1333,13 @@ TEST(Matcher, ConstructorArgumentCount) { Constructor1Arg)); } +TEST(Matcher,ThisExpr) { + EXPECT_TRUE( + matches("struct X { int a; int f () { return a; } };", thisExpr())); + EXPECT_TRUE( + notMatches("struct X { int f () { int a; return a; } };", thisExpr())); +} + TEST(Matcher, BindTemporaryExpression) { StatementMatcher TempExpression = bindTemporaryExpr(); |