On 22/05/2019 16:12, Jonny Grant wrote: > Hello > > This is a little test case. It is not real code. > > We used gcc-8 to get some warnings, but on the godbolt trunk gcc doesn't > those warnings with this little test case. Am I missing something > obvious? Is this an issue? > The warning is for treating 0 as a null pointer, but you are not doing that - you are using NULL as a null pointer. The whole point of nullptr is to have a way to give a null pointer that matches function overloads of pointer type rather than overloads of integer type: int foo(void*) { return 1; } int foo(int) { return 2; } Calling "foo(0)" will give you 2, which is not the result you want if you are wanting a null pointer. Calling "foo(nullptr)" will give you 1, which is the sensible result. Calling "foo(NULL)" will give you an error about ambiguous overloads. That is perhaps not great, but it will certainly avoid a quite error in the code. So there is no need for this warning to trigger on the use of NULL for a null pointer. (This is just my opinion as a user.) > with gcc-8 only (1) of the (3) occurrences of NULL is warned. > > Cheers, Jonny > > myfile.cpp:100:15 error: zero as null pointer constant > [-Werror=zero-as-null-pointer-constant] > if(NULL == format) > ^~~~~~ > > > Options > -Wall -Wextra -Werror=zero-as-null-pointer-constant > > > > #include <cstddef> > > int str(const char * const format, ...) > { > if(NULL == format) // gcc-8 warning > { > return -1; > } > > return 0; > } > > int main() > { > char * buf = NULL; > > str(buf); > > return (NULL == buf); > } >