help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug? std::string promoted to bool???


From: U.Mutlu
Subject: Re: Bug? std::string promoted to bool???
Date: Thu, 14 May 2015 02:21:45 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:40.0) Gecko/20100101 Firefox/40.0 SeaMonkey/2.37a1

crimaniak@googlemail.com wrote on 05/13/2015 08:12 PM:
среда, 13 мая 2015 г., 5:47:40 UTC+3 пользователь U.Mutlu написал:
The 2nd par should be a bool not a std::string. IMO the compiler should
generate a warning (actually even an error) about it.
...
func(S, "X");   // <-- HERE

It is char *, not a std::string.

From docs:

Boolean conversions

Prvalues of integral, floating-point, unscoped enumeration, pointer, and
pointer-to-member types can be converted to prvalues of type bool.

The value zero (for integral, floating-point, and unscoped enumeration) and
the null pointer and the null pointer-to-member values become false. All
other values become true.

But this doesn't cover this special case (char*) here, does it?
Whatever the doc says, it is IMO an extremly dangerous construct.
As such, the compiler should at least give a warning.

--
cu
Uenal





reply via email to

[Prev in Thread] Current Thread [Next in Thread]