HotSpot doesn't use NULL
Kim Barrett
kim.barrett at oracle.com
Tue Nov 26 00:25:38 UTC 2024
On 11/25/24 7:16 AM, Kennke, Roman wrote:
> Is it possible - and would it make sense - to mechanically forbit NULL? E.g. by re-defining it in a central place, just like we do for other stuff like constuctors for certain things?
I don't think so.
Redefining it in a way that makes it unusable seems problematic because it
might affect non-HotSpot code. An example where I'm pretty sure this
would be
a problem is gtest.
Redefining it in a way that still works, as is currently done for
Windows (see
JDK-8324686) doesn't prevent adding new uses.
Something like the suggestion in JDK-8343802 is the only viable approach
I've
been able to come up with. I've seen discussion that maybe there should
be a
gcc -Wnull-as-null-pointer-constant (alongside the existing
-Wzero-as-null-pointer-constant), but that doesn't currently exist, and
would
only help for gcc-based platforms.
clang-tidy has modernize-use-nullptr: "The check converts the usage of null
pointer constants (e.g. NULL, 0) to use the new C++11 and C23 nullptr
keyword." Perhaps something could be built on that? Doing so is likely more
work than the grep-based approach suggested in JDK-8343802.
More information about the hotspot-dev
mailing list