From: Daniel Jasper Date: Tue, 18 Sep 2012 13:36:17 +0000 (+0000) Subject: Add missing matcher for C-style cast expressions. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=417f77684b7283269ce5aa0997b8bf549a2f64f4;p=platform%2Fupstream%2Fllvm.git Add missing matcher for C-style cast expressions. Patch by Gábor Horváth. llvm-svn: 164123 --- diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index 9fdd933..2a1acdb 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -865,6 +865,16 @@ const internal::VariadicDynCastAllOfMatcher< Stmt, 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. /// /// Matches any cast expression written in user code, whether it be a diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index 348034f..b8ffaa4 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -2229,6 +2229,20 @@ TEST(StaticCast, DoesNotMatchOtherCasts) { staticCastExpr())); } +TEST(CStyleCast, MatchesSimpleCase) { + EXPECT_TRUE(matches("int i = (int) 2.2f;", cStyleCastExpr())); +} + +TEST(CStyleCast, DoesNotMatchOtherCasts) { + EXPECT_TRUE(notMatches("char* p = static_cast(0);" + "char q, *r = const_cast(&q);" + "void* s = reinterpret_cast(&s);" + "struct B { virtual ~B() {} }; struct D : B {};" + "B b;" + "D* t = dynamic_cast(&b);", + cStyleCastExpr())); +} + TEST(HasDestinationType, MatchesSimpleCase) { EXPECT_TRUE(matches("char* p = static_cast(0);", staticCastExpr(hasDestinationType(