Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#12333 closed Bugs (invalid)

boost/algorithm/hex.hpp: warning C4244: 'return': conversion from 'unsigned int' to 'unsigned char'

Reported by: pravic <ehysta@…> Owned by: Marshall Clow
Milestone: To Be Determined Component: algorithm
Version: Boost 1.61.0 Severity: Problem
Keywords: Cc:

Description

… which is not surprise:

    template <typename T>
    unsigned char hex_char_to_int ( T val ) {
        char c = static_cast<char> ( val );
        unsigned retval = 0; // <--
        // ...
        return retval; // <--
        }

Compiler output:

1>boost/algorithm/hex.hpp(74): warning C4244: 'return': conversion from 'unsigned int' to 'unsigned char', possible loss of data
1>  boost/algorithm/hex.hpp(129): note: see reference to function template instantiation 'unsigned char boost::algorithm::detail::hex_char_to_int<char>(T)' being compiled
1>          with
1>          [
1>              T=char
1>          ]
1>  boost/algorithm/hex.hpp(196): note: see reference to function template instantiation 'unsigned char *boost::algorithm::detail::decode_one<InputIterator,OutputIterator,bool(__cdecl *)(Iterator,Iterator)>(InputIterator &,InputIterator,OutputIterator,EndPred)' being compiled
1>          with
1>          [
1>              InputIterator=const char *,
1>              OutputIterator=unsigned char *,
1>              Iterator=const char *,
1>              EndPred=bool (__cdecl *)(const char *,const char *)
1>          ]

Change History (2)

comment:1 by Marshall Clow, 6 years ago

Resolution: invalid
Status: newclosed

We've been down this road before; the compiler is flat out wrong here.

This function returns a value in the range 0 .. 255; there is no loss of data.

Please report this bug against the MS compiler instead.

comment:2 by pravic <ehysta@…>, 6 years ago

What about compatibility? During many years Boost has been developed to be compatible with lot of compilers (even really old and outdated ones). And now you telling about bug in MSVC? Not very professional answer.

Note: See TracTickets for help on using tickets.