Created attachment 57857 [details] Test case We are looking at bringing up the TigerVNC project to a more modern C++ style, and one thing was using nullptr instead of NULL. We were very glad when we found -Wzero-as-null-pointer-constant to help out with this. Unfortunately, it doesn't seem to do much for NULL in modern¹ gcc. It spots usage of "0", but not any "NULL". clang has no trouble finding both. I've attached a test case with some comments on the cases we've seen. ¹ gcc 5 spots some, but not all NULL
Hmm.. I found bug 77513, and r9-873. So I guess this is intentional? This makes the warning somewhat pointless. We want to make sure developers standardise on nullptr, both for style and since the behaviour of NULL is compiler dependent (if I'm understanding the C++ standard correctly). It's also annoying if there is not a consensus between clang and gcc here.
Found another case that neither gcc 5, gcc 13, nor clang complain about for some odd reason: > assert(thing == NULL); All three complain about: > assert(thing == 0); Not sure what's going on here.
And another odd case; gcc 5 complains about this: > const char *a; > a = NULL; but not: > const char *a = NULL; gcc 13 complains about neither, and clang about both.
If you want a diagnostic for that, you should add (or ask for) -Wnull-as-null-pointer-constant NULL is not zero. I want to get warned for 0 but not for NULL.
That may be, but -Wzero-as-null-pointer-constant is documented as facilitating conversion to "nullptr", which means it definitely should be complaining about NULL, since that might not be the same thing. Compatibility with clang would also make everyone's lives easier.
(In reply to Pierre Ossman from comment #5) > That may be, but -Wzero-as-null-pointer-constant is documented as > facilitating conversion to "nullptr", That documentation should be fixed to remove that sentence. > which means it definitely should be > complaining about NULL, since that might not be the same thing. You could move that sentence to a hypothetical -Wnull-as-null-pointer-constant. Otherwise, how should I transition from 0 to NULL? The name for the diagnostic is already taken. > Compatibility with clang would also make everyone's lives easier. Clang made a bad decision. They should probably fix it.
See also: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117059>