Today I made a small typo in my program, and was wandering why I wasn't getting any output, although the program compiled fine. Basically it reduces to this:
#include <iostream>
int main()
{
std::cout < "test"; // no << but <
}
I have absolutely no idea what kind of implicit conversion is performed here so the program still compiles (both g++4.9.2 and even g++5). I just realized that clang++ rejects the code. Is there a conversion to void*
being performed (cannot think of anything else)? I remember seeing something like this, but I thought it was addressed in g++5, but this doesn't seem to be the case.
EDIT: I was not compiling with -std=c++11
, so the code was valid in pre-C++11 (due to conversion to void*
of ostream
). When compiling with -std=c++11
g++5 rejects the code, g++4.9 still accepts it.
-Wall
though. – Iberia-Wall
, however this was a tiny piece of code that I compiled in sublime text and realized it magically works – Thought(void*)std::cout
with a string literal decayed to aconst char
pointer, and the comparison seem to be false. See the answers to understand why the conversion. – Thought