Opened 16 years ago
Closed 15 years ago
#377 closed defect (fixed)
MSVC 9.0 warning in xapian-core/common/str.h
Reported by: | Peter Kelm | Owned by: | Olly Betts |
---|---|---|---|
Priority: | normal | Milestone: | 1.1.1 |
Component: | Other | Version: | SVN trunk |
Severity: | normal | Keywords: | |
Cc: | Blocked By: | ||
Blocking: | Operating System: | Microsoft Windows |
Description
MSVC 9.0 complains about line 74 in "xapian-core/common/str.h":
inline std::string str(bool value) { return std::string(1, '0' | value); }
with the (bogus) message:
"warning C4806: '|' : unsafe operation: no value of type 'bool' promoted to type 'char' can equal the given constant"
Proposed resolution is to convert "value" to a "char" via static_cast:
inline std::string str(bool value) { return std::string(1, '0' | static_cast<char>(value)); }
Change History (8)
comment:1 by , 16 years ago
Milestone: | → 1.1.1 |
---|---|
Resolution: | → fixed |
Status: | new → closed |
comment:2 by , 15 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
The template functions in line 41 (tostring_unsigned) and 59 (tostring) of "common/str.cc" exhibit a similar issue. In this case, however the compiler generates a warning only as there is the "specialization" for bool as above.
Same resolution proposed as above, i.e. adding a static_cast on the "value" parameter.
comment:3 by , 15 years ago
Is this really the same warning as before? There's no logical operator involved in these assignments at all - not even a bitwise one!
It's also odd that the "constructor cast" on line 42 isn't enough to avoid this warning. What revision are you seeing this in?
comment:4 by , 15 years ago
Version is svn trunk 12765.
These are the output messages from the compiler (MSVC 9.0):
.\str.cc(59) : warning C4244: 'argument' : conversion from 'long' to 'char', possible loss of data .\str.cc(98) : see reference to function template instantiation 'std::string tostring<long>(T)' being compiled with [ T=long ] .\str.cc(41) : warning C4244: 'argument' : conversion from 'unsigned long' to 'char', possible loss of data .\str.cc(104) : see reference to function template instantiation 'std::string tostring_unsigned<unsigned long>(T)' being compiled with [ T=unsigned long ] .\str.cc(59) : warning C4244: 'argument' : conversion from '__int64' to 'char', possible loss of data .\str.cc(110) : see reference to function template instantiation 'std::string tostring<__int64>(T)' being compiled with [ T=__int64 ] .\str.cc(41) : warning C4244: 'argument' : conversion from 'unsigned __int64' to 'char', possible loss of data .\str.cc(116) : see reference to function template instantiation 'std::string tostring_unsigned<unsigned __int64>(T)' being compiled with [ T=unsigned __int64 ]
What "constructor cast" in line 42 are you referring to?
comment:5 by , 15 years ago
Ah, OK. It's probably better to open a new ticket for a new issue (but never mind this time). Reopening a ticket is really for cases like when a supposed fix didn't work.
r12768 added a "constructor cast" to line 41 (sorry, 42 was a typo). Oddly I didn't add one to line 59, but I'm curious if you still get a warning for line 41 after "svn up".
comment:6 by , 15 years ago
Milestone: | 1.1.1 → 1.1.2 |
---|
Still awaiting a response to my query about r12768, and this is a compiler warning not an error, so not worth holding up 1.1.1 further for, so bumping milestone.
comment:7 by , 15 years ago
Just tried trunk-12909. I can confirm that the warning does not appear there.
comment:8 by , 15 years ago
Milestone: | 1.1.2 → 1.1.1 |
---|---|
Resolution: | → fixed |
Status: | reopened → closed |
Thanks for confirming, so this was actually fixed in 1.1.1.
Thanks - committed to trunk in r12763.