Opened 10 years ago

Closed 10 years ago

#7949 closed Bugs (fixed)

Level 4 Warnings with VS2005

Reported by: Peter Brockamp <p.brockamp@…> Owned by: Antony Polukhin
Milestone: Boost 1.54.0 Component: lexical_cast
Version: Boost 1.52.0 Severity: Optimization
Keywords: warnings VS2005 Cc:

Description

Try to compile the following with /W4 under VS2005:

#include "boost/lexical_cast.hpp"
#include "boost/date_time.hpp"

This will give you a bunch of warnings:

\boost\lexical_cast.hpp(732) : warning C4244: '+=' : conversion from 'int' to 'unsigned short', possible loss of data
\boost\lexical_cast.hpp(1627) : see reference to function template instantiation 'bool boost::detail::lcast_ret_unsigned<Traits,Type,CharT>(T &,const CharT *const ,const CharT *)' being compiled
\boost\lexical_cast.hpp(1751) : see reference to function template instantiation 'bool boost::detail::lexical_stream_limited_src<CharT,Traits,RequiresStringbuffer>::shr_unsigned<unsigned short>(Type &)' being compiled
\boost\lexical_cast.hpp(1751) : while compiling class template member function 'bool boost::detail::lexical_stream_limited_src<CharT,Traits,RequiresStringbuffer>::operator >>(unsigned short &)'
\boost\lexical_cast.hpp(2137) : see reference to class template instantiation 'boost::detail::lexical_stream_limited_src<CharT,Traits,RequiresStringbuffer>' being compiled
\boost\lexical_cast.hpp(2083) : while compiling class template member function 'unsigned short boost::detail::lexical_cast_do_cast<Target,Source>::lexical_cast_impl(const Source &)'
\boost\lexical_cast.hpp(2300) : see reference to class template instantiation 'boost::detail::lexical_cast_do_cast<Target,Source>' being compiled
\boost\date_time\date_parsing.hpp(138) : see reference to function template instantiation 'Target boost::lexical_cast<unsigned short,Type>(const Source &)' being compiled
\boost\date_time\gregorian\parsers.hpp(30) : see reference to function template instantiation 'date_type boost::date_time::parse_date<boost::gregorian::date>(const std::string &,int)' being compiled
\boost\lexical_cast.hpp(780) : warning C4244: '+=' : conversion from 'int' to 'unsigned short', possible loss of data

Attached a patch which silences these, as is done in other libraries.

Attachments (1)

lexical_cast.hpp.diff (773 bytes ) - added by Peter Brockamp <p.brockamp@…> 10 years ago.
Silence warning C4244 under VS2005

Download all attachments as: .zip

Change History (8)

by Peter Brockamp <p.brockamp@…>, 10 years ago

Attachment: lexical_cast.hpp.diff added

Silence warning C4244 under VS2005

comment:1 by Antony Polukhin, 10 years ago

Milestone: To Be DeterminedBoost 1.54.0
Status: newassigned

comment:2 by Antony Polukhin, 10 years ago

Resolution: wontfix
Status: assignedclosed

This is a bug of VS2005, it is fixed in VS2012 (may be also fixed in earlier versions of VS). Working around buggy warnings on non default warning level - I don't think that it is worth doing in lexical_cast.

in reply to:  2 comment:3 by Peter Brockamp <p.brockamp@…>, 10 years ago

Replying to apolukhin:

Working around buggy warnings on non default warning level - I don't think that it is worth doing in lexical_cast.

Well, maybe it is not, yes. Admittedly this particular warning is rather braindead under some circumstances (notably more or less unneccessary integer promotion done by the compiler behind the scenes. Short int seems to be treated as a second class citizen here). Anyway, consider:

  • The problem with warnings coming from headers of course is that they often will popup in every including cpp-file or at every place an certain template instance is used, cluttering the build output and hindering/demotivating programmers fixing their selfmade warnings.
  • There are companies that implement a zero-warning-policy - they have a reason to do so.
  • "Tightening the screws" on programmers by increasing the warning level is a useful thing, it often leads the way to uncover hidden, subtle bugs.
  • Boost itself states they intend to make warning free headers for every supported compiler - with additional warnings enabled (/W4, -Wall, etc.).
  • Many programmers unfortunately are bound to a certain compiler/compiler version - and to being molested by the warnings it emmits, no matter whether they're buggy or not.

So that's why I submitted this, and the patch is just a #pragma to shut down the warnings in lexical_cast, no line of production code is being changed. But never mind, that's just my personal opinion and everyone's summoned to have their personal opinion.

Best regards

Peter

comment:4 by Antony Polukhin, 10 years ago

Resolution: wontfix
Status: closedreopened

OK, you convinced me. But I'll disable this warning only for VS2005 (_MSC_VER == 1400). If you could reproduce it on VS2008, I'll also fix it there.

in reply to:  4 comment:5 by Peter Brockamp <p.brockamp@…>, 10 years ago

Replying to apolukhin:

OK, you convinced me. But I'll disable this warning only for VS2005 (_MSC_VER == 1400).

Yep, that's fine.

If you could reproduce it on VS2008, I'll also fix it there.

Sorry, but this is a no-op for me! I do not have access to VS2008 (AKA for the time being I'm bound to VS2005 & gcc 4.3.3 (WindRiver version, somehow patched for vxWorks) and may not simply install an express edition of VS2008 or whatever) :-/

Someone else has to check whether this poses a problem in VS2008, too. Of course I could install VS at home for testing purposes - but everybody wants to call it a day eventually, so do I. <irony> You don't want my wife to punish me, do you? </irony> ;->

Best regards

Peter

comment:6 by Antony Polukhin, 10 years ago

(In [82807]) Silence some buggy VS warnings (refs #7949)

comment:7 by Antony Polukhin, 10 years ago

Resolution: fixed
Status: reopenedclosed

(In [83114]) Merge from trunk:

  • Silence some buggy VS warnings (fixes #7949)
  • Fix -Wconversion warnings (fixes #2558)
  • Added support for int128 conversions (fixes #7909)
Note: See TracTickets for help on using tickets.