diff options
| -rw-r--r-- | clang/include/clang/ASTMatchers/ASTMatchers.h | 11 | ||||
| -rw-r--r-- | clang/unittests/ASTMatchers/ASTMatchersTest.cpp | 5 |
2 files changed, 14 insertions, 2 deletions
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index 21a49691cd7..5a40fce60b1 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -3688,15 +3688,22 @@ AST_MATCHER(QualType, isAnyCharacter) { return Node->isAnyCharacterType(); } -//// \brief Matches QualType nodes that are of any pointer type. +/// \brief Matches QualType nodes that are of any pointer type; this includes +/// the Objective-C object pointer type, which is different despite being +/// syntactically similar. /// /// Given /// \code /// int *i = nullptr; +/// +/// @interface Foo +/// @end +/// Foo *f; +/// /// int j; /// \endcode /// varDecl(hasType(isAnyPointer())) -/// matches "int *i", but not "int j". +/// matches "int *i" and "Foo *f", but not "int j". AST_MATCHER(QualType, isAnyPointer) { return Node->isAnyPointerType(); } diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index 133dc70513c..a777e7f497c 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -1483,6 +1483,11 @@ TEST(IsAnyPointer, MatchesPointers) { EXPECT_TRUE(matches("int* i = nullptr;", varDecl(hasType(isAnyPointer())))); } +TEST(IsAnyPointer, MatchesObjcPointer) { + EXPECT_TRUE(matchesObjC("@interface Foo @end Foo *f;", + varDecl(hasType(isAnyPointer())))); +} + TEST(IsAnyPointer, ReportsNoFalsePositives) { EXPECT_TRUE(notMatches("int i = 0;", varDecl(hasType(isAnyPointer())))); } |

