Should char_traits<char>::int_type be an int or unsigned long?

Craig Rodrigues
Sat Feb 10 15:37:00 GMT 2001


Platform: Redhat Linux 7.0
Compiler: gcc version 2.97 20010210 (experimental) (from CodeSourcery)


I recently could not compile a third party library with this compiler
version.  I isolated the problem to the following:

#include <iostream>
using namespace std;
class mybuf : public streambuf
                virtual int underflow();
return 0;

Compiling this yields: conflicting return type specified for `virtual int mybuf::underflow()'
/usr/local/include/g++-v3/bits/std_streambuf.h:475:   overriding `typename
   _Traits::int_type std::basic_streambuf<_CharT, _Traits>::underflow() [with
   _CharT = char, _Traits = std::char_traits<char>]'         

streambuf is defined as: typedef basic_streambuf<char>    streambuf; 
in std_iosfwd.h.

I then looked in the file g++-v3/std_streambuf.h:
   template<typename _CharT, typename _Traits>
   class basic_streambuf

      virtual int_type
      { return traits_type::eof(); }    

I then looked in the file g++-v3/bits/char_traits.h
  // 21.1.2 Basis for explicit _Traits specialization
  // NB: That for any given actual character type this definition is
  // probably wrong.
  template<class _CharT>
    struct char_traits
      typedef _CharT            char_type;
      // Unsigned as wint_t in unsigned.
      typedef unsigned long     int_type;
      typedef streampos         pos_type;
      typedef streamoff         off_type;
      typedef mbstate_t         state_type;

So in this case, streambuf::int_type is defined as an unsigned long.
I have looked at a few other IOStream implementations, such as STLport, and
streambuf::int_type maps to an int.

What is the correct solution to the problem?
Craig Rodrigues          

More information about the Libstdc++ mailing list