[clang] [C] Update -Wimplicit-void-ptr-cast for null pointer constants (PR #138271)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue May 20 05:52:32 PDT 2025
AaronBallman wrote:
> > Just to confirm: is it intended that `char *s = NULL;` now generates this warning? I mean, the C library may define `NULL` as `((void*)0)`, and `char *s = ((void*)0);` is clearly not C++-compatible. However, when compiling this code in C++, `NULL` may expand to something that IS actually okay in C++ (like `0`, `nullptr` or `__null`). So this warning may be a bit too noisy overall?
> > https://gcc.godbolt.org/z/hnMfsPjsa
>
> Hmmm, semi-intended. It's intended to diagnose `void foo(void *ptr) { char *s = ptr; }`, but a null pointer constant initialization, regardless of form (`nullptr`, `(void *)0`, `__null`, etc) should not be diagnosed. So I think I need to be more clever here; I'll work on a fix (thought it likely won't be until tomorrow at this point). Thank you for bringing this up!
https://github.com/llvm/llvm-project/pull/140724 should address this concern
https://github.com/llvm/llvm-project/pull/138271
More information about the cfe-commits
mailing list