From: Felix Berger Date: Sun, 6 Mar 2016 15:27:59 +0000 (+0000) Subject: [ASTMatchers] Document that isAnyPointer() matcher also matches Objective-C object... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=be393191c2e635290725d23de779ed10e01f9f90;p=clang [ASTMatchers] Document that isAnyPointer() matcher also matches Objective-C object pointers. Summary: Add test for Objective-C object pointer matching. Reviewers: aaron.ballman Subscribers: klimek Differential Revision: http://reviews.llvm.org/D17489 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@262806 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h index 21a49691cd..5a40fce60b 100644 --- a/include/clang/ASTMatchers/ASTMatchers.h +++ b/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/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index 133dc70513..a777e7f497 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/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())))); }