I tested the following code with 3 compilers and got 3 different results: error, warning and ok.
- GCC (5.3): error: invalid user-defined conversion from ‘std::nullptr_t’ to ‘const Thing&’
- Clang (3.8): warning: implicit conversion of nullptr constant to 'bool'
- MSVC (14.1): no error, no warning
Which compiler is correct? I know it's a trivial conversion between a pointer type and bool
. But what's about std::nullptr_t
and bool
?
(In the end, Clang and MSVC are both fine with the code. Clang is a little bit more verbose in a positive way.)
struct Thing
{
Thing(bool) {}
};
void addThing(const Thing&){}
int main()
{
addThing(nullptr); // warning or error on this line
}