Why is C++ allowing me to assign a const char to a const char *?​!

Viewed 4139

To my astonishment, this compiles:

const char* c_str()
{
    static const char nullchar = '\0';
    return nullchar;
}

and it introduced a bug in my code. Thankfully, I caught it.

Is this intentional by C++, or a compiler bug? Is there a reason why the data type is actively ignored?
It worked in Visual C++ 2010 and GCC, but I don't understand why it should work, given the obvious data type mismatch. (The static isn't necessary, either.)

8 Answers
Related