[Xapian-devel] str.h warning in MSVC 9.0

Olly Betts olly at survex.com
Tue May 5 14:37:01 BST 2009

On Tue, May 05, 2009 at 03:09:58PM +0200, Kelm, Peter  ST/HZA-TG wrote:
> MSVC complains about line 74 in "xapian-core/common/str.h":
> inline std::string str(bool value) { return std::string('0' | value, 1);
> }

Well, the parameters are swapped in the constructor here (I'll fix
that), but I don't see that explaining the warning.

> with the message:
> "warning C4806: '|' : unsafe operation: no value of type 'bool' promoted
> to type 'char' can equal the given constant"

This warning makes no sense to me.  Why should value have to be able to
be equal to '0' for this code to be "safe"?  

Unless anyone can explain why this code is a problem, I propose we just
add 4806 to the list of MSVC warnings to be ignored.

> I believe the intention is to do the following - or am I missing
> something?
> inline std::string str(bool value) { return std::string(value ? '1' :
> '0'); }

That won't compile as there is no such std::string constructor.


More information about the Xapian-devel mailing list