I goggled it & tried to find similar question on SO also but didn't find anything useful. So, posting my question here.
Consider this program:
#include <iostream>
void foo(const std::string &) {}
int main()
{
foo(false);
}
[Warning] converting 'false' to pointer type for argument 1 of 'std::basic_string::basic_string(const _CharT*, const _Alloc&) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator]' [-Wconversion-null]
Why C++ allows this without explicit cast? I was expecting to get compiler error. The program abnormally terminates at runtime due to exception displaying following:
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct null not valid
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
What the standard says about this type of implicit conversion?
false
can be implicilty casted toconst char*
as null pointer. - undermind