Opened 14 years ago

Closed 13 years ago

#2045 closed Bugs (worksforme)

lexical_cast<std::string> of short unsigned produces warnigns with g++ and -Wsign-promo

Reported by: aeriksson@… Owned by: nasonov
Milestone: Boost 1.36.0 Component: lexical_cast
Version: Boost 1.35.0 Severity: Problem
Keywords: Cc:

Description

#include <boost/lexical_cast.hpp>

void foo() {
  short unsigned int x;
  boost::lexical_cast<std::string>(x);
}

Compiled with g++ 4.2.0, boost 1.35.0, and the -Wsign-promo flag this produces the following warnings:

/opt/boost/include/boost-1_35/boost/lexical_cast.hpp: In member function ‘bool boost::detail::lexical_stream_limited_src<CharT, Base, Traits>::operator<<(short unsigned int) [with CharT = char, Base = boost::detail::lexical_streambuf_fake, Traits = std::char_traits<char>]’:
/opt/boost/include/boost-1_35/boost/lexical_cast.hpp:1146:   instantiated from ‘Target boost::detail::lexical_cast(typename boost::call_traits<Source>::param_type, CharT*, size_t) [with Target = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Source = short unsigned int, bool Unlimited = false, CharT = char]’
/opt/boost/include/boost-1_35/boost/lexical_cast.hpp:1170:   instantiated from ‘Target boost::lexical_cast(const Source&) [with Target = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Source = short unsigned int]’
lexicalWarning.cpp:5:   instantiated from here
/opt/boost/include/boost-1_35/boost/lexical_cast.hpp:910: warning: passing ‘short unsigned int’ chooses ‘int’ over ‘long int’
/opt/boost/include/boost-1_35/boost/lexical_cast.hpp:910: warning:   in call to ‘unsigned int boost::detail::lcast_to_unsigned(int)’

Change History (1)

comment:1 by nasonov, 13 years ago

Resolution: worksforme
Status: newclosed

Not reproducible neither with gcc 3.4.6 nor 4.1.3 on NetBSD 5.99.17 (-current) i386. Please submit a patch.

Note: See TracTickets for help on using tickets.