This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

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


Hi,

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

Problem:

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
{
        protected:
                virtual int underflow();
};
 
int
mybuf::underflow()
{
return 0;
}                                    

Compiling this yields:
a.cc:7: 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
      underflow()
      { 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?
Thanks.
-- 
Craig Rodrigues        
http://www.gis.net/~craigr    
rodrigc@mediaone.net          


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]