home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / gnu / g / bug / 2326 < prev    next >
Encoding:
Text File  |  1993-01-25  |  20.7 KB  |  827 lines

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!cs.rice.edu!dougm
  2. From: dougm@cs.rice.edu (Doug Moore)
  3. Newsgroups: gnu.g++.bug
  4. Subject: 2.3.3: premature dtor of temp?
  5. Date: 25 Jan 1993 20:44:18 -0500
  6. Organization: GNUs Not Usenet
  7. Lines: 814
  8. Sender: daemon@cis.ohio-state.edu
  9. Approved: bug-g++@prep.ai.mit.edu
  10. Distribution: gnu
  11. Message-ID: <9301242117.AA04053@cs.rice.edu>
  12.  
  13. The program that follows demonstrates (I think) that under some
  14. circumstances, g++ destroys a temporary prematurely.  The ARM is a bit
  15. too vague to let me say with complete confidence that this is a bug,
  16. but it certainly ought to be.
  17.  
  18. On a sparc, sunos 4.1.2, using g++ 2.3.3 as shipped, the temporary
  19. object of type Foo is destroyed after the first "<<" operation.  Sun
  20. C++ does not destroy the temporary Foo object until all "<<"
  21. operations are completed.
  22.  
  23. Verbose compiler output:
  24. ===================================================================
  25. g++ -Wall -v bug.cc
  26. Reading specs from /blossom/lib/gcc-lib/sun4/2.3.3/specs
  27. gcc version 2.3.3
  28.  /blossom/lib/gcc-lib/sun4/2.3.3/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 -Wall bug.cc /usr/tmp/cca04009.i
  29. GNU CPP version 2.3.3 (sparc)
  30.  /blossom/lib/gcc-lib/sun4/2.3.3/cc1plus /usr/tmp/cca04009.i -quiet -dumpbase bug.cc -Wall -version -o /usr/tmp/cca04009.s
  31. GNU C++ version 2.3.3 (sparc) compiled by GNU C version 2.3.3.
  32.  as -o /usr/tmp/cca040091.o /usr/tmp/cca04009.s
  33.  /blossom/lib/gcc-lib/sun4/2.3.3/ld -e start -dc -dp /lib/crt0.o -L/blossom/lib/gcc-lib/sun4/2.3.3 -L/blossom/lib /usr/tmp/cca040091.o -lg++ -lgcc -lc -lgcc
  34. ===================================================================
  35.  
  36. Output from the program:
  37.  
  38. ===================================================================
  39. Making foo
  40. Putting foo with value 1
  41. Killing foo with value 1
  42. Putting foo with value 4
  43. Putting foo with value 9
  44. Putting foo with value 16
  45. ===================================================================
  46.  
  47. Output from same program compiled with Sun C++:
  48.  
  49. ===================================================================
  50. Making foo
  51. Putting foo with value 1
  52. Putting foo with value 4
  53. Putting foo with value 9
  54. Putting foo with value 16
  55. Killing foo with value 16
  56. ===================================================================
  57.  
  58. The complete program follows.
  59.  
  60. Doug Moore
  61. (dougm@cs.rice.edu)
  62.  
  63.  
  64. # 1 "bug.cc"
  65. # 1 "/blossom/lib/gcc-lib/sun4/2.3.3/g++-include/iostream.h" 1 3
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85. #pragma interface
  86.  
  87.  
  88.  
  89. # 1 "/blossom/lib/gcc-lib/sun4/2.3.3/g++-include/streambuf.h" 1 3
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109. #pragma interface
  110.  
  111.  
  112.    
  113.  
  114. # 1 "/blossom/lib/gcc-lib/sun4/2.3.3/g++-include/_G_config.h" 1 3
  115.   
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122. typedef long _G_clock_t;
  123. typedef short _G_dev_t;
  124. typedef long   _G_fpos_t;
  125. typedef unsigned short _G_gid_t;
  126. typedef unsigned long _G_ino_t;
  127. typedef unsigned short _G_mode_t;
  128. typedef short _G_nlink_t;
  129. typedef long _G_off_t;
  130. typedef int _G_pid_t;
  131. typedef int _G_ptrdiff_t;
  132. typedef int _G_sigset_t;
  133. typedef int _G_size_t;
  134. typedef long _G_time_t;
  135. typedef unsigned short _G_uid_t;
  136. typedef unsigned short _G_wchar_t;
  137. typedef int   _G_ssize_t;
  138. typedef char * _G_va_list;
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160. # 25 "/blossom/lib/gcc-lib/sun4/2.3.3/g++-include/streambuf.h" 2 3
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176. class ostream; class streambuf; class backupbuf;
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186. extern "C" int __underflow(streambuf*);
  187. extern "C" int __overflow(streambuf*, int);
  188.  
  189. typedef _G_off_t streamoff;
  190. typedef _G_off_t streampos;  
  191.  
  192. typedef unsigned long __fmtflags;
  193. typedef unsigned char __iostate;
  194.  
  195. struct _ios_fields {  
  196.     streambuf *_strbuf;
  197.     ostream* _tie;
  198.     int _width;
  199.     __fmtflags _flags;
  200.     _G_wchar_t _fill;
  201.     __iostate _state;
  202.     __iostate _exceptions;
  203.     int _precision;
  204. };
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220. # 95 "/blossom/lib/gcc-lib/sun4/2.3.3/g++-include/streambuf.h" 3
  221.  
  222.  
  223. class ios : public _ios_fields {
  224.   public:
  225.     typedef __fmtflags fmtflags;
  226.     typedef int iostate;
  227.     typedef int openmode;
  228.     enum io_state {
  229.     goodbit = 0 ,
  230.     eofbit = 1 ,
  231.     failbit = 2 ,
  232.     badbit = 4  };
  233.     enum open_mode {
  234.     in = 1 ,
  235.     out = 2 ,
  236.     ate = 4 ,
  237.     app = 8 ,
  238.     trunc = 16 ,
  239.     nocreate = 32 ,
  240.     noreplace = 64 ,
  241.     bin = 128  };
  242.     enum seek_dir { beg, cur, end};
  243.      
  244.     enum { skipws=01, left=02, right=04, internal=010,
  245.        dec=020, oct=040, hex=0100,
  246.        showbase=0200, showpoint=0400, uppercase=01000, showpos=02000,
  247.        scientific=04000, fixed=010000, unitbuf=020000, stdio=040000,
  248.        dont_close=0x80000000  
  249.        };
  250.     enum {  
  251.     basefield=dec+oct+hex,
  252.     floatfield = scientific+fixed,
  253.     adjustfield = left+right+internal
  254.     };
  255.  
  256. # 138 "/blossom/lib/gcc-lib/sun4/2.3.3/g++-include/streambuf.h" 3
  257.  
  258.  
  259.     ostream* tie() const { return _tie; }
  260.     ostream* tie(ostream* val) { ostream* save=_tie; _tie=val; return save; }
  261.  
  262.      
  263.     _G_wchar_t fill() const { return (_G_wchar_t)_fill; }
  264.     _G_wchar_t fill(_G_wchar_t newf)
  265.     {_G_wchar_t oldf = (_G_wchar_t)_fill; _fill = (char)newf; return oldf;}
  266.     fmtflags flags() const { return _flags; }
  267.     fmtflags flags(fmtflags new_val) {
  268.     fmtflags old_val = _flags; _flags = new_val; return old_val; }
  269.     int precision() const { return _precision; }
  270.     int precision(int newp) {
  271.     unsigned short oldp = _precision; _precision = (unsigned short)newp;
  272.     return oldp; }
  273.     fmtflags setf(fmtflags val) {
  274.     fmtflags oldbits = _flags;
  275.     _flags |= val; return oldbits; }
  276.     fmtflags setf(fmtflags val, fmtflags mask) {
  277.     fmtflags oldbits = _flags;
  278.     _flags = (_flags & ~mask) | (val & mask); return oldbits; }
  279.     fmtflags unsetf(fmtflags mask) {
  280.     fmtflags oldbits = _flags & mask;
  281.     _flags &= ~mask; return oldbits; }
  282.     int width() const { return _width; }
  283.     int width(int val) { int save = _width; _width = val; return save; }
  284.  
  285.  
  286.  
  287.  
  288.     void _throw_failure() { }
  289.  
  290.  
  291.     streambuf* rdbuf() const { return _strbuf; }
  292.     void clear(iostate state = 0) {
  293.     _state = _strbuf ? state : state|badbit;
  294.     if (_state & _exceptions) _throw_failure(); }
  295.     void set(iostate flag) { _state |= flag;
  296.     if (_state & _exceptions) _throw_failure(); }
  297.     int good() const { return _state == 0; }
  298.     int eof() const { return _state & ios::eofbit; }
  299.     int fail() const { return _state & (ios::badbit|ios::failbit); }
  300.     int bad() const { return _state & ios::badbit; }
  301.     iostate rdstate() const { return _state; }
  302.     operator void*() const { return fail() ? (void*)0 : (void*)(-1); }
  303.     int operator!() const { return fail(); }
  304.     iostate exception(iostate enable) {
  305.     iostate old = _exceptions; _exceptions = enable;
  306.     if (_state & _exceptions) _throw_failure();
  307.     return old; }
  308.  
  309.     static int sync_with_stdio(int on);
  310.     static void sync_with_stdio() { sync_with_stdio(1); }
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.   protected:
  321.     ios(streambuf* sb = 0, ostream* tie = 0);
  322.     virtual ~ios();
  323.     void init(streambuf* sb) { _state=0; _strbuf=sb; }
  324. };
  325.  
  326.  
  327.  
  328.  
  329. typedef ios::seek_dir _seek_dir;
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359. class streammarker {
  360.     friend class streambuf;
  361.  
  362.  
  363.  
  364.     friend int __underflow(streambuf*);
  365.  
  366.     struct streammarker *_next;   
  367.     streambuf *_sbuf;  
  368.     streampos _spos;  
  369.     void set_streampos(streampos sp) { _spos = sp; }
  370.     void set_offset(int offset) { _pos = offset; _spos = (streampos)(-2); }
  371.      
  372.      
  373.     int _pos;
  374.   public:
  375.     streammarker(streambuf *sb);
  376.     ~streammarker();
  377.     int saving() { return  _spos == -2; }
  378.     int delta(streammarker&);
  379.     int delta();
  380. };
  381.  
  382. struct __streambuf {
  383.      
  384.     int _flags;         
  385.     char* _gptr;     
  386.     char* _egptr;     
  387.     char* _eback;     
  388.     char* _pbase;     
  389.     char* _pptr;     
  390.     char* _epptr;     
  391.     char* _base;     
  392.     char* _ebuf;     
  393.     struct streambuf *_chain;
  394.  
  395.      
  396.     friend class streammarker;
  397.     char *_other_gbase;  
  398.     char *_aux_limit;   
  399.     char *_other_egptr;  
  400.     streammarker *_markers;
  401.  
  402.  
  403.      
  404.     unsigned short _cur_column;
  405.     char _unused;
  406.     char _shortbuf[1];
  407. };
  408.  
  409. extern unsigned __adjust_column(unsigned start, const char *line, int count);
  410.  
  411. struct streambuf : private __streambuf {
  412.     friend class ios;
  413.     friend class istream;
  414.     friend class ostream;
  415.     friend class streammarker;
  416.  
  417.  
  418.  
  419.     friend int __underflow(streambuf*);
  420.  
  421.   protected:
  422.     static streambuf* _list_all;  
  423.     streambuf*& xchain() { return _chain; }
  424.     void _un_link();
  425.     void _link_in();
  426.     char* gptr() const { return _gptr; }
  427.     char* pptr() const { return _pptr; }
  428.     char* egptr() const { return _egptr; }
  429.     char* epptr() const { return _epptr; }
  430.     char* pbase() const { return _pbase; }
  431.     char* eback() const { return _eback; }
  432.     char* base() const { return _base; }
  433.     char* ebuf() const { return _ebuf; }
  434.     int blen() const { return _ebuf - _base; }
  435.     void xput_char(char c) { *_pptr++ = c; }
  436.     int xflags() { return _flags; }
  437.     int xflags(int f) { int fl = _flags; _flags = f; return fl; }
  438.     void xsetflags(int f) { _flags |= f; }
  439.     void xsetflags(int f, int mask) { _flags = (_flags & ~mask) | (f & mask); }
  440.     void gbump(int n) { _gptr += n; }
  441.     void pbump(int n) { _pptr += n; }
  442.     void setb(char* b, char* eb, int a=0);
  443.     void setp(char* p, char* ep) { _pbase=_pptr=p; _epptr=ep; }
  444.     void setg(char* eb, char* g, char *eg) { _eback=eb; _gptr=g; _egptr=eg; }
  445.     char *shortbuf() { return _shortbuf; }
  446.  
  447.     int in_backup() { return _flags & 0x100 ; }
  448.      
  449.     char *Gbase() { return in_backup() ? _other_gbase : _eback; }
  450.      
  451.     char *eGptr() { return in_backup() ? _other_egptr : _egptr; }
  452.      
  453.     char *Bbase() { return in_backup() ? _eback : _other_gbase; }
  454.     char *Bptr() { return _aux_limit; }
  455.      
  456.     char *eBptr() { return in_backup() ? _egptr : _other_egptr; }
  457.     char *Nbase() { return _other_gbase; }
  458.     char *eNptr() { return _other_egptr; }
  459.     int have_backup() { return _other_gbase != ((void*)0) ; }
  460.     int have_markers() { return _markers != ((void*)0) ; }
  461.     int _least_marker();
  462.     void switch_to_main_get_area();
  463.     void switch_to_backup_area();
  464.     void free_backup_area();
  465.     void unsave_markers();  
  466.     int put_mode() { return _flags & 0x800 ; }
  467.     int switch_to_get_mode();
  468.     
  469.     streambuf(int flags=0);
  470.   public:
  471.     static int flush_all();
  472.     static void flush_all_linebuffered();  
  473.     virtual int underflow() = 0;  
  474.     virtual int overflow(int c = (-1) ) = 0;  
  475.     virtual int doallocate();
  476.     virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
  477.     virtual streampos seekpos(streampos pos, int mode = ios::in|ios::out);
  478.     int seekmark(streammarker& mark, int delta = 0);
  479.     int sputbackc(char c);
  480.     int sungetc();
  481.     virtual ~streambuf();
  482.     int unbuffered() { return _flags & 2  ? 1 : 0; }
  483.     int linebuffered() { return _flags & 0x200  ? 1 : 0; }
  484.     void unbuffered(int i)
  485.     { if (i) _flags |= 2 ; else _flags &= ~2 ; }
  486.     void linebuffered(int i)
  487.     { if (i) _flags |= 0x200 ; else _flags &= ~0x200 ; }
  488.     int allocate() {  
  489.     if (base() || unbuffered()) return 0;
  490.     else return doallocate(); }
  491.      
  492.     void allocbuf() { if (base() == ((void*)0) ) doallocbuf(); }
  493.     void doallocbuf();
  494.     virtual int sync();
  495.     virtual int pbackfail(int c);
  496.     virtual streambuf* setbuf(char* p, int len);
  497.     int in_avail() { return _egptr - _gptr; }
  498.     int out_waiting() { return _pptr - _pbase; }
  499.     virtual int xsputn(const char* s, int n);
  500.     int sputn(const char* s, int n) { return xsputn(s, n); }
  501.     int padn(char pad, int n);  
  502.     virtual int xsgetn(char* s, int n);
  503.     int sgetn(char* s, int n) { return xsgetn(s, n); }
  504.     int ignore(int);
  505.     virtual int get_column();
  506.     virtual int set_column(int);
  507.     long sgetline(char* buf, _G_size_t n, char delim, int putback_delim);
  508.     int sbumpc() {
  509.     if (_gptr >= _egptr && __underflow(this) == (-1) ) return (-1) ;
  510.     else return *(unsigned char*)_gptr++; }
  511.     int sgetc() {
  512.     if (_gptr >= _egptr && __underflow(this) == (-1) ) return (-1) ;
  513.     else return *(unsigned char*)_gptr; }
  514.     int snextc() {
  515.     if (_gptr >= _egptr && __underflow(this) == (-1) ) return (-1) ;
  516.     return _gptr++, sgetc(); }
  517.     int sputc(int c) {
  518.     if (_pptr >= _epptr) return __overflow(this, (unsigned char)c);
  519.     else return *_pptr++ = c, (unsigned char)c; }
  520.     void stossc() { if (_gptr < _egptr) _gptr++; }
  521.     int vscan(char const *fmt0, _G_va_list ap, ios* stream = ((void*)0) );
  522.     int scan(char const *fmt0 ...);
  523.     int vform(char const *fmt0, _G_va_list ap);
  524.     int form(char const *fmt0 ...);
  525.  
  526.  
  527.  
  528.  
  529. };
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539. class backupbuf : public streambuf {
  540.     friend class streammarker;
  541.   protected:
  542.     backupbuf(int flags=0) : streambuf(flags|0x4000 ) { }
  543.   public:
  544.     virtual int pbackfail(int c);
  545.     virtual int underflow();
  546.     virtual int overflow(int c = (-1) );
  547. };
  548.  
  549. struct __file_fields {
  550.     short _fileno;
  551.     int _blksize;
  552.     _G_fpos_t  _offset;
  553.  
  554. };
  555.  
  556. class filebuf : public backupbuf {
  557.   protected:
  558.     struct __file_fields _fb;
  559.     void init();
  560.   public:
  561.     static const int openprot;  
  562.     filebuf();
  563.     filebuf(int fd);
  564.     filebuf(int fd, char* p, int len);
  565.     ~filebuf();
  566.     filebuf* attach(int fd);
  567.     filebuf* open(const char *filename, const char *mode);
  568.     filebuf* open(const char *filename, ios::openmode mode, int prot = 0664);
  569.     virtual int underflow();
  570.     virtual int overflow(int c = (-1) );
  571.     int is_open() const { return _fb._fileno >= 0; }
  572.     int fd() const { return is_open() ? _fb._fileno : (-1) ; }
  573.     filebuf* close();
  574.     virtual int doallocate();
  575.     virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
  576.     virtual streambuf* setbuf(char* p, int len);
  577.     int xsputn(const char* s, int n);
  578.     int xsgetn(char* s, int n);
  579.     virtual int sync();
  580.   protected:  
  581.  
  582.     int is_reading() { return eback() != egptr(); }
  583.     char* cur_ptr() { return is_reading() ?  gptr() : pptr(); }
  584.      
  585.     char* file_ptr() { return eGptr(); }
  586.     int do_write(const char *data, int to_do);
  587.     int do_flush() { return do_write(_pbase, _pptr-_pbase); }
  588.      
  589.     virtual _G_ssize_t sys_read(char* buf, _G_size_t size);
  590.     virtual _G_fpos_t  sys_seek(_G_fpos_t , _seek_dir);
  591.     virtual _G_ssize_t sys_write(const void*, long);
  592.     virtual int sys_stat(void*);  
  593.     virtual int sys_close();
  594. };
  595.  
  596. inline ios::ios(streambuf* sb  , ostream* tie  ) {
  597.         _state = sb ? ios::goodbit : ios::badbit; _exceptions=0;
  598.         _strbuf=sb; _tie = tie; _width=0; _fill=' ';
  599.         _flags=ios::skipws|ios::dec; _precision=6; }
  600. inline ios::~ios() {
  601.     if (!(_flags & (unsigned int)ios::dont_close)) delete _strbuf; }
  602.  
  603.  
  604. # 24 "/blossom/lib/gcc-lib/sun4/2.3.3/g++-include/iostream.h" 2 3
  605.  
  606.  
  607. class istream; class ostream;
  608. typedef ios& (*__manip)(ios&);
  609. typedef istream& (*__imanip)(istream&);
  610. typedef ostream& (*__omanip)(ostream&);
  611.  
  612. extern istream& ws(istream& ins);
  613. extern ostream& flush(ostream& outs);
  614. extern ostream& endl(ostream& outs);
  615. extern ostream& ends(ostream& outs);
  616.  
  617. class ostream : virtual public ios
  618. {
  619.      
  620.     void do_osfx();
  621.   public:
  622.     ostream() { }
  623.     ostream(streambuf* sb, ostream* tied=((void*)0) );
  624.     int opfx() {
  625.     if (!good()) return 0; else { if (_tie) _tie->flush(); return 1;} }
  626.     void osfx() { if (flags() & (ios::unitbuf|ios::stdio))
  627.               do_osfx(); }
  628.     streambuf* ostreambuf() const { return _strbuf; }
  629.     ostream& flush();
  630.     ostream& put(char c) { _strbuf->sputc(c); return *this; }
  631.     ostream& put(unsigned char c) { return put((char)c); }
  632.  
  633.     ostream& write(const char *s, int n);
  634.     ostream& write(const unsigned char *s, int n) { return write((const char*)s, n);}
  635.  
  636.     ostream& put(signed char c) { return put((char)c); }
  637.     ostream& write(const signed char *s, int n) { return write((const char*)s, n);}
  638.  
  639.     ostream& write(const void *s, int n) { return write((const char*)s, n);}
  640.     ostream& seekp(streampos);
  641.     ostream& seekp(streamoff, _seek_dir);
  642.     streampos tellp();
  643.     ostream& form(const char *format ...);
  644.     ostream& vform(const char *format, _G_va_list args);
  645.  
  646.     ostream& operator<<(char c);
  647.     ostream& operator<<(unsigned char c) { return (*this) << (char)c; }
  648.  
  649.     ostream& operator<<(signed char c) { return (*this) << (char)c; }
  650.  
  651.     ostream& operator<<(const char *s);
  652.     ostream& operator<<(const unsigned char *s)
  653.     { return (*this) << (const char*)s; }
  654.  
  655.     ostream& operator<<(const signed char *s)
  656.     { return (*this) << (const char*)s; }
  657.  
  658.     ostream& operator<<(void *p);
  659.     ostream& operator<<(int n);
  660.     ostream& operator<<(unsigned int n);
  661.     ostream& operator<<(long n);
  662.     ostream& operator<<(unsigned long n);
  663.  
  664.     ostream& operator<<(long long n);
  665.     ostream& operator<<(unsigned long long n);
  666.  
  667.     ostream& operator<<(short n) {return operator<<((int)n);}
  668.     ostream& operator<<(unsigned short n) {return operator<<((unsigned int)n);}
  669.     ostream& operator<<(double n);
  670.     ostream& operator<<(float n) { return operator<<((double)n); }
  671.     ostream& operator<<(__omanip func) { return (*func)(*this); }
  672.     ostream& operator<<(__manip func) {(*func)(*this); return *this;}
  673.     ostream& operator<<(streambuf*);
  674. };
  675.  
  676. class istream : virtual public ios
  677. {
  678.      
  679.     _G_ssize_t _gcount;
  680.  
  681.     int _skip_ws();
  682.   public:
  683.     istream() { _gcount = 0; }
  684.     istream(streambuf* sb, ostream*tied=((void*)0) );
  685.     streambuf* istreambuf() const { return _strbuf; }
  686.     istream& get(char* ptr, int len, char delim = '\n');
  687.     istream& get(unsigned char* ptr, int len, char delim = '\n')
  688.     { return get((char*)ptr, len, delim); }
  689.     istream& get(char& c);
  690.     istream& get(unsigned char& c) { return get((char&)c); }
  691.     istream& getline(char* ptr, int len, char delim = '\n');
  692.     istream& getline(unsigned char* ptr, int len, char delim = '\n')
  693.     { return getline((char*)ptr, len, delim); }
  694.  
  695.     istream& get(signed char& c)  { return get((char&)c); }
  696.     istream& get(signed char* ptr, int len, char delim = '\n')
  697.     { return get((char*)ptr, len, delim); }
  698.     istream& getline(signed char* ptr, int len, char delim = '\n')
  699.     { return getline((char*)ptr, len, delim); }
  700.  
  701.     istream& read(char *ptr, int n);
  702.     istream& read(unsigned char *ptr, int n) { return read((char*)ptr, n); }
  703.  
  704.     istream& read(signed char *ptr, int n) { return read((char*)ptr, n); }
  705.  
  706.     istream& read(void *ptr, int n) { return read((char*)ptr, n); }
  707.      
  708.     istream& get(streambuf& sb, char delim = '\n');
  709.     istream& gets(char **s, char delim = '\n');
  710.     int ipfx(int need) {
  711.     if (!good()) { set(ios::failbit); return 0; }
  712.     if (_tie && (need == 0 || rdbuf()->in_avail() < need)) _tie->flush();
  713.     if (!need && (flags() & ios::skipws)) return _skip_ws();
  714.     return 1;
  715.     }
  716.     int ipfx0() {  
  717.     if (!good()) { set(ios::failbit); return 0; }
  718.     if (_tie) _tie->flush();
  719.     if (flags() & ios::skipws) return _skip_ws();
  720.     return 1;
  721.     }
  722.     int ipfx1() {  
  723.     if (!good()) { set(ios::failbit); return 0; }
  724.     if (_tie && rdbuf()->in_avail() == 0) _tie->flush();
  725.     return 1;
  726.     }
  727.     int get() { if (!ipfx1()) return (-1) ;
  728.         int ch = _strbuf->sbumpc();
  729.         if (ch == (-1) ) set(ios::eofbit);
  730.         return ch; }
  731.     int peek() { if (!ipfx1()) return (-1) ;
  732.         int ch = _strbuf->sgetc();
  733.         if (ch == (-1) ) set(ios::eofbit);
  734.         return ch; }
  735.     _G_ssize_t gcount() { return _gcount; }
  736.     istream& ignore(int n=1, int delim = (-1) );
  737.     istream& seekg(streampos);
  738.     istream& seekg(streamoff, _seek_dir);
  739.     streampos tellg();
  740.     istream& putback(char ch) {
  741.     if (good() && _strbuf->sputbackc(ch) == (-1) ) clear(ios::badbit);
  742.     return *this;}
  743.     istream& unget() {
  744.     if (good() && _strbuf->sungetc() == (-1) ) clear(ios::badbit);
  745.     return *this;}
  746.     istream& scan(const char *format ...);
  747.     istream& vscan(const char *format, _G_va_list args);
  748.  
  749.  
  750.  
  751.  
  752.  
  753.     istream& operator>>(char*);
  754.     istream& operator>>(unsigned char* p) { return operator>>((char*)p); }
  755.  
  756.     istream& operator>>(signed char*p) { return operator>>((char*)p); }
  757.  
  758.     istream& operator>>(char& c);
  759.     istream& operator>>(unsigned char& c) {return operator>>((char&)c);}
  760.  
  761.     istream& operator>>(signed char& c) {return operator>>((char&)c);}
  762.  
  763.     istream& operator>>(int&);
  764.     istream& operator>>(long&);
  765.  
  766.     istream& operator>>(long long&);
  767.  
  768.     istream& operator>>(short&);
  769.     istream& operator>>(unsigned int&);
  770.     istream& operator>>(unsigned long&);
  771.  
  772.     istream& operator>>(unsigned long long&);
  773.  
  774.     istream& operator>>(unsigned short&);
  775.     istream& operator>>(float&);
  776.     istream& operator>>(double&);
  777.     istream& operator>>( __manip func) {(*func)(*this); return *this;}
  778.     istream& operator>>(__imanip func) { return (*func)(*this); }
  779.     istream& operator>>(streambuf*);
  780. };
  781.  
  782.  
  783. class iostream : public istream, public ostream
  784. {
  785.     _G_ssize_t _gcount;
  786.   public:
  787.     iostream() { _gcount = 0; }
  788.     iostream(streambuf* sb, ostream*tied=((void*)0) );
  789. };
  790.  
  791. extern istream cin;
  792. extern ostream cout, cerr, clog;  
  793.  
  794. struct Iostream_init { } ;   
  795.  
  796. inline ios& dec(ios& i)
  797. { i.setf(ios::dec, ios::dec|ios::hex|ios::oct); return i; }
  798. inline ios& hex(ios& i)
  799. { i.setf(ios::hex, ios::dec|ios::hex|ios::oct); return i; }
  800. inline ios& oct(ios& i)
  801. { i.setf(ios::oct, ios::dec|ios::hex|ios::oct); return i; }
  802.  
  803.  
  804. # 1 "bug.cc" 2
  805.  
  806.  
  807. class Foo
  808. {
  809.   int a;
  810. public:
  811.   Foo() 
  812.   :a(0) {cerr << "Making foo\n";}
  813.   ~Foo() {cerr << "Killing foo with value " << a << endl;}
  814.   Foo& operator << (int b)
  815.   {
  816.     a += b;
  817.     cerr << "Putting foo with value " << a << endl;
  818.     return *this;
  819.   }
  820. };
  821.  
  822. main()
  823. {
  824.   Foo() << 1 << 3 << 5 << 7;
  825. }
  826.  
  827.