Whether false
is allowed to be implicitly converted to pointer is different between clang++ and g++:
g++-4.8: always a warning with or without -std=c++11
clang++ (trunk): a warning if without -std=c++11, and an error if with -std=c++11
So anyone knows why g++ and clang++ behaves differently, and who is correct? What paragraphs in C++ standard (both C++03 and C++11) talks about the situation.
Thanks.
[hidden ~]$ cat b.cpp
const char* f() { return false; }
[hidden ~]$ g++ -c b.cpp
b.cpp: In function ‘const char* f()’:
b.cpp:1:26: warning: converting ‘false’ to pointer type ‘const char*’ [-Wconversion-null]
const char* f() { return false; }
^
[hidden ~]$ g++ -std=c++11 -c b.cpp
b.cpp: In function ‘const char* f()’:
b.cpp:1:26: warning: converting ‘false’ to pointer type ‘const char*’ [-Wconversion-null]
const char* f() { return false; }
^
[hidden ~]$ clang++ -c b.cpp
b.cpp:1:26: warning: initialization of pointer of type 'const char *' to null from a constant boolean expression [-Wbool-conversion]
const char* f() { return false; }
^~~~~
1 warning generated.
[hidden ~]$ clang++ -std=c++11 -c b.cpp
b.cpp:1:26: error: cannot initialize return object of type 'const char *' with an rvalue of type 'bool'
const char* f() { return false; }
^~~~~
1 error generated.
See Question&Answers more detail:os