diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h index 6a5f5ee57c51c3eb7e27d4e7c3c2889dba9d21cf..6fcae748d8225abd9849182bf687411b121e3042 100644 --- a/include/clang/ASTMatchers/ASTMatchers.h +++ b/include/clang/ASTMatchers/ASTMatchers.h @@ -3533,6 +3533,20 @@ AST_MATCHER(QualType, isInteger) { return Node->isIntegerType(); } +/// \brief Matches QualType nodes that are of character type. +/// +/// Given +/// \code +/// void a(char); +/// void b(wchar_t); +/// void c(double); +/// \endcode +/// functionDecl(hasAnyParameter(hasType(isAnyCharacter()))) +/// matches "a(char)", "b(wchar_t)", but not "c(double)". +AST_MATCHER(QualType, isAnyCharacter) { + return Node->isAnyCharacterType(); +} + /// \brief Matches QualType nodes that are const-qualified, i.e., that /// include "top-level" const. /// diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index 9aefb07809173b4abad9da4239853bf81185ab04..80f234338a3e0555aec2366d36b54a1de3fac11f 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -1469,6 +1469,14 @@ TEST(IsInteger, ReportsNoFalsePositives) { to(varDecl(hasType(isInteger())))))))); } +TEST(IsAnyCharacter, MatchesCharacters) { + EXPECT_TRUE(matches("char i = 0;", varDecl(hasType(isAnyCharacter())))); +} + +TEST(IsAnyCharacter, ReportsNoFalsePositives) { + EXPECT_TRUE(notMatches("int i;", varDecl(hasType(isAnyCharacter())))); +} + TEST(IsArrow, MatchesMemberVariablesViaArrow) { EXPECT_TRUE(matches("class Y { void x() { this->y; } int y; };", memberExpr(isArrow())));