Opened 15 years ago

Closed 15 years ago

#1229 closed Bugs (fixed)

[GCC] compiler warning: comparison between signed and unsigned integer expressions

Reported by: Dean Michael Berris <mikhailberis@…> Owned by: Robert Ramey
Milestone: Boost 1.35.0 Component: serialization
Version: Boost Development Trunk Severity: Cosmetic
Keywords: serialization, compiler warnings Cc:

Description

I've attached the warning generated during compilation of the Serialization library.

gcc.compile.c++ /usr/local/lib/boost/bin.v2/libs/serialization/build/gcc-4.1.2/debug/link-static/optimization-speed/threading-multi/binary_iarchive.o
/usr/local/lib/boost/boost/archive/basic_binary_iprimitive.hpp: In member function void boost::archive::basic_binary_iprimitive<Archive, Elem, Tr>::load_binary(void*, size_t) [with Archive = boost::archive::naked_binary_iarchive, Elem = char, Tr = std::char_traits<char>]:
/usr/local/lib/boost/libs/serialization/src/binary_iarchive.cpp:24:   instantiated from here
/usr/local/lib/boost/boost/archive/basic_binary_iprimitive.hpp:163: warning: comparison between signed and unsigned integer expressions
/usr/local/lib/boost/boost/archive/basic_binary_iprimitive.hpp: In member function void boost::archive::basic_binary_iprimitive<Archive, Elem, Tr>::load_binary(void*, size_t) [with Archive = boost::archive::binary_iarchive, Elem = char, Tr = std::char_traits<char>]:
/usr/local/lib/boost/libs/serialization/src/binary_iarchive.cpp:38:   instantiated from here
/usr/local/lib/boost/boost/archive/basic_binary_iprimitive.hpp:163: warning: comparison between signed and unsigned integer expressions

GCC Compiler version 4.1.2 .

I suspect the problem has something to do with the GNU GCC's definition of 'streamsize' as:

  /// Integral type for I/O operation counts and buffer sizes.
  typedef ptrdiff_t streamsize; // Signed integral type

-- from bits/postypes.h

The warning is caused by the following code:

    std::streamsize s = count / sizeof(Elem);
    std::streamsize scount = m_sb.sgetn(
        static_cast<Elem *>(address),
        s
    );
    if(scount != static_cast<std::size_t>(s))
        boost::throw_exception(
            archive_exception(archive_exception::stream_error)
        );

Changing 'std::size_t' into 'std::streamsize' seems to resolve the problem.

Change History (1)

comment:1 by Robert Ramey, 15 years ago

Milestone: To Be DeterminedBoost 1.35.0
Resolution: fixed
Severity: ProblemCosmetic
Status: newclosed

fixed in next release

Note: See TracTickets for help on using tickets.