[clang] Fix false match on nullPointerConstant for array indices (PR #201893)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 24 09:19:26 PDT 2026


================
@@ -980,6 +980,8 @@ AST Matchers
 ------------
 - Add ``functionTypeLoc`` matcher for matching ``FunctionTypeLoc``.
 - Add missing support for ``TraversalKind`` in some ``addMatcher()`` overloads.
+- Fixed ``nullPointerConstant`` matcher falsely matching integer literal ``0``
----------------
AaronBallman wrote:

While you can swap the array and the index around in some language modes (so `array[idx]` and `idx[array]` are equivalent), that doesn't work with integer literals without casts and so we don't have to worry about a pathological case like: `int index = 0; index[0];` Phew. :-D

That said, I think this isn't quite accurate because you're also fixing other false positives like `int *ptr; ptr + 0;`: https://godbolt.org/z/hhMoTW7e8

https://github.com/llvm/llvm-project/pull/201893


More information about the cfe-commits mailing list