Add missing matcher for C-style cast expressions.

Patch by Gábor Horváth.

llvm-svn: 164123
This commit is contained in:
Daniel Jasper 2012-09-18 13:36:17 +00:00
parent a73727143a
commit 417f77684b
2 changed files with 24 additions and 0 deletions

View File

@ -865,6 +865,16 @@ const internal::VariadicDynCastAllOfMatcher<
Stmt, Stmt,
CXXConstCastExpr> constCastExpr; CXXConstCastExpr> constCastExpr;
/// \brief Matches a C-style cast expression.
///
/// Example: Matches (int*) 2.2f in
/// \code
/// int i = (int) 2.2f;
/// \endcode
const internal::VariadicDynCastAllOfMatcher<
Stmt,
CStyleCastExpr> cStyleCastExpr;
/// \brief Matches explicit cast expressions. /// \brief Matches explicit cast expressions.
/// ///
/// Matches any cast expression written in user code, whether it be a /// Matches any cast expression written in user code, whether it be a

View File

@ -2229,6 +2229,20 @@ TEST(StaticCast, DoesNotMatchOtherCasts) {
staticCastExpr())); staticCastExpr()));
} }
TEST(CStyleCast, MatchesSimpleCase) {
EXPECT_TRUE(matches("int i = (int) 2.2f;", cStyleCastExpr()));
}
TEST(CStyleCast, DoesNotMatchOtherCasts) {
EXPECT_TRUE(notMatches("char* p = static_cast<char*>(0);"
"char q, *r = const_cast<char*>(&q);"
"void* s = reinterpret_cast<char*>(&s);"
"struct B { virtual ~B() {} }; struct D : B {};"
"B b;"
"D* t = dynamic_cast<D*>(&b);",
cStyleCastExpr()));
}
TEST(HasDestinationType, MatchesSimpleCase) { TEST(HasDestinationType, MatchesSimpleCase) {
EXPECT_TRUE(matches("char* p = static_cast<char*>(0);", EXPECT_TRUE(matches("char* p = static_cast<char*>(0);",
staticCastExpr(hasDestinationType( staticCastExpr(hasDestinationType(