[vbox-dev] [PATCH 2/8] Fix an implicit conversion from pointer to bool
Michal Necasek
michal.necasek at oracle.com
Thu Mar 26 18:03:43 UTC 2015
The question isn't whether a compiler can warn. The question is, why should it?
What you quoted doesn't contradict what Frank said. There is a very well defined pointer to bool conversion. So what's the problem? Or in other words, what is the semantic difference between
if (ptr)
and
if (ptr != NULL)
(in whatever is the today's blessed flavor of C++)? It's not obvious to me.
Regards,
Michal
----- Original Message -----
From: jkim at FreeBSD.org
To: frank.mehnert at oracle.com, vbox-dev at virtualbox.org
Sent: Thursday, March 26, 2015 6:50:08 PM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna
Subject: Re: [vbox-dev] [PATCH 2/8] Fix an implicit conversion from pointer to bool
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
On 03/26/2015 04:51, Frank Mehnert wrote:
> Hi,
>
> On Friday 13 March 2015 16:56:56 Jung-uk Kim wrote:
>> This fix an implicit conversion from pointer to bool.
>
> why is this patch necessary? An expression like
>
> if (pointer) { }
>
> is completely valid and no compiler should warn about it. It tests
> if the pointer has a value different from NULL.
Pointer is NOT bool. Actually, the pointer is *implicitly* converted
to bool type here and compiler can warn about it. Excerpt from C++11:
4.12 Boolean conversions
A prvalue of arithmetic, unscoped enumeration, pointer, or pointer to
member type can be converted to a prvalue of type bool. A zero value,
null pointer value, or null member pointer value is converted to
false; any other value is converted to true. A prvalue of type
std::nullptr_t can be converted to a prvalue of type bool; the
resulting value is false.
> Would
>
> - || ( (a_pVCpu) /*!= NULL*/ \ + || ( a_pVCpu
> \
>
> fix the compiler warning as well?
No, I don't think so.
Jung-uk Kim
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQEcBAEBCAAGBQJVFEasAAoJEHyflib82/FGx2QH+QFvlUHYOpr7XvLgElyYMuQu
hrm+ycpPH54xXf+zb9XGCnbLl4OBwil0Pe4SbLQ1W6feX2PufIcRaZmPfytUlE0W
LHLAaFboeRTEBjbzfpqfDEADHsD4pEDFwp1zIZsL63snmqzdIyXwA47MPxMBmGLO
/0KjHWbfUZ2crQZ4gKCgZDNvf4H43bRtDD8cF9D4YYKrRxpCc8jDTFThS05PcxkJ
1+i2LDCSAkRk/JrRpw2TLAjhDi3Bxvdbi7Hqg2MFh7j6GVaSatsqzuN5klQGTblt
JJqsc9HfqfKHsOCWHti0WnUgmRguS2qAvGaIoP8NQ2UGArOWTii5GTTK9HOTmMA=
=Dp1C
-----END PGP SIGNATURE-----
_______________________________________________
vbox-dev mailing list
vbox-dev at virtualbox.org
https://www.virtualbox.org/mailman/listinfo/vbox-dev
More information about the vbox-dev
mailing list