|
Boost : |
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2022-05-22 21:58:49
On 5/22/22 18:35, Peter Dimov wrote:
>> I did however not know that GCC doesn't warn on NULL. Interesting
>> compromise, even though I don't quite see the point of it.
>>
>> Clang does warn on NULL, however.
>
> I do see the point of it now. Under GCC the warning is pragmatically
> intended to catch actual mistakes such as mistyping
>
> while( *p != 0 )
>
> as
>
> while( p != 0 )
>
> so the warning only triggers on the actual 0, and is enabled under
> C++03 as well.
>
> Clang, and the various static analysis tools such as the MS analyzer,
> enforce a stylistic preference for nullptr, so they warn on both 0
> and NULL, but Clang doesn't warn in C++03 mode.
>
> Either way, I'm not looking forward to adding a bunch of lines to
> suppress the various warnings, instead of just telling the PR author
> to use BOOST_NULLPTR instead of nullptr.
We already have NULL as the portable macro, so I would still prefer it
to a Boost invention.
Again, that some compilers warn on NULL is a compiler bug and should be
treated as such, IMO. Compiler vendors should keep their stylistic
preferences to themselves, especially when they are impossible to follow
(in C++03 case). The use of NULL as a null pointer is perfectly valid,
in the sense of both formal C++ compliance and code readability.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk