Article View: gnu.g++.bug
Article #12762.3.2 base class initializer bug
From: Doug Moore
Date: Wed, 16 Dec 1992 02:18
Date: Wed, 16 Dec 1992 02:18
2381 lines
41087 bytes
41087 bytes
In deriving a class from ostream in libg++-2.3, the argument to the
base class ios (a parent of ostream) is incorrectly passed. That is,
the ostream constructor is called with a non-NULL pointer as its first
argument; it, in turn, sends its arguments to an ios constructor which
sees its first argument as NULL.
The version 2.3.2 of g++ has been patched by a patch from Michael N.
Lipp, initially submitted for version 2.2.2, that avoids a compiler
infinite loop that occurs (both in 2.2.2 and unpatched 2.3.2) when
compiling the source to his rpc++ library. The machine and os are a
sparc and sunos4.1.2, respectively.
Here is a sample session with gdb that evokes the bug:
======================================================
GDB is free software and you are welcome to distribute copies of it
under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for details.
GDB 4.7, Copyright 1992 Free Software Foundation, Inc...
(gdb) Breakpoint 1 at 0x58d0: file xdr.cc, line 13.
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /blossom/src/rpc++/xdrstream/a.out
4
Hello
3.14159
Breakpoint 1, main () at xdr.cc:13
(gdb) s
oxdrstream::oxdrstream (this=0xf7fff9d0, __in$chrg=1, sb=0xf7fffa08) at xdrstream.h:23
(gdb) p sb
$1 = (struct streambuf *) 0xf7fffa08
(gdb) s
ios::ios (this=0xf7fff9ec, sb=0x0, tie=0x0)
at /blossom/lib/gcc-lib/sun4/2.3.2/g++-include/streambuf.h:477
(gdb) p sb
$2 = (struct streambuf *) 0x0
(gdb)
=========================================================
In the source to come, defining the preprocessor variable BUG invokes
the bug; failing to do so circumvents the bug. The verbose compiler
output generated on this source is:
==========================================================
dougm@titan:xdrstream $ g++ -g xdr.bug.cc -v -Wall -DBUG
Reading specs from /blossom/lib/gcc-lib/sun4/2.3.2/specs
gcc version 2.3.2
/blossom/lib/gcc-lib/sun4/2.3.2/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix -g -Wall -DBUG xdr.bug.cc /usr/tmp/cca26863.i
GNU CPP version 2.3.2 (sparc)
/blossom/lib/gcc-lib/sun4/2.3.2/cc1plus /usr/tmp/cca26863.i -quiet -dumpbase xdr.bug.cc -g -Wall -version -o /usr/tmp/cca26863.s
GNU C++ version 2.3.2 (sparc) compiled by GNU C version 2.3.2.
as -o /usr/tmp/cca268631.o /usr/tmp/cca26863.s
/blossom/lib/gcc-lib/sun4/2.3.2/ld -e start -dc -dp /lib/crt0.o -L/blossom/lib/gcc-lib/sun4/2.3.2 -L/blossom/lib /usr/tmp/cca268631.o -lg++ -lgcc -lc -lg -lgcc
dougm@titan:xdrstream $
============================================================
Finally, the source, as run through g++ -E, follows.
Doug Moore
(dougm@cs.rice.edu)
# 1 "xdr.cc"
# 1 "xdrstream.h" 1
# 1 "/blossom/lib/gcc-lib/sun4/2.3.2/g++-include/iostream.h" 1 3
# 1 "/blossom/lib/gcc-lib/sun4/2.3.2/g++-include/streambuf.h" 1 3
# 1 "/blossom/lib/gcc-lib/sun4/2.3.2/g++-include/_G_config.h" 1 3
typedef long _G_clock_t;
typedef short _G_dev_t;
typedef long _G_fpos_t;
typedef unsigned short _G_gid_t;
typedef unsigned long _G_ino_t;
typedef unsigned short _G_mode_t;
typedef short _G_nlink_t;
typedef long _G_off_t;
typedef int _G_pid_t;
typedef int _G_ptrdiff_t;
typedef int _G_sigset_t;
typedef int _G_size_t;
typedef long _G_time_t;
typedef unsigned short _G_uid_t;
typedef unsigned short _G_wchar_t;
typedef int _G_ssize_t;
typedef char * _G_va_list;
# 25 "/blossom/lib/gcc-lib/sun4/2.3.2/g++-include/streambuf.h" 2 3
class ostream; class streambuf; class backupbuf;
extern "C" int __underflow(streambuf*);
extern "C" int __overflow(streambuf*, int);
typedef _G_off_t streamoff;
typedef _G_off_t streampos;
typedef unsigned long __fmtflags;
typedef unsigned char __iostate;
struct _ios_fields {
streambuf *_strbuf;
ostream* _tie;
int _width;
__fmtflags _flags;
_G_wchar_t _fill;
__iostate _state;
__iostate _exceptions;
int _precision;
};
# 95 "/blossom/lib/gcc-lib/sun4/2.3.2/g++-include/streambuf.h" 3
class ios : public _ios_fields {
public:
typedef __fmtflags fmtflags;
typedef int iostate;
typedef int openmode;
enum io_state {
goodbit = 0 ,
eofbit = 1 ,
failbit = 2 ,
badbit = 4 };
enum open_mode {
in = 1 ,
out = 2 ,
ate = 4 ,
app = 8 ,
trunc = 16 ,
nocreate = 32 ,
noreplace = 64 ,
bin = 128 };
enum seek_dir { beg, cur, end};
enum { skipws=01, left=02, right=04, internal=010,
dec=020, oct=040, hex=0100,
showbase=0200, showpoint=0400, uppercase=01000, showpos=02000,
scientific=04000, fixed=010000, unitbuf=020000, stdio=040000,
dont_close=0x80000000
};
enum {
basefield=dec+oct+hex,
floatfield = scientific+fixed,
adjustfield = left+right+internal
};
# 138 "/blossom/lib/gcc-lib/sun4/2.3.2/g++-include/streambuf.h" 3
ostream* tie() const { return _tie; }
ostream* tie(ostream* val) { ostream* save=_tie; _tie=val; return save; }
_G_wchar_t fill() const { return (_G_wchar_t)_fill; }
_G_wchar_t fill(_G_wchar_t newf)
{_G_wchar_t oldf = (_G_wchar_t)_fill; _fill = (char)newf; return oldf;}
fmtflags flags() const { return _flags; }
fmtflags flags(fmtflags new_val) {
fmtflags old_val = _flags; _flags = new_val; return old_val; }
int precision() const { return _precision; }
int precision(int newp) {
unsigned short oldp = _precision; _precision = (unsigned short)newp;
return oldp; }
fmtflags setf(fmtflags val) {
fmtflags oldbits = _flags;
_flags |= val; return oldbits; }
fmtflags setf(fmtflags val, fmtflags mask) {
fmtflags oldbits = _flags;
_flags = (_flags & ~mask) | (val & mask); return oldbits; }
fmtflags unsetf(fmtflags mask) {
fmtflags oldbits = _flags & mask;
_flags &= ~mask; return oldbits; }
int width() const { return _width; }
int width(int val) { int save = _width; _width = val; return save; }
void _throw_failure() { }
streambuf* rdbuf() const { return _strbuf; }
void clear(iostate state = 0) {
_state = _strbuf ? state : state|badbit;
if (_state & _exceptions) _throw_failure(); }
void set(iostate flag) { _state |= flag;
if (_state & _exceptions) _throw_failure(); }
int good() const { return _state == 0; }
int eof() const { return _state & ios::eofbit; }
int fail() const { return _state & (ios::badbit|ios::failbit); }
int bad() const { return _state & ios::badbit; }
iostate rdstate() const { return _state; }
operator void*() const { return fail() ? (void*)0 : (void*)(-1); }
int operator!() const { return fail(); }
iostate exception(iostate enable) {
iostate old = _exceptions; _exceptions = enable;
if (_state & _exceptions) _throw_failure();
return old; }
static int sync_with_stdio(int on);
static void sync_with_stdio() { sync_with_stdio(1); }
protected:
ios(streambuf* sb = 0, ostream* tie = 0);
virtual ~ios();
void init(streambuf* sb) { _state=0; _strbuf=sb; }
};
typedef ios::seek_dir _seek_dir;
class streammarker {
friend class streambuf;
friend int __underflow(streambuf*);
struct streammarker *_next;
streambuf *_sbuf;
streampos _spos;
void set_streampos(streampos sp) { _spos = sp; }
void set_offset(int offset) { _pos = offset; _spos = (streampos)(-2); }
int _pos;
public:
streammarker(streambuf *sb);
~streammarker();
int saving() { return _spos == -2; }
int delta(streammarker&);
int delta();
};
struct __streambuf {
int _flags;
char* _gptr;
char* _egptr;
char* _eback;
char* _pbase;
char* _pptr;
char* _epptr;
char* _base;
char* _ebuf;
struct streambuf *_chain;
friend class streammarker;
char *_other_gbase;
char *_aux_limit;
char *_other_egptr;
streammarker *_markers;
unsigned short _cur_column;
char _unused;
char _shortbuf[1];
};
extern unsigned __adjust_column(unsigned start, const char *line, int count);
struct streambuf : private __streambuf {
friend class ios;
friend class istream;
friend class ostream;
friend class streammarker;
friend int __underflow(streambuf*);
protected:
static streambuf* _list_all;
streambuf*& xchain() { return _chain; }
void _un_link();
void _link_in();
char* gptr() const { return _gptr; }
char* pptr() const { return _pptr; }
char* egptr() const { return _egptr; }
char* epptr() const { return _epptr; }
char* pbase() const { return _pbase; }
char* eback() const { return _eback; }
char* base() const { return _base; }
char* ebuf() const { return _ebuf; }
int blen() const { return _ebuf - _base; }
void xput_char(char c) { *_pptr++ = c; }
int xflags() { return _flags; }
int xflags(int f) { int fl = _flags; _flags = f; return fl; }
void xsetflags(int f) { _flags |= f; }
void xsetflags(int f, int mask) { _flags = (_flags & ~mask) | (f & mask); }
void gbump(int n) { _gptr += n; }
void pbump(int n) { _pptr += n; }
void setb(char* b, char* eb, int a=0);
void setp(char* p, char* ep) { _pbase=_pptr=p; _epptr=ep; }
void setg(char* eb, char* g, char *eg) { _eback=eb; _gptr=g; _egptr=eg; }
char *shortbuf() { return _shortbuf; }
int in_backup() { return _flags & 0x100 ; }
char *Gbase() { return in_backup() ? _other_gbase : _eback; }
char *eGptr() { return in_backup() ? _other_egptr : _egptr; }
char *Bbase() { return in_backup() ? _eback : _other_gbase; }
char *Bptr() { return _aux_limit; }
char *eBptr() { return in_backup() ? _egptr : _other_egptr; }
char *Nbase() { return _other_gbase; }
char *eNptr() { return _other_egptr; }
int have_backup() { return _other_gbase != ((void*)0) ; }
int have_markers() { return _markers != ((void*)0) ; }
int _least_marker();
void switch_to_main_get_area();
void switch_to_backup_area();
void free_backup_area();
void unsave_markers();
int put_mode() { return _flags & 0x800 ; }
int switch_to_get_mode();
streambuf(int flags=0);
public:
static int flush_all();
static void flush_all_linebuffered();
virtual int underflow() = 0;
virtual int overflow(int c = (-1) ) = 0;
virtual int doallocate();
virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
virtual streampos seekpos(streampos pos, int mode = ios::in|ios::out);
int seekmark(streammarker& mark, int delta = 0);
int sputbackc(char c);
int sungetc();
virtual ~streambuf();
int unbuffered() { return _flags & 2 ? 1 : 0; }
int linebuffered() { return _flags & 0x200 ? 1 : 0; }
void unbuffered(int i)
{ if (i) _flags |= 2 ; else _flags &= ~2 ; }
void linebuffered(int i)
{ if (i) _flags |= 0x200 ; else _flags &= ~0x200 ; }
int allocate() {
if (base() || unbuffered()) return 0;
else return doallocate(); }
void allocbuf() { if (base() == ((void*)0) ) doallocbuf(); }
void doallocbuf();
virtual int sync();
virtual int pbackfail(int c);
virtual streambuf* setbuf(char* p, int len);
int in_avail() { return _egptr - _gptr; }
int out_waiting() { return _pptr - _pbase; }
virtual int xsputn(const char* s, int n);
int sputn(const char* s, int n) { return xsputn(s, n); }
int padn(char pad, int n);
virtual int xsgetn(char* s, int n);
int sgetn(char* s, int n) { return xsgetn(s, n); }
int ignore(int);
virtual int get_column();
virtual int set_column(int);
long sgetline(char* buf, _G_size_t n, char delim, int putback_delim);
int sbumpc() {
if (_gptr >= _egptr && __underflow(this) == (-1) ) return (-1) ;
else return *(unsigned char*)_gptr++; }
int sgetc() {
if (_gptr >= _egptr && __underflow(this) == (-1) ) return (-1) ;
else return *(unsigned char*)_gptr; }
int snextc() {
if (_gptr >= _egptr && __underflow(this) == (-1) ) return (-1) ;
return _gptr++, sgetc(); }
int sputc(int c) {
if (_pptr >= _epptr) return __overflow(this, (unsigned char)c);
else return *_pptr++ = c, (unsigned char)c; }
void stossc() { if (_gptr < _egptr) _gptr++; }
int vscan(char const *fmt0, _G_va_list ap, ios* stream = ((void*)0) );
int scan(char const *fmt0 ...);
int vform(char const *fmt0, _G_va_list ap);
int form(char const *fmt0 ...);
};
class backupbuf : public streambuf {
friend class streammarker;
protected:
backupbuf(int flags=0) : streambuf(flags|0x4000 ) { }
public:
virtual int pbackfail(int c);
virtual int underflow();
virtual int overflow(int c = (-1) );
};
struct __file_fields {
short _fileno;
int _blksize;
_G_fpos_t _offset;
};
class filebuf : public backupbuf {
protected:
struct __file_fields _fb;
void init();
public:
static const int openprot;
filebuf();
filebuf(int fd);
filebuf(int fd, char* p, int len);
~filebuf();
filebuf* attach(int fd);
filebuf* open(const char *filename, const char *mode);
filebuf* open(const char *filename, ios::openmode mode, int prot = 0664);
virtual int underflow();
virtual int overflow(int c = (-1) );
int is_open() const { return _fb._fileno >= 0; }
int fd() const { return is_open() ? _fb._fileno : (-1) ; }
filebuf* close();
virtual int doallocate();
virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
virtual streambuf* setbuf(char* p, int len);
int xsputn(const char* s, int n);
int xsgetn(char* s, int n);
virtual int sync();
protected:
int is_reading() { return eback() != egptr(); }
char* cur_ptr() { return is_reading() ? gptr() : pptr(); }
char* file_ptr() { return eGptr(); }
int do_write(const char *data, int to_do);
int do_flush() { return do_write(_pbase, _pptr-_pbase); }
virtual _G_ssize_t sys_read(char* buf, _G_size_t size);
virtual _G_fpos_t sys_seek(_G_fpos_t , _seek_dir);
virtual _G_ssize_t sys_write(const void*, long);
virtual int sys_stat(void*);
virtual int sys_close();
};
inline ios::ios(streambuf* sb , ostream* tie ) {
_state = sb ? ios::goodbit : ios::badbit; _exceptions=0;
_strbuf=sb; _tie = tie; _width=0; _fill=' ';
_flags=ios::skipws|ios::dec; _precision=6; }
inline ios::~ios() {
if (!(_flags & (unsigned int)ios::dont_close)) delete _strbuf; }
# 24 "/blossom/lib/gcc-lib/sun4/2.3.2/g++-include/iostream.h" 2 3
class istream; class ostream;
typedef ios& (*__manip)(ios&);
typedef istream& (*__imanip)(istream&);
typedef ostream& (*__omanip)(ostream&);
extern istream& ws(istream& ins);
extern ostream& flush(ostream& outs);
extern ostream& endl(ostream& outs);
extern ostream& ends(ostream& outs);
class ostream : virtual public ios
{
void do_osfx();
public:
ostream() { }
ostream(streambuf* sb, ostream* tied=((void*)0) );
int opfx() {
if (!good()) return 0; else { if (_tie) _tie->flush(); return 1;} }
void osfx() { if (flags() & (ios::unitbuf|ios::stdio))
do_osfx(); }
streambuf* ostreambuf() const { return _strbuf; }
ostream& flush();
ostream& put(char c) { _strbuf->sputc(c); return *this; }
ostream& put(unsigned char c) { return put((char)c); }
ostream& write(const char *s, int n);
ostream& write(const unsigned char *s, int n) { return write((const char*)s, n);}
ostream& put(signed char c) { return put((char)c); }
ostream& write(const signed char *s, int n) { return write((const char*)s, n);}
ostream& write(const void *s, int n) { return write((const char*)s, n);}
ostream& seekp(streampos);
ostream& seekp(streamoff, _seek_dir);
streampos tellp();
ostream& form(const char *format ...);
ostream& vform(const char *format, _G_va_list args);
ostream& operator<<(char c);
ostream& operator<<(unsigned char c) { return (*this) << (char)c; }
ostream& operator<<(signed char c) { return (*this) << (char)c; }
ostream& operator<<(const char *s);
ostream& operator<<(const unsigned char *s)
{ return (*this) << (const char*)s; }
ostream& operator<<(const signed char *s)
{ return (*this) << (const char*)s; }
ostream& operator<<(void *p);
ostream& operator<<(int n);
ostream& operator<<(unsigned int n);
ostream& operator<<(long n);
ostream& operator<<(unsigned long n);
ostream& operator<<(long long n);
ostream& operator<<(unsigned long long n);
ostream& operator<<(short n) {return operator<<((int)n);}
ostream& operator<<(unsigned short n) {return operator<<((unsigned int)n);}
ostream& operator<<(double n);
ostream& operator<<(float n) { return operator<<((double)n); }
ostream& operator<<(__omanip func) { return (*func)(*this); }
ostream& operator<<(__manip func) {(*func)(*this); return *this;}
ostream& operator<<(streambuf*);
};
class istream : virtual public ios
{
_G_ssize_t _gcount;
int _skip_ws();
public:
istream() { _gcount = 0; }
istream(streambuf* sb, ostream*tied=((void*)0) );
streambuf* istreambuf() const { return _strbuf; }
istream& get(char* ptr, int len, char delim = '\n');
istream& get(unsigned char* ptr, int len, char delim = '\n')
{ return get((char*)ptr, len, delim); }
istream& get(char& c);
istream& get(unsigned char& c) { return get((char&)c); }
istream& getline(char* ptr, int len, char delim = '\n');
istream& getline(unsigned char* ptr, int len, char delim = '\n')
{ return getline((char*)ptr, len, delim); }
istream& get(signed char& c) { return get((char&)c); }
istream& get(signed char* ptr, int len, char delim = '\n')
{ return get((char*)ptr, len, delim); }
istream& getline(signed char* ptr, int len, char delim = '\n')
{ return getline((char*)ptr, len, delim); }
istream& read(char *ptr, int n);
istream& read(unsigned char *ptr, int n) { return read((char*)ptr, n); }
istream& read(signed char *ptr, int n) { return read((char*)ptr, n); }
istream& read(void *ptr, int n) { return read((char*)ptr, n); }
istream& get(streambuf& sb, char delim = '\n');
istream& gets(char **s, char delim = '\n');
int ipfx(int need) {
if (!good()) { set(ios::failbit); return 0; }
if (_tie && (need == 0 || rdbuf()->in_avail() < need)) _tie->flush();
if (!need && (flags() & ios::skipws)) return _skip_ws();
return 1;
}
int ipfx0() {
if (!good()) { set(ios::failbit); return 0; }
if (_tie) _tie->flush();
if (flags() & ios::skipws) return _skip_ws();
return 1;
}
int ipfx1() {
if (!good()) { set(ios::failbit); return 0; }
if (_tie && rdbuf()->in_avail() == 0) _tie->flush();
return 1;
}
int get() { if (!ipfx1()) return (-1) ;
int ch = _strbuf->sbumpc();
if (ch == (-1) ) set(ios::eofbit);
return ch; }
int peek() { if (!ipfx1()) return (-1) ;
int ch = _strbuf->sgetc();
if (ch == (-1) ) set(ios::eofbit);
return ch; }
_G_ssize_t gcount() { return _gcount; }
istream& ignore(int n=1, int delim = (-1) );
istream& seekg(streampos);
istream& seekg(streamoff, _seek_dir);
streampos tellg();
istream& putback(char ch) {
if (good() && _strbuf->sputbackc(ch) == (-1) ) clear(ios::badbit);
return *this;}
istream& unget() {
if (good() && _strbuf->sungetc() == (-1) ) clear(ios::badbit);
return *this;}
istream& scan(const char *format ...);
istream& vscan(const char *format, _G_va_list args);
istream& operator>>(char*);
istream& operator>>(unsigned char* p) { return operator>>((char*)p); }
istream& operator>>(signed char*p) { return operator>>((char*)p); }
istream& operator>>(char& c);
istream& operator>>(unsigned char& c) {return operator>>((char&)c);}
istream& operator>>(signed char& c) {return operator>>((char&)c);}
istream& operator>>(int&);
istream& operator>>(long&);
istream& operator>>(long long&);
istream& operator>>(short&);
istream& operator>>(unsigned int&);
istream& operator>>(unsigned long&);
istream& operator>>(unsigned long long&);
istream& operator>>(unsigned short&);
istream& operator>>(float&);
istream& operator>>(double&);
istream& operator>>( __manip func) {(*func)(*this); return *this;}
istream& operator>>(__imanip func) { return (*func)(*this); }
istream& operator>>(streambuf*);
};
class iostream : public istream, public ostream
{
_G_ssize_t _gcount;
public:
iostream() { _gcount = 0; }
iostream(streambuf* sb, ostream*tied=((void*)0) );
};
extern istream cin;
extern ostream cout, cerr, clog;
struct Iostream_init { } ;
inline ios& dec(ios& i)
{ i.setf(ios::dec, ios::dec|ios::hex|ios::oct); return i; }
inline ios& hex(ios& i)
{ i.setf(ios::hex, ios::dec|ios::hex|ios::oct); return i; }
inline ios& oct(ios& i)
{ i.setf(ios::oct, ios::dec|ios::hex|ios::oct); return i; }
# 7 "xdrstream.h" 2
# 1 "/blossom/lib/gcc-lib/sun4/2.3.2/include/rpc/xdr.h" 1 3
# 1 "/blossom/lib/gcc-lib/sun4/2.3.2/include/rpc/c_types.h" 1 3
typedef void (*_PFV_)();
typedef int (*_PFI_)();
# 77 "/blossom/lib/gcc-lib/sun4/2.3.2/include/rpc/c_types.h" 3
# 41 "/blossom/lib/gcc-lib/sun4/2.3.2/include/rpc/xdr.h" 2 3
# 1 "/usr/include/rpc/types.h" 1 3
# 1 "/blossom/lib/gcc-lib/sun4/2.3.2/include/malloc.h" 1 3
struct mallinfo {
int arena;
int ordblks;
int smblks;
int hblks;
int hblkhd;
int usmblks;
int fsmblks;
int uordblks;
int fordblks;
int keepcost;
int mxfast;
int nlblks;
int grain;
int uordbytes;
int allocated;
int treeoverhead;
};
typedef void * malloc_t;
extern malloc_t calloc( );
extern void free( );
extern malloc_t malloc( );
extern malloc_t realloc( );
extern int mallopt();
extern struct mallinfo mallinfo();
# 27 "/usr/include/rpc/types.h" 2 3
# 1 "/blossom/lib/gcc-lib/sun4/2.3.2/g++-include/sys/types.h" 1 3
extern "C"
{
# 1 "/blossom/lib/gcc-lib/sun4/2.3.2/g++-include/stddef.h" 1 3
extern "C" {
# 1 "/blossom/lib/gcc-lib/sun4/2.3.2/include/stddef.h" 1 3
# 43 "/blossom/lib/gcc-lib/sun4/2.3.2/include/stddef.h" 3
typedef int ptrdiff_t;
typedef int size_t;
typedef __wchar_t wchar_t;
# 179 "/blossom/lib/gcc-lib/sun4/2.3.2/include/stddef.h" 3
# 7 "/blossom/lib/gcc-lib/sun4/2.3.2/g++-include/stddef.h" 2 3
}
# 10 "/blossom/lib/gcc-lib/sun4/2.3.2/g++-include/sys/types.h" 2 3
# 1 "/blossom/lib/gcc-lib/sun4/2.3.2/include/sys/types.h" 1 3
# 1 "/blossom/lib/gcc-lib/sun4/2.3.2/include/sys/stdtypes.h" 1 3
typedef int sigset_t;
typedef unsigned int speed_t;
typedef unsigned long tcflag_t;
typedef unsigned char cc_t;
typedef int pid_t;
typedef unsigned short mode_t;
typedef short nlink_t;
typedef long clock_t;
typedef long time_t;
# 16 "/blossom/lib/gcc-lib/sun4/2.3.2/include/sys/types.h" 2 3
# 1 "/usr/include/sys/sysmacros.h" 1 3
# 19 "/blossom/lib/gcc-lib/sun4/2.3.2/include/sys/types.h" 2 3
typedef unsigned char u_char;
typedef unsigned short u_short;
typedef unsigned int u_int;
typedef unsigned long u_long;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef struct _physadr_t { int r[1]; } *physadr_t;
typedef struct label_t {
int val[2];
} label_t;
typedef struct _quad_t { long val[2]; } quad_t;
typedef long daddr_t;
typedef char * caddr_t;
typedef unsigned long ino_t;
typedef short dev_t;
typedef long off_t;
typedef unsigned short uid_t;
typedef unsigned short gid_t;
typedef long key_t;
typedef char * addr_t;
typedef long fd_mask;
typedef struct fd_set {
fd_mask fds_bits[(((256 )+(( (sizeof (fd_mask) * 8 ) )-1))/( (sizeof (fd_mask) * 8 ) )) ];
} fd_set;
# 113 "/blossom/lib/gcc-lib/sun4/2.3.2/include/sys/types.h" 3
# 15 "/blossom/lib/gcc-lib/sun4/2.3.2/g++-include/sys/types.h" 2 3
}
# 36 "/usr/include/rpc/types.h" 2 3
# 1 "/blossom/lib/gcc-lib/sun4/2.3.2/g++-include/sys/time.h" 1 3
extern "C"
{
# 1 "/usr/include/sys/time.h" 1 3
struct timeval {
long tv_sec;
long tv_usec;
};
struct timezone {
int tz_minuteswest;
int tz_dsttime;
};
struct itimerval {
struct timeval it_interval;
struct timeval it_value;
};
# 1 "/blossom/lib/gcc-lib/sun4/2.3.2/g++-include/time.h" 1 3
extern "C" {
# 22 "/blossom/lib/gcc-lib/sun4/2.3.2/g++-include/time.h" 3
# 44 "/blossom/lib/gcc-lib/sun4/2.3.2/g++-include/time.h" 3
# 1 "/usr/include/time.h" 1 3
struct tm {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
char *tm_zone;
long tm_gmtoff;
};
extern struct tm *__hide_gmtime (), *__hide_localtime ();
extern char *__hide_asctime (), *__hide_ctime ();
extern void __hide_tzset (), __hide_tzsetwall ();
extern int dysize();
extern time_t timelocal(), timegm();
# 49 "/blossom/lib/gcc-lib/sun4/2.3.2/g++-include/time.h" 2 3
extern char* asctime (...) ;
extern char* ctime (...) ;
double difftime (...) ;
extern struct tm* gmtime (...) ;
extern struct tm* localtime (...) ;
extern _G_time_t mktime(struct tm*);
extern _G_size_t strftime (...) ;
extern void tzset();
extern void tzsetwall();
extern int getitimer(int, struct itimerval*);
extern int setitimer (...) ;
extern int gettimeofday(struct timeval*, struct timezone*);
extern int settimeofday (...) ;
extern int stime (...) ;
extern int dysize(int);
long clock(void);
_G_time_t time(_G_time_t*);
unsigned ualarm(unsigned, unsigned);
unsigned usleep(unsigned);
void profil (...) ;
}
# 67 "/usr/include/sys/time.h" 2 3
# 25 "/blossom/lib/gcc-lib/sun4/2.3.2/g++-include/sys/time.h" 2 3
}
# 37 "/usr/include/rpc/types.h" 2 3
# 42 "/blossom/lib/gcc-lib/sun4/2.3.2/include/rpc/xdr.h" 2 3
# 1 "/blossom/lib/gcc-lib/sun4/2.3.2/g++-include/stdio.h" 1 3
extern "C" {
# 1 "/blossom/lib/gcc-lib/sun4/2.3.2/include/stdio.h" 1 3
# 1 "/blossom/lib/gcc-lib/sun4/2.3.2/g++-include/stdarg.h" 1 3
extern "C" {
# 1 "/blossom/lib/gcc-lib/sun4/2.3.2/include/stdarg.h" 1 3
# 1 "/blossom/lib/gcc-lib/sun4/2.3.2/include/va-sparc.h" 1 3
typedef char * __gnuc_va_list;
# 81 "/blossom/lib/gcc-lib/sun4/2.3.2/include/va-sparc.h" 3
# 32 "/blossom/lib/gcc-lib/sun4/2.3.2/include/stdarg.h" 2 3
# 89 "/blossom/lib/gcc-lib/sun4/2.3.2/include/stdarg.h" 3
# 137 "/blossom/lib/gcc-lib/sun4/2.3.2/include/stdarg.h" 3
# 2 "/blossom/lib/gcc-lib/sun4/2.3.2/g++-include/stdarg.h" 2 3
}
# 2 "/blossom/lib/gcc-lib/sun4/2.3.2/include/stdio.h" 2 3
extern struct _iobuf {
int _cnt;
unsigned char *_ptr;
unsigned char *_base;
int _bufsiz;
short _flag;
char _file;
} _iob[];
extern struct _iobuf *__hide_fopen ();
extern struct _iobuf *__hide_fdopen ();
extern struct _iobuf *__hide_freopen ();
extern struct _iobuf *__hide_popen ();
extern struct _iobuf *tmpfile();
extern long __hide_ftell ();
extern char *fgets();
extern char *gets();
extern char *__hide_sprintf ();
extern char *ctermid();
extern char *cuserid();
extern char *__hide_tempnam ();
extern char *tmpnam();
# 69 "/blossom/lib/gcc-lib/sun4/2.3.2/g++-include/stdio.h" 2 3
}
extern "C" {
int fclose(struct _iobuf *);
struct _iobuf * fdopen(int, const char*);
int fflush(struct _iobuf *);
int fgetc(struct _iobuf *);
char* fgets(char*, int, struct _iobuf *);
struct _iobuf * fopen(const char*, const char*);
int fprintf(struct _iobuf *, const char* ...);
int fputc(int, struct _iobuf *);
int fputs(const char*, struct _iobuf *);
_G_size_t fread(void*, _G_size_t , _G_size_t , struct _iobuf *);
struct _iobuf * freopen(const char*, const char*, struct _iobuf *);
int fscanf(struct _iobuf *, const char* ...);
int fseek(struct _iobuf *, long, int);
long ftell(struct _iobuf *);
_G_size_t fwrite(const void*, _G_size_t , _G_size_t , struct _iobuf *);
char* gets(char*);
int getw(struct _iobuf *);
int pclose(struct _iobuf *);
void perror(const char*);
struct _iobuf * popen(const char*, const char*);
int printf(const char* ...);
int puts(const char*);
int putw(int, struct _iobuf *);
int rewind(struct _iobuf *);
int scanf(const char* ...);
void setbuf(struct _iobuf *, char*);
void setbuffer(struct _iobuf *, char*, int);
int setlinebuf(struct _iobuf *);
int setvbuf(struct _iobuf *, char*, int, _G_size_t );
int sscanf(char*, const char* ...);
struct _iobuf * tmpfile();
int ungetc(int, struct _iobuf *);
int vfprintf (...) ;
int vprintf (...) ;
char* sprintf (...) ;
char* vsprintf (...) ;
extern int _filbuf (...) ;
extern int _flsbuf (...) ;
}
# 43 "/blossom/lib/gcc-lib/sun4/2.3.2/include/rpc/xdr.h" 2 3
enum xdr_op {
XDR_ENCODE=0,
XDR_DECODE=1,
XDR_FREE=2
};
typedef struct XDR{
enum xdr_op x_op;
struct xdr_ops {
int (*x_getlong) (struct XDR*, long*) ;
int (*x_putlong) (struct XDR*, long*) ;
int (*x_getbytes) (struct XDR*, void*, u_int) ;
int (*x_putbytes) (struct XDR*, void*, u_int) ;
u_int (*x_getpostn) (struct XDR*) ;
int (*x_setpostn) (struct XDR*, u_int) ;
long * (*x_inline) (struct XDR*, u_int) ;
void (*x_destroy) (struct XDR*) ;
} *x_ops;
caddr_t x_public;
caddr_t x_private;
caddr_t x_base;
int x_handy;
} XDR;
typedef int (*xdrproc_t) (XDR*, void*) ;
struct xdr_discrim {
int value;
xdrproc_t proc;
};
extern "C" { int xdr_void (); } ;
extern "C" { int xdr_int (XDR*, int*); } ;
extern "C" { int xdr_u_int (XDR*, u_int*); } ;
extern "C" { int xdr_long (XDR*, long*); } ;
extern "C" { int xdr_u_long (XDR*, u_long*); } ;
extern "C" { int xdr_short (XDR*, short*); } ;
extern "C" { int xdr_u_short (XDR*, u_short*); } ;
extern "C" { int xdr_bool (XDR*, int *); } ;
extern "C" { int xdr_enum (XDR*, int *); } ;
extern "C" { int xdr_array (XDR*, void**, u_int*, u_int, u_int, xdrproc_t); } ;
extern "C" { int xdr_bytes (XDR*, void**, u_int*, u_int); } ;
extern "C" { int xdr_opaque (XDR*, void*, u_int); } ;
extern "C" { int xdr_string (XDR*, char**, u_int); } ;
extern "C" { int xdr_union (XDR*, int *, void*, struct xdr_discrim*, int (*)()); } ;
extern "C" { void xdr_free (xdrproc_t, void*); } ;
extern "C" { int xdr_char (XDR*, char*); } ;
extern "C" { int xdr_u_char (XDR*, u_char*); } ;
extern "C" { int xdr_vector (XDR*, void*, u_int, u_int, xdrproc_t); } ;
extern "C" { int xdr_float (XDR*, float*); } ;
extern "C" { int xdr_double (XDR*, double*); } ;
extern "C" { int xdr_reference (XDR*, void**, u_int, xdrproc_t); } ;
extern "C" { int xdr_pointer (XDR*, void**, u_int, xdrproc_t); } ;
extern "C" { int xdr_wrapstring (XDR*, char**); } ;
struct netobj {
u_int n_len;
char *n_bytes;
};
typedef struct netobj netobj;
extern "C" { int xdr_netobj (); } ;
extern "C" { void xdrmem_create (XDR*, void*, u_int, enum xdr_op); } ;
extern "C" { void xdrstdio_create (XDR*, struct _iobuf *, enum xdr_op); } ;
extern "C" { void xdrrec_create (XDR*, u_int, u_int, void*, int(*)(), int(*)()); } ;
extern "C" { int xdrrec_endofrecord (XDR*, int ); } ;
extern "C" { int xdrrec_readbytes (XDR*, void*, u_int); } ;
extern "C" { int xdrrec_skiprecord (XDR*); } ;
extern "C" { int xdrrec_eof (XDR*); } ;
# 8 "xdrstream.h" 2
class oxdrstream : public ostream
{
XDR xdrs;
static int wrThis(void* ptr, void* buf, unsigned len)
{
oxdrstream& self = *(oxdrstream*)(ptr);
self.write(buf, len);
return self.good()? len: -1;
}
public:
oxdrstream(streambuf* sb = 0 )
:ostream(sb)
{
xdrrec_create(&xdrs, 0, 0, this, 0, &wrThis);
xdrs.x_op = XDR_ENCODE;
}
~oxdrstream()
{
xdrrec_endofrecord(&xdrs, (1) );
if ((&xdrs)->x_ops->x_destroy) (*(&xdrs)->x_ops->x_destroy)(&xdrs) ;
}
oxdrstream& put(char c)
{ if (!xdr_char(&xdrs, &c)) set(ios::failbit); return *this; }
oxdrstream& operator<<(char c)
{ return put(c); }
oxdrstream& operator<<(const char *s)
{ if (!xdr_string(&xdrs, &s, 256)) set(ios::failbit); return *this; }
oxdrstream& put(unsigned char c)
{ if (!xdr_u_char(&xdrs, &c)) set(ios::failbit); return *this; }
oxdrstream& operator<<(unsigned char c)
{ return put(c); }
oxdrstream& operator<<(const unsigned char *s)
{ return (*this) << (const char*)s; }
oxdrstream& put(signed char c)
{ return put((char)c); }
oxdrstream& operator<<(signed char c)
{ return put(c); }
oxdrstream& operator<<(const signed char *s)
{ return (*this) << (const char*)s; }
oxdrstream& operator<<(short n)
{ if (!xdr_short(&xdrs, &n)) set(ios::failbit); return *this; }
oxdrstream& operator<<(unsigned short n)
{ if (!xdr_u_short(&xdrs, &n)) set(ios::failbit); return *this; }
oxdrstream& operator<<(int n)
{ if (!xdr_int(&xdrs, &n)) set(ios::failbit); return *this; }
oxdrstream& operator<<(unsigned int n)
{ if (!xdr_u_int(&xdrs, &n)) set(ios::failbit); return *this; }
oxdrstream& operator<<(long n)
{ if (!xdr_long(&xdrs, &n)) set(ios::failbit); return *this; }
oxdrstream& operator<<(unsigned long n)
{ if (!xdr_u_long(&xdrs, &n)) set(ios::failbit); return *this; }
oxdrstream& operator<<(long long n)
{
long* p = (long*)&n;
if (!xdr_long(&xdrs, p)) set(ios::failbit);
if (!xdr_long(&xdrs, p+1)) set(ios::failbit);
return *this;
}
oxdrstream& operator<<(unsigned long long n)
{
unsigned long* p = (unsigned long*)&n;
if (!xdr_u_long(&xdrs, p)) set(ios::failbit);
if (!xdr_u_long(&xdrs, p+1)) set(ios::failbit);
return *this;
}
oxdrstream& operator<<(float n)
{ if (!xdr_float (&xdrs, &n)) set(ios::failbit); return *this; }
oxdrstream& operator<<(double n)
{ if (!xdr_double(&xdrs, &n)) set(ios::failbit); return *this; }
};
class ixdrstream : public istream
{
XDR xdrs;
static int rdThis(void* ptr, void* buf, unsigned len)
{
ixdrstream& self = *(ixdrstream*)(ptr);
self. read(buf, len);
return self.gcount();
}
public:
ixdrstream(streambuf* sb = 0 )
{
init(sb);
xdrrec_create(&xdrs, 0, 0, this, &rdThis, 0);
xdrs.x_op = XDR_DECODE;
xdrrec_skiprecord(&xdrs);
}
~ixdrstream()
{
if ((&xdrs)->x_ops->x_destroy) (*(&xdrs)->x_ops->x_destroy)(&xdrs) ;
}
ixdrstream& get(char& c)
{ if (!xdr_char (&xdrs, &c)) set(ios::failbit); return *this; }
ixdrstream& get(char* ptr, int len, char delim = '\n')
{ if (!xdr_string (&xdrs, &ptr, len)) set(ios::failbit); return *this; }
ixdrstream& operator>>(char& c)
{ return get(c); }
ixdrstream& operator>>(char* s)
{ if (!xdr_string (&xdrs, &s, 256)) set(ios::failbit); return *this; }
ixdrstream& get(unsigned char& c)
{ if (!xdr_u_char (&xdrs, &c)) set(ios::failbit); return *this; }
ixdrstream& get(unsigned char* ptr, int len, char delim = '\n')
{ return get((char*)ptr, len, delim); }
ixdrstream& operator>>(unsigned char& c)
{ return get(c); }
ixdrstream& operator>>(unsigned char* p)
{ return operator>>((char*)p); }
ixdrstream& get(signed char& c)
{ return get((char&)c); }
ixdrstream& get(signed char* ptr, int len, char delim = '\n')
{ return get((char*)ptr, len, delim); }
ixdrstream& operator>>(signed char& c)
{ return get(c); }
ixdrstream& operator>>(signed char*p)
{ return operator>>((char*)p); }
ixdrstream& operator>>(short& n)
{ if (!xdr_short (&xdrs, &n)) set(ios::failbit); return *this; }
ixdrstream& operator>>(unsigned short& n)
{ if (!xdr_u_short (&xdrs, &n)) set(ios::failbit); return *this; }
ixdrstream& operator>>(int& n)
{ if (!xdr_int (&xdrs, &n)) set(ios::failbit); return *this; }
ixdrstream& operator>>(unsigned int& n)
{ if (!xdr_u_int (&xdrs, &n)) set(ios::failbit); return *this; }
ixdrstream& operator>>(long& n)
{ if (!xdr_long (&xdrs, &n)) set(ios::failbit); return *this; }
ixdrstream& operator>>(unsigned long& n)
{ if (!xdr_u_long (&xdrs, &n)) set(ios::failbit); return *this; }
ixdrstream& operator>>(long long& n)
{
long* p = (long*)&n;
if (!xdr_long(&xdrs, p)) set(ios::failbit);
if (!xdr_long(&xdrs, p+1)) set(ios::failbit);
return *this;
}
ixdrstream& operator>>(unsigned long long& n)
{
unsigned long* p = (unsigned long*)&n;
if (!xdr_u_long(&xdrs, p)) set(ios::failbit);
if (!xdr_u_long(&xdrs, p+1)) set(ios::failbit);
return *this;
}
ixdrstream& operator>>(float& n)
{ if (!xdr_float (&xdrs, &n)) set(ios::failbit); return *this; }
ixdrstream& operator>>(double& n)
{ if (!xdr_double(&xdrs, &n)) set(ios::failbit); return *this; }
};
# 1 "xdr.cc" 2
main()
{
int i = 4;
char s[] = "Hello";
double d = 3.14159265358979;
cout << i << endl << s << endl << d << endl;
{
filebuf ofbuf;
ofbuf.open("xfile", "w");
oxdrstream ut(&ofbuf);
ut << i << s << d;
}
int ic;
char sc[100];
double dc;
{
filebuf ifbuf;
ifbuf.open("xfile", "r");
ixdrstream en(&ifbuf);
en >> ic >> sc >> dc;
}
cout << ic << endl << sc << endl << dc << endl;
}
Technical Details
Message-ID:
<9212160218.AA27064@cs.rice.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!agate!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!cs.rice.edu!dougmShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!agate!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!cs.rice.edu!dougm From: dougm@cs.rice.edu (Doug Moore) Subject: 2.3.2 base class initializer bug Message-ID: <9212160218.AA27064@cs.rice.edu> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Wed, 16 Dec 1992 02:18:15 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 2382