Add matcher for ExprWithCleanups.

Summary: Add matcher for ExprWithCleanups.

Reviewers: klimek

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D3248

llvm-svn: 205420
This commit is contained in:
Samuel Benzaquen 2014-04-02 13:12:14 +00:00
parent 2019cea863
commit f10662923a
3 changed files with 20 additions and 0 deletions

View File

@ -662,6 +662,16 @@ const internal::VariadicDynCastAllOfMatcher<
Stmt,
CXXMemberCallExpr> memberCallExpr;
/// \brief Matches expressions that introduce cleanups to be run at the end
/// of the sub-expression's evaluation.
///
/// Example matches std::string()
/// \code
/// const std::string str = std::string();
/// \endcode
const internal::VariadicDynCastAllOfMatcher<Stmt, ExprWithCleanups>
exprWithCleanups;
/// \brief Matches init list expressions.
///
/// Given

View File

@ -149,6 +149,7 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(equalsBoundNode);
REGISTER_MATCHER(explicitCastExpr);
REGISTER_MATCHER(expr);
REGISTER_MATCHER(exprWithCleanups);
REGISTER_MATCHER(fieldDecl);
REGISTER_MATCHER(floatLiteral);
REGISTER_MATCHER(forEach);

View File

@ -2943,6 +2943,15 @@ TEST(DeclarationStatement, MatchesVariableDeclarationStatements) {
EXPECT_TRUE(matches("void x() { int a; }", declStmt()));
}
TEST(ExprWithCleanups, MatchesExprWithCleanups) {
EXPECT_TRUE(matches("struct Foo { ~Foo(); };"
"const Foo f = Foo();",
varDecl(hasInitializer(exprWithCleanups()))));
EXPECT_FALSE(matches("struct Foo { };"
"const Foo f = Foo();",
varDecl(hasInitializer(exprWithCleanups()))));
}
TEST(InitListExpression, MatchesInitListExpression) {
EXPECT_TRUE(matches("int a[] = { 1, 2 };",
initListExpr(hasType(asString("int [2]")))));