Modify

Ticket #7949 (closed Bugs: fixed)

Opened 15 months ago

Last modified 14 months ago

Level 4 Warnings with VS2005

Reported by: Peter Brockamp <p.brockamp@…> Owned by: apolukhin
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

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

Change History

Changed 15 months ago by Peter Brockamp <p.brockamp@…>

Silence warning C4244 under VS2005

comment:1 Changed 15 months ago by apolukhin

  • Status changed from new to assigned
  • Milestone changed from To Be Determined to Boost 1.54.0

comment:2 follow-up: ↓ 3 Changed 15 months ago by apolukhin

  • Status changed from assigned to closed
  • Resolution set to wontfix

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.

comment:3 in reply to: ↑ 2 Changed 15 months ago by Peter Brockamp <p.brockamp@…>

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 follow-up: ↓ 5 Changed 15 months ago by apolukhin

  • Status changed from closed to reopened
  • Resolution wontfix deleted

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.

comment:5 in reply to: ↑ 4 Changed 15 months ago by Peter Brockamp <p.brockamp@…>

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 Changed 15 months ago by apolukhin

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

comment:7 Changed 14 months ago by apolukhin

  • Status changed from reopened to closed
  • Resolution set to fixed

(In [83114]) Merge from trunk:

  • Silence some buggy VS warnings (fixes #7949)
  • Fix -Wconversion warnings (fixes #2558)
  • Added support for int128 conversions (fixes #7909)
View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.