Revert "Revert "Implement nullPointerConstant() using a better API.""

This reverts commit 6984e0d439.

While change by itself seems to be consistent with nullPointerConstant
docs of not matching "int i = 0;" but it's not clear why it's wrong and
9148302a2a author just forgot to update
the doc.
This commit is contained in:
Mikhail Goncharov 2021-02-22 13:30:25 +01:00
parent cf3ef15a6e
commit ba1d9546ee
2 changed files with 4 additions and 5 deletions

View File

@ -7384,10 +7384,9 @@ extern const internal::VariadicDynCastAllOfMatcher<Stmt, CUDAKernelCallExpr>
/// expr(nullPointerConstant())
/// matches the initializer for v1, v2, v3, cp, and ip. Does not match the
/// initializer for i.
AST_MATCHER_FUNCTION(internal::Matcher<Expr>, nullPointerConstant) {
return anyOf(
gnuNullExpr(), cxxNullPtrLiteralExpr(),
integerLiteral(equals(0), hasParent(expr(hasType(pointerType())))));
AST_MATCHER(Expr, nullPointerConstant) {
return Node.isNullPointerConstant(Finder->getASTContext(),
Expr::NPC_ValueDependentIsNull);
}
/// Matches the DecompositionDecl the binding belongs to.

View File

@ -3663,7 +3663,7 @@ TEST_P(ASTMatchersTest, NullPointerConstant) {
expr(nullPointerConstant())));
EXPECT_TRUE(matches("char *cp = (char *)0;", expr(nullPointerConstant())));
EXPECT_TRUE(matches("int *ip = 0;", expr(nullPointerConstant())));
EXPECT_FALSE(matches("int i = 0;", expr(nullPointerConstant())));
EXPECT_TRUE(matches("int i = 0;", expr(nullPointerConstant())));
}
TEST_P(ASTMatchersTest, NullPointerConstant_GNUNull) {