2 // { dg-options "-Wno-builtin-declaration-mismatch" }
3 // This test case caused the compiler to abort at one point in time.
6 class ostream; class streambuf;
8 typedef long streamoff, streampos;
17 unsigned short _precision;
21 enum state_value { _good = 0, _eof = 1, _fail = 2, _bad = 4 };
22 enum open_mode { input=1, output=2, append=8 };
25 class ios : public _ios_fields {
27 enum io_state { goodbit=0, eofbit=1, failbit=2, badbit=4 };
36 enum seek_dir { beg, cur, end};
37 enum { skipws=01, left=02, right=04, internal=010,
38 dec=020, oct=040, hex=0100,
39 showbase=0200, showpoint=0400, uppercase=01000, showpos=02000,
40 scientific=04000, fixed=0100000, unitbuf=020000, stdio=040000,
44 ostream* tie() const { return _tie; }
45 ostream* tie(ostream* val) { ostream* save=_tie; _tie=val; return save; }
48 char fill() const { return _fill; }
49 char fill(char newf) { char oldf = _fill; _fill = newf; return oldf; }
50 unsigned long flags() const { return _flags; }
51 unsigned long flags(unsigned long new_val) {
52 unsigned long old_val = _flags; _flags = new_val; return old_val; }
53 unsigned short precision() const { return _precision; }
54 unsigned short precision(int newp) {
55 unsigned short oldp = _precision; _precision = (unsigned short)newp;
57 unsigned long setf(unsigned long val) {
58 unsigned long oldbits = _flags;
59 _flags |= val; return oldbits; }
60 unsigned long setf(unsigned long val, unsigned long mask) {
61 unsigned long oldbits = _flags;
62 _flags = (_flags & ~mask) | (val & mask); return oldbits; }
63 unsigned long unsetf(unsigned long mask) {
64 unsigned long oldbits = _flags & mask;
65 _flags &= ~mask; return oldbits; }
66 int width() const { return _width; }
67 int width(long val) { long save = _width; _width = val; return save; }
69 static const unsigned long basefield;
70 static const unsigned long adjustfield;
71 static const unsigned long floatfield;
73 streambuf* rdbuf() const { return _strbuf; }
74 void clear(int state = 0) { _state = state; }
75 int good() const { return _state == 0; }
76 int eof() const { return _state & ios::eofbit; }
77 int fail() const { return _state & (ios::badbit|ios::failbit); }
78 int bad() const { return _state & ios::badbit; }
79 int rdstate() const { return _state; }
80 void set(int flag) { _state |= flag; }
81 operator void*() const { return fail() ? (void*)0 : (void*)this; }
82 int operator!() const { return fail(); }
85 void unset(state_value flag) { _state &= ~flag; }
93 ios(streambuf*sb) { _strbuf=sb; _state=0; _width=0; _fill=' ';
94 _flags=ios::skipws; _precision=6; }
100 typedef ios::seek_dir _seek_dir;
123 //# 168 "/usr/latest/lib/g++-include/streambuf.h" 3
137 struct streambuf *_chain;
144 struct streambuf : private __streambuf {
146 friend class istream;
147 friend class ostream;
149 static streambuf* _list_all;
150 streambuf*& xchain() { return _chain; }
153 char* gptr() const { return _gptr; }
154 char* pptr() const { return _pptr; }
155 char* egptr() const { return _egptr; }
156 char* epptr() const { return _epptr; }
157 char* pbase() const { return _pbase; }
158 char* eback() const { return _eback; }
159 char* ebuf() const { return _ebuf; }
160 char* base() const { return _base; }
161 void xput_char(char c) { *_pptr++ = c; }
162 int xflags() { return _flags; }
163 int xflags(int f) { int fl = _flags; _flags = f; return fl; }
164 void xsetflags(int f) { _flags |= f; }
165 void gbump(int n) { _gptr += n; }
166 void pbump(int n) { _pptr += n; }
167 void setb(char* b, char* eb, int a=0);
168 void setp(char* p, char* ep) { _pbase=_pptr=p; _epptr=ep; }
169 void setg(char* eb, char* g, char *eg) { _eback=eb; _gptr=g; _egptr=eg; }
171 static int flush_all();
172 static void flush_all_linebuffered();
173 virtual int underflow();
174 virtual int overflow(int c = (-1) );
175 virtual int doallocate();
176 virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
177 virtual streampos seekpos(streampos pos, int mode = ios::in|ios::out);
178 int sputbackc(char c);
181 virtual ~streambuf();
182 int unbuffered() { return _flags & 2 ? 1 : 0; }
183 int linebuffered() { return _flags & 0x4000 ? 1 : 0; }
184 void unbuffered(int i)
185 { if (i) _flags |= 2 ; else _flags &= ~2 ; }
186 void linebuffered(int i)
187 { if (i) _flags |= 0x4000 ; else _flags &= ~0x4000 ; }
189 if (base() || unbuffered()) return 0;
190 else return doallocate(); }
192 virtual int pbackfail(int c);
193 virtual int ungetfail();
194 virtual streambuf* setbuf(char* p, int len);
195 int in_avail() { return _egptr - _gptr; }
196 int out_waiting() { return _pptr - _pbase; }
197 virtual int sputn(const char* s, int n);
198 virtual int sgetn(char* s, int n);
199 long sgetline(char* buf, int n, char delim, int putback_delim);
201 if (_gptr >= _egptr && underflow() == (-1) ) return (-1) ;
202 else return *(unsigned char*)_gptr++; }
204 if (_gptr >= _egptr && underflow() == (-1) ) return (-1) ;
205 else return *(unsigned char*)_gptr; }
207 if (++_gptr >= _egptr && underflow() == (-1) ) return (-1) ;
208 else return *(unsigned char*)_gptr; }
210 if (_pptr >= _epptr) return overflow(c);
211 return *_pptr++ = c, (unsigned char)c; }
212 int vscan(char const *fmt0, char* ap);
213 int vform(char const *fmt0, char* ap);
222 struct __file_fields {
232 class filebuf : public streambuf {
233 struct __file_fields _fb;
238 filebuf(int fd, char* p, int len);
240 filebuf* attach(int fd);
241 filebuf* open(const char *filename, const char *mode);
242 filebuf* open(const char *filename, int mode, int prot = 0664);
243 virtual int underflow();
244 virtual int overflow(int c = (-1) );
245 int is_open() { return _fb._fileno >= 0; }
246 int fd() { return is_open() ? _fb._fileno : (-1) ; }
248 virtual int doallocate();
249 virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
250 int sputn(const char* s, int n);
251 int sgetn(char* s, int n);
254 virtual int pbackfail(int c);
255 int is_reading() { return eback() != egptr(); }
256 char* cur_ptr() { return is_reading() ? gptr() : pptr(); }
258 char* file_ptr() { return _fb._save_gptr ? _fb._save_egptr : egptr(); }
261 virtual int sys_read(char* buf, int size);
262 virtual long sys_seek(long , _seek_dir);
263 virtual long sys_write(const void*, long);
264 virtual int sys_stat(void*);
265 virtual int sys_close();
269 inline int ios::readable() { return rdbuf()->_flags & 4 ; }
270 inline int ios::writable() { return rdbuf()->_flags & 8 ; }
271 inline int ios::is_open() {return rdbuf()->_flags & 4 +8 ;}
276 //# 25 "/usr/latest/lib/g++-include/iostream.h" 2 3
279 class istream; class ostream;
280 typedef istream& (*__imanip)(istream&);
281 typedef ostream& (*__omanip)(ostream&);
283 extern istream& ws(istream& ins);
284 extern ostream& flush(ostream& outs);
285 extern ostream& endl(ostream& outs);
286 extern ostream& ends(ostream& outs);
288 class ostream : public ios
293 ostream(streambuf* sb, ostream* tied=__null );
296 int opfx() { if (!good()) return 0; if (_tie) _tie->flush(); return 1; }
297 void osfx() { if (flags() & (ios::unitbuf|ios::stdio))
299 streambuf* ostreambuf() const { return _strbuf; }
301 ostream& put(char c);
302 ostream& write(const char *s, int n);
303 ostream& write(const unsigned char *s, int n) { return write((char*)s, n);}
304 ostream& write(const void *s, int n) { return write((char*)s, n);}
305 ostream& seekp(streampos);
306 ostream& seekp(streamoff, _seek_dir);
308 ostream& form(const char *format ...);
309 ostream& vform(const char *format, char* args);
312 extern ostream& operator<<(ostream&, char c);
313 inline ostream& operator<<(ostream& os, unsigned char c)
314 { return os << (char)c; }
316 extern ostream& operator<<(ostream&, const char *s);
317 inline ostream& operator<<(ostream& os, const unsigned char *s)
318 { return os << (const char*)s; }
321 extern ostream& operator<<(ostream&, void *p);
322 extern ostream& operator<<(ostream&, int n);
323 extern ostream& operator<<(ostream&, long n);
324 extern ostream& operator<<(ostream&, unsigned int n);
325 extern ostream& operator<<(ostream&, unsigned long n);
326 inline ostream& operator<<(ostream& os, short n) {return os << (int)n;}
327 inline ostream& operator<<(ostream& os, unsigned short n)
328 {return os << (unsigned int)n;}
329 extern ostream& operator<<(ostream&, float n);
330 extern ostream& operator<<(ostream&, double n);
331 inline ostream& operator<<(ostream& os, __omanip func) { return (*func)(os); }
332 extern ostream& operator<<(ostream&, streambuf*);
334 class istream : public ios
339 istream(streambuf* sb, ostream*tied=__null );
341 streambuf* istreambuf() const { return _strbuf; }
342 istream& get(char& c);
343 istream& get(unsigned char& c);
344 istream& read(char *ptr, int n);
345 istream& read(unsigned char *ptr, int n) { return read((char*)ptr, n); }
346 istream& read(void *ptr, int n) { return read((char*)ptr, n); }
348 istream& getline(char* ptr, int len, char delim = '\n');
349 istream& get(char* ptr, int len, char delim = '\n');
350 istream& gets(char **s, char delim = '\n');
352 if (!good()) { set(ios::failbit); return 0; }
353 if (_tie && (need == 0 || rdbuf()->in_avail() < need)) _tie->flush();
354 if (!need && (flags() & ios::skipws) && !ws(*this)) return 0;
358 if (!good()) { set(ios::failbit); return 0; }
359 if (_tie) _tie->flush();
360 if ((flags() & ios::skipws) && !ws(*this)) return 0;
364 if (!good()) { set(ios::failbit); return 0; }
365 if (_tie && rdbuf()->in_avail() == 0) _tie->flush();
368 int get() { if (!ipfx1()) return (-1) ;
369 int ch = _strbuf->sbumpc();
370 if (ch == (-1) ) set(ios::eofbit);
372 int peek() { if (!ipfx1()) return (-1) ;
373 int ch = _strbuf->sgetc();
374 if (ch == (-1) ) set(ios::eofbit);
376 int gcount() { return _gcount; }
377 istream& ignore(int n=1, int delim = (-1) );
378 istream& seekg(streampos);
379 istream& seekg(streamoff, _seek_dir);
381 istream& putback(char ch) {
382 if (good() && _strbuf->sputbackc(ch) == (-1) ) clear(ios::badbit);
385 if (good() && _strbuf->sungetc() == (-1) ) clear(ios::badbit);
388 istream& unget(char ch) { return putback(ch); }
393 extern istream& operator>>(istream&, char*);
394 inline istream& operator>>(istream& is, unsigned char* p)
395 { return is >> (char*)p; }
397 extern istream& operator>>(istream&, char& c);
398 extern istream& operator>>(istream&, unsigned char& c);
400 extern istream& operator>>(istream&, int&);
401 extern istream& operator>>(istream&, long&);
402 extern istream& operator>>(istream&, short&);
403 extern istream& operator>>(istream&, unsigned int&);
404 extern istream& operator>>(istream&, unsigned long&);
405 extern istream& operator>>(istream&, unsigned short&);
406 extern istream& operator>>(istream&, float&);
407 extern istream& operator>>(istream&, double&);
408 inline istream& operator>>(istream& is, __imanip func) { return (*func)(is); }
410 inline ostream& ostream::put(char c) { _strbuf->sputc(c); return *this; }
412 class iostream : public ios {
416 iostream(streambuf* sb, ostream*tied=__null );
417 operator istream&() { return *(istream*)this; }
418 operator ostream&() { return *(ostream*)this; }
421 istream& get(char& c) { return ((istream*)this)->get(c); }
422 istream& get(unsigned char& c) { return ((istream*)this)->get(c); }
423 istream& read(char *ptr, int n) { return ((istream*)this)->read(ptr, n); }
424 istream& read(unsigned char *ptr, int n)
425 { return ((istream*)this)->read((char*)ptr, n); }
426 istream& read(void *ptr, int n)
427 { return ((istream*)this)->read((char*)ptr, n); }
428 istream& getline(char* ptr, int len, char delim = '\n')
429 { return ((istream*)this)->getline(ptr, len, delim); }
430 istream& get(char* ptr, int len, char delim = '\n')
431 { return ((istream*)this)->get(ptr, len, delim); }
432 istream& gets(char **s, char delim = '\n')
433 { return ((istream*)this)->gets(s, delim); }
434 istream& ignore(int n=1, int delim = (-1) )
435 { return ((istream*)this)->ignore(n, delim); }
436 int ipfx(int need) { return ((istream*)this)->ipfx(need); }
437 int ipfx0() { return ((istream*)this)->ipfx0(); }
438 int ipfx1() { return ((istream*)this)->ipfx1(); }
439 int get() { return _strbuf->sbumpc(); }
440 int peek() { return ipfx1() ? _strbuf->sgetc() : (-1) ; }
441 int gcount() { return _gcount; }
442 istream& putback(char ch) { return ((istream*)this)->putback(ch); }
443 istream& unget() { return ((istream*)this)->unget(); }
444 istream& seekg(streampos pos) { return ((istream*)this)->seekg(pos); }
445 istream& seekg(streamoff off, _seek_dir dir)
446 { return ((istream*)this)->seekg(off, dir); }
447 streampos tellg() { return ((istream*)this)->tellg(); }
449 istream& unget(char ch) { return putback(ch); }
453 int opfx() { return ((ostream*)this)->opfx(); }
454 void osfx() { ((ostream*)this)->osfx(); }
455 ostream& flush() { return ((ostream*)this)->flush(); }
456 ostream& put(char c) { return ((ostream*)this)->put(c); }
457 ostream& write(const char *s, int n)
458 { return ((ostream*)this)->write(s, n); }
459 ostream& write(const unsigned char *s, int n)
460 { return ((ostream*)this)->write((char*)s, n); }
461 ostream& write(const void *s, int n)
462 { return ((ostream*)this)->write((char*)s, n); }
463 ostream& form(const char *format ...);
464 ostream& vform(const char *format, char* args)
465 { return ((ostream*)this)->vform(format, args); }
466 ostream& seekp(streampos pos) { return ((ostream*)this)->seekp(pos); }
467 ostream& seekp(streamoff off, _seek_dir dir)
468 { return ((ostream*)this)->seekp(off, dir); }
469 streampos tellp() { return ((ostream*)this)->tellp(); }
473 extern ostream cout, cerr, clog;
475 struct Iostream_init { } ;
477 inline ios& dec(ios& i)
478 { i.setf(ios::dec, ios::dec|ios::hex|ios::oct); return i; }
479 inline ios& hex(ios& i)
480 { i.setf(ios::hex, ios::dec|ios::hex|ios::oct); return i; }
481 inline ios& oct(ios& i)
482 { i.setf(ios::oct, ios::dec|ios::hex|ios::oct); return i; }
485 //# 7 "/usr/latest/lib/g++-include/stream.h" 2 3
488 extern char* form(const char*, ...);
490 extern char* dec(long, int=0);
491 extern char* dec(int, int=0);
492 extern char* dec(unsigned long, int=0);
493 extern char* dec(unsigned int, int=0);
495 extern char* hex(long, int=0);
496 extern char* hex(int, int=0);
497 extern char* hex(unsigned long, int=0);
498 extern char* hex(unsigned int, int=0);
500 extern char* oct(long, int=0);
501 extern char* oct(int, int=0);
502 extern char* oct(unsigned long, int=0);
503 extern char* oct(unsigned int, int=0);
505 inline istream& WS(istream& str) { return ws(str); }
514 virtual const char *stringify() = 0;
515 virtual char *stringify2() const = 0; // { dg-message "overridden" }
518 class X: public Y { // { dg-message "defined here" }
521 const char *stringify(); // { dg-message "candidate" }
522 const char *stringify2() const; // { dg-message "candidate" }
523 // { dg-error "conflicting return type" "" { target *-*-* } .-1 }
527 X::stringify() const // { dg-error "no declaration matches" }
533 X::stringify2() // { dg-error "no declaration matches" }
545 cout << x.stringify() << '\n';
546 cout << x.stringify2() << '\n';
549 cout << y.stringify() << '\n';
550 cout << y.stringify2() << '\n';