The function I want to run:
struct foo;
void bar(const foo* p = 0);
How I call the function:
auto thread = std::thread(&bar, NULL);
The warning:
foobar.h:223:9: warning: passing NULL to non-pointer argument 2 of ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (*)(const foo*), _Args = {int}]’ [-Wconversion-null]
What am I missing here?
When I call the function with non-NULL argument, the warning goes away.
0instead ofNULL? - wimhnullptrinstead ofNULLin C++ >= 11. - cdhowie_Argsis deduced from the arguments supplied to thestd::threadconstructor, which implies that whatever theNULLmacro evaluates to has typeint. The definition ofNULLis implementation-defined, so we'd have to know how it's defined in OP's case to understand why it has typeint. (Typically it's defined as((void *)0)in older C code. Obviously it has a different definition here -- probably just0, and0is implicitly convertible to any pointer type, but some randomint, which is what the0becomes as a parameter tostd::thread(), cannot.) - cdhowie