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:
parent
2019cea863
commit
f10662923a
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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]")))));
|
||||
|
|
Loading…
Reference in New Issue