r262806 - [ASTMatchers] Document that isAnyPointer() matcher also matches Objective-C object pointers.
Felix Berger via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 6 07:28:00 PST 2016
Author: flx
Date: Sun Mar 6 09:27:59 2016
New Revision: 262806
URL: http://llvm.org/viewvc/llvm-project?rev=262806&view=rev
Log:
[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
Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=262806&r1=262805&r2=262806&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Sun Mar 6 09:27:59 2016
@@ -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();
}
Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=262806&r1=262805&r2=262806&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Sun Mar 6 09:27:59 2016
@@ -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()))));
}
More information about the cfe-commits
mailing list