Issue 87008
Summary The nullPointerConstant matcher is problematic
Labels new issue
Assignees
Reporter GKxxQAQ
    Current definition of `clang::ast_matchers::nullPointerConstant` (in `clang/include/clang/ASTMatchers.h`) is

```cpp
AST_MATCHER_FUNCTION(internal::Matcher<Expr>, nullPointerConstant) {
  return anyOf(
      gnuNullExpr(), cxxNullPtrLiteralExpr(),
      integerLiteral(equals(0), hasParent(expr(hasType(pointerType())))));
}
```

The third argument to `anyOf` here is problematic, I think. Counterexample:

```cpp
int main() {
  int *p[1];
 p[0];
}
```

The integer literal `0` in `p[0]` is matched by `expr(nullPointerConstant())`.

Possible fix: use `integerLiteral(equals(0), hasParent(expr(implicitCastExpr(hasImplicitDestinationType(pointerType())))))` (not sure if it's right).
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to