Index: include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- include/clang/ASTMatchers/ASTMatchers.h +++ include/clang/ASTMatchers/ASTMatchers.h @@ -3547,6 +3547,19 @@ return Node->isAnyCharacterType(); } +//// \brief Matches QualType nodes that are of any pointer type. +/// +/// Given +/// \code +/// int *i = nullptr; +/// int j; +/// \endcode +/// varDecl(hasType(isAnyPointer())) +/// matches "int *i", but not "int j". +AST_MATCHER(QualType, isAnyPointer) { + return Node->isAnyPointerType(); +} + /// \brief Matches QualType nodes that are const-qualified, i.e., that /// include "top-level" const. /// Index: lib/ASTMatchers/Dynamic/Registry.cpp =================================================================== --- lib/ASTMatchers/Dynamic/Registry.cpp +++ lib/ASTMatchers/Dynamic/Registry.cpp @@ -261,6 +261,8 @@ REGISTER_MATCHER(innerType); REGISTER_MATCHER(integerLiteral); REGISTER_MATCHER(isAnonymous); + REGISTER_MATCHER(isAnyCharacter); + REGISTER_MATCHER(isAnyPointer); REGISTER_MATCHER(isArrow); REGISTER_MATCHER(isBaseInitializer); REGISTER_MATCHER(isCatchAll); @@ -268,6 +270,7 @@ REGISTER_MATCHER(isConst); REGISTER_MATCHER(isConstQualified); REGISTER_MATCHER(isCopyConstructor); + REGISTER_MATCHER(isCopyAssignmentOperator); REGISTER_MATCHER(isDefaultConstructor); REGISTER_MATCHER(isDefinition); REGISTER_MATCHER(isDeleted); Index: unittests/ASTMatchers/ASTMatchersTest.cpp =================================================================== --- unittests/ASTMatchers/ASTMatchersTest.cpp +++ unittests/ASTMatchers/ASTMatchersTest.cpp @@ -1469,6 +1469,14 @@ to(varDecl(hasType(isInteger())))))))); } +TEST(IsAnyPointer, MatchesPointers) { + EXPECT_TRUE(matches("int* i = nullptr;", varDecl(hasType(isAnyPointer())))); +} + +TEST(IsAnyPointer, ReportsNoFalsePositives) { + EXPECT_TRUE(notMatches("int i = 0;", varDecl(hasType(isAnyPointer())))); +} + TEST(IsAnyCharacter, MatchesCharacters) { EXPECT_TRUE(matches("char i = 0;", varDecl(hasType(isAnyCharacter())))); }