On 26 September 2011 05:29, Ian Lance Taylor wrote:
> Jon Grant <j...@jguk.org> writes:
>
>> Currently gcc, and g++ don't give a warning when a pointer was
>> converted to a bool, in the same way it is for other types.

At least in C++, it's not really true to say "in the same way it is
for other types" because you cannot convert from a pointer to any
integer type except bool.  Your test uses NULL for the other integer
types, which is an integral constant expression with value zero, so
it's ok to convert that to an integer type. That's not true for
general pointer values: if your test used m_int(g_glob) then it
wouldn't compile.

> There is a lot of code which uses
>    if (p)
> where p is a pointer to test whether p is not NULL.  I don't think we
> could reasonably have gcc warn about such a case.
>
> We might be able to separate out conversion to bool on assignment from
> conversion to bool in a test, though.

That would still break this:

Base* p = getObj();
bool is_derived = dynamic_cast<Derived*>(p);

What problem is the warning supposed to solve?

Reply via email to