friends inside namespace

David J. Dooling dooling@piglet.chem-eng.nwu.edu
Fri Feb 5 07:29:00 GMT 1999


Brief description: declaring a friend function/operator inside a
namespace and defining it outside the namespace (after a ``using''
directive) causes the compiler to think two functions with the same
signature have been created, one inside the namespace and one outside,
leading to an ambiguity.  If you do not use a using directive and
fully qualify all functions/operators/classes, it compiles without
error.

Note: I am not 100% positive this is an error in the compiler since my
DEC C++ compiler (cxx 6.0-010) also got confused by this sequence of
events.

egcs version: gcc version egcs-2.91.60 19981201 (egcs-1.1.1 release)

architecture: alphaev56-dec-osf4.0d

configure options: --prefix=/usr/local/egcs

command line and output:

g++ -v --save-temps -g friend.cc
Reading specs from /usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/specs
gcc version egcs-2.91.60 19981201 (egcs-1.1.1 release)
 /usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=91 -Dunix -D__osf__ -D_LONGLONG -DSYSTYPE_BSD -D_SYSTYPE_BSD -D__unix__ -D__osf__ -D_LONGLONG -D__SYSTYPE_BSD__ -D_SYSTYPE_BSD -D__unix -D__SYSTYPE_BSD -Asystem(unix) -Asystem(xpg4) -D__EXCEPTIONS -g -D__LANGUAGE_C_PLUS_PLUS__ -D__LANGUAGE_C_PLUS_PLUS -D__cplusplus -Acpu(alpha) -Amachine(alpha) -D__alpha -D__alpha__ -D__alpha_ev5__ -Acpu(ev5) -D__alpha_bwx__ -Acpu(bwx) friend.cc friend.ii
GNU CPP version egcs-2.91.60 19981201 (egcs-1.1.1 release)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/egcs/include/g++
 /usr/local/include
 /usr/local/egcs/alphaev56-dec-osf4.0d/include
 /usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/include
 /usr/include
End of search list.
 /usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/cc1plus friend.ii -quiet -dumpbase friend.cc -g -version -o friend.s
GNU C++ version egcs-2.91.60 19981201 (egcs-1.1.1 release) (alphaev56-dec-osf4.0d) compiled by GNU C version egcs-2.91.60 19981201 (egcs-1.1.1 release).
friend.cc: In function `int main()':
friend.cc:22: ambiguous overload for `_IO_ostream_withassign & << ::N::X &'
friend.cc:15: candidates are: operator <<(ostream &, const ::N::X &)
friend.cc:9:                 operator <<(ostream &, const ::N::X &)
--- end output ---

here are the files (search ``==='' to get to next file)
files included (in order): friend.cc, friend.ii, friend.s

=== friend.cc ===
// test friend declaration in namespace
#include <iostream>

namespace N {
    class X {
	int i;
    public:
	X(int i_i) : i(i_i) {}
	friend std::ostream& operator<<(std::ostream& os, const X& x);
    };
}

using namespace N;
std::ostream& operator<<(std::ostream& os, const X& x)
{
    return os << x.i;
}

main()
{
    X x(7);
    std::cout << x << std::endl;
}

=== friend.ii ===
# 1 "friend.cc"
 
# 1 "/usr/local/egcs/include/g++/iostream" 1 3
 
 



# 1 "/usr/local/egcs/include/g++/iostream.h" 1 3
 

























#pragma interface



# 1 "/usr/local/egcs/include/g++/streambuf.h" 1 3
 


























#pragma interface


   



extern "C" {
# 1 "/usr/local/egcs/include/g++/libio.h" 1 3
 




























# 1 "/usr/local/egcs/alphaev56-dec-osf4.0d/include/_G_config.h" 1 3
  










typedef          int   _G_int8_t __attribute__((__mode__(__QI__)));
typedef unsigned int  _G_uint8_t __attribute__((__mode__(__QI__)));
typedef          int  _G_int16_t __attribute__((__mode__(__HI__)));
typedef unsigned int _G_uint16_t __attribute__((__mode__(__HI__)));
typedef          int  _G_int32_t __attribute__((__mode__(__SI__)));
typedef unsigned int _G_uint32_t __attribute__((__mode__(__SI__)));
typedef          int  _G_int64_t __attribute__((__mode__(__DI__)));
typedef unsigned int _G_uint64_t __attribute__((__mode__(__DI__)));

__extension__ typedef long long _G_llong;
__extension__ typedef unsigned long long _G_ullong;








typedef int _G_clock_t;
typedef int _G_dev_t;
typedef long _G_fpos_t;
typedef unsigned int _G_gid_t;
typedef unsigned int _G_ino_t;
typedef unsigned int _G_mode_t;
typedef unsigned short _G_nlink_t;
typedef long _G_off_t;
typedef int _G_pid_t;



typedef long int _G_ptrdiff_t;
typedef unsigned long _G_sigset_t;



typedef long unsigned int _G_size_t;
typedef int _G_time_t;
typedef unsigned int _G_uid_t;
typedef unsigned int _G_wchar_t;















typedef long _G_ssize_t;
typedef unsigned int _G_wint_t;



















# 1 "/usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/include/stddef.h" 1 3






 


# 19 "/usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/include/stddef.h" 3



 


 





 


# 61 "/usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/include/stddef.h" 3


 





 


















 





 

 

# 131 "/usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/include/stddef.h" 3


 

 

# 190 "/usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/include/stddef.h" 3



 




 

# 271 "/usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/include/stddef.h" 3


# 283 "/usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/include/stddef.h" 3


 

 

# 317 "/usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/include/stddef.h" 3




 





















# 88 "/usr/local/egcs/alphaev56-dec-osf4.0d/include/_G_config.h" 2 3


# 30 "/usr/local/egcs/include/g++/libio.h" 2 3


















 

# 1 "/usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/include/stdarg.h" 1 3
 


































# 1 "/usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/include/va-alpha.h" 1 3
 

 




 





 





typedef struct {
  char *__base;			 
  int __offset;			 
} __gnuc_va_list;




 

# 130 "/usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/include/va-alpha.h" 3


# 36 "/usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/include/stdarg.h" 2 3

# 126 "/usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/include/stdarg.h" 3









# 202 "/usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/include/stdarg.h" 3




# 50 "/usr/local/egcs/include/g++/libio.h" 2 3



























 















# 104 "/usr/local/egcs/include/g++/libio.h" 3











 
























 



















struct _IO_jump_t;  struct _IO_FILE;

 
# 174 "/usr/local/egcs/include/g++/libio.h" 3









    typedef void _IO_lock_t;





 

struct _IO_marker {
  struct _IO_marker *_next;
  struct _IO_FILE *_sbuf;
   

   
  int _pos;
# 207 "/usr/local/egcs/include/g++/libio.h" 3

};

struct _IO_FILE {
  int _flags;		 


   
   
  char* _IO_read_ptr;	 
  char* _IO_read_end;	 
  char* _IO_read_base;	 
  char* _IO_write_base;	 
  char* _IO_write_ptr;	 
  char* _IO_write_end;	 
  char* _IO_buf_base;	 
  char* _IO_buf_end;	 
   
  char *_IO_save_base;  
  char *_IO_backup_base;   
  char *_IO_save_end;  

  struct _IO_marker *_markers;

  struct _IO_FILE *_chain;

  int _fileno;
  int _blksize;



  _G_off_t  _offset;



   
  unsigned short _cur_column;
  char _unused;
  char _shortbuf[1];

   








};











struct _IO_FILE_plus;
extern struct _IO_FILE_plus _IO_stdin_, _IO_stdout_, _IO_stderr_;





 
typedef struct
{
  _G_ssize_t  (*read)  (struct _IO_FILE *, void *, _G_ssize_t )  ;
  _G_ssize_t  (*write)  (struct _IO_FILE *, const void *, _G_ssize_t )  ;
  _G_fpos_t  (*seek)  (struct _IO_FILE *, _G_off_t , int)  ;
  int (*close)  (struct _IO_FILE *)  ;
} _IO_cookie_io_functions_t;

 
struct _IO_cookie_file
{
  struct _IO_FILE file;
  const void *vtable;
  void *cookie;
  _IO_cookie_io_functions_t io_functions;
};



extern "C" {


extern int __underflow  (_IO_FILE *)  ;
extern int __uflow  (_IO_FILE *)  ;
extern int __overflow  (_IO_FILE *, int)  ;

















extern int _IO_getc  (_IO_FILE *__fp)  ;
extern int _IO_putc  (int __c, _IO_FILE *__fp)  ;
extern int _IO_feof  (_IO_FILE *__fp)  ;
extern int _IO_ferror  (_IO_FILE *__fp)  ;

extern int _IO_peekc_locked  (_IO_FILE *__fp)  ;

 



extern void _IO_flockfile  (_IO_FILE *)  ;
extern void _IO_funlockfile  (_IO_FILE *)  ;
extern int _IO_ftrylockfile  (_IO_FILE *)  ;













extern int _IO_vfscanf  (_IO_FILE *, const char *, __gnuc_va_list , int *)  ;
extern int _IO_vfprintf  (_IO_FILE *, const char *, __gnuc_va_list )  ;
extern _G_ssize_t  _IO_padn  (_IO_FILE *, int, _G_ssize_t )  ;
extern _G_size_t  _IO_sgetn  (_IO_FILE *, void *, _G_size_t )  ;





extern _G_fpos_t  _IO_seekoff  (_IO_FILE *, _G_off_t , int, int)  ;
extern _G_fpos_t  _IO_seekpos  (_IO_FILE *, _G_fpos_t , int)  ;


extern void _IO_free_backup_area  (_IO_FILE *)  ;


}



# 36 "/usr/local/egcs/include/g++/streambuf.h" 2 3

}
 

# 1 "/usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/include/stdarg.h" 1 3
 


































# 1 "/usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/include/va-alpha.h" 1 3
 

 




 

# 26 "/usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/include/va-alpha.h" 3


 







# 47 "/usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/include/va-alpha.h" 3


 

 


















 

enum {
  __no_type_class = -1,
  __void_type_class,
  __integer_type_class,
  __char_type_class,
  __enumeral_type_class,
  __boolean_type_class,
  __pointer_type_class,
  __reference_type_class,
  __offset_type_class,
  __real_type_class,
  __complex_type_class,
  __function_type_class,
  __method_type_class,
  __record_type_class,
  __union_type_class,
  __array_type_class,
  __string_type_class,
  __set_type_class,
  __file_type_class,
  __lang_type_class
};



 


 




 





















 




# 36 "/usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/include/stdarg.h" 2 3

# 126 "/usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/include/stdarg.h" 3










 
 













# 168 "/usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/include/stdarg.h" 3


 



# 198 "/usr/local/egcs/lib/gcc-lib/alphaev56-dec-osf4.0d/egcs-2.91.60/include/stdarg.h" 3








# 40 "/usr/local/egcs/include/g++/streambuf.h" 2 3

























extern "C++" {
class istream;  
class ostream; class streambuf;

 







typedef _G_off_t  streamoff;
typedef _G_fpos_t  streampos;

typedef _G_ssize_t  streamsize;

typedef unsigned long __fmtflags;
typedef unsigned char __iostate;

struct _ios_fields
{  
    streambuf *_strbuf;
    ostream* _tie;
    int _width;
    __fmtflags _flags;
    short  _fill;
    __iostate _state;
    __iostate _exceptions;
    int _precision;

    void *_arrays;  
};















# 124 "/usr/local/egcs/include/g++/streambuf.h" 3


class ios : public _ios_fields {
  ios& operator=(ios&);   
  ios (const ios&);  
  public:
    typedef __fmtflags fmtflags;
    typedef int iostate;
    typedef int openmode;
    typedef int streamsize;
    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 ,  
	binary = 128  };
    enum seek_dir { beg, cur, end};
    typedef enum seek_dir seekdir;
     
    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 



	   };
    enum {  
	basefield=dec+oct+hex,
	floatfield = scientific+fixed,
	adjustfield = left+right+internal
    };

# 177 "/usr/local/egcs/include/g++/streambuf.h" 3


    ostream* tie() const { return _tie; }
    ostream* tie(ostream* val) { ostream* save=_tie; _tie=val; return save; }

     
    short  fill() const { return _fill; }
    short  fill(short  newf)
	{short  oldf = _fill; _fill = 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;
	_flags &= ~mask; return oldbits; }
    int width() const { return _width; }
    int width(int val) { int save = _width; _width = val; return save; }




    void _throw_failure() const { }

    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(); }
    void setstate(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 exceptions() const { return _exceptions; }
    void exceptions(iostate enable) {
	_exceptions = enable;
	if (_state & _exceptions) _throw_failure(); }

    streambuf* rdbuf() const { return _strbuf; }
    streambuf* rdbuf(streambuf *_s) {
      streambuf *_old = _strbuf; _strbuf = _s; clear (); return _old; }

    static int sync_with_stdio(int on);
    static void sync_with_stdio() { sync_with_stdio(1); }
    static fmtflags bitalloc();
    static int xalloc();
    void*& pword(int);
    void* pword(int) const;
    long& iword(int);
    long iword(int) const;









     
    class Init {
    public:
      Init () { }
    };

  protected:
    inline ios(streambuf* sb = 0, ostream* tie_to = 0);
    inline virtual ~ios();
    inline void init(streambuf* sb, ostream* tie = 0);
};




typedef ios::seek_dir _seek_dir;


 
 
 
 
 

 
 
class streammarker : private _IO_marker {
    friend class streambuf;
    void set_offset(int offset) { _pos = offset; }
  public:
    streammarker(streambuf *sb);
    ~streammarker();
    int saving() { return  1; }
    int delta(streammarker&);
    int delta();
};

struct streambuf : public _IO_FILE {  
    friend class ios;
    friend class istream;
    friend class ostream;
    friend class streammarker;
    const void *&_vtable() { return *(const void**)((_IO_FILE*)this + 1); }
  protected:
    static streambuf* _list_all;  
    _IO_FILE*& xchain() { return _chain; }
    void _un_link();
    void _link_in();
    char* gptr() const
      { return _flags  & 0x100  ? _IO_save_base : _IO_read_ptr; }
    char* pptr() const { return _IO_write_ptr; }
    char* egptr() const
      { return _flags  & 0x100  ? _IO_save_end : _IO_read_end; }
    char* epptr() const { return _IO_write_end; }
    char* pbase() const { return _IO_write_base; }
    char* eback() const
      { return _flags  & 0x100  ? _IO_save_base : _IO_read_base;}
    char* base() const { return _IO_buf_base; }
    char* ebuf() const { return _IO_buf_end; }
    int blen() const { return _IO_buf_end - _IO_buf_base; }
    void xput_char(char c) { *_IO_write_ptr++ = 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)
      { _flags  & 0x100  ? (_IO_save_base+=n):(_IO_read_ptr+=n);}
    void pbump(int n) { _IO_write_ptr += n; }
    void setb(char* b, char* eb, int a=0);
    void setp(char* p, char* ep)
      { _IO_write_base=_IO_write_ptr=p; _IO_write_end=ep; }
    void setg(char* eb, char* g, char *eg) {
      if (_flags  & 0x100 ) _IO_free_backup_area(this); 
      _IO_read_base = eb; _IO_read_ptr = g; _IO_read_end = eg; }
    char *shortbuf() { return _shortbuf; }

    int in_backup() { return _flags & 0x100 ; }
     
    char *Gbase() { return in_backup() ? _IO_save_base : _IO_read_base; }
     
    char *eGptr() { return in_backup() ? _IO_save_end : _IO_read_end; }
     
    char *Bbase() { return in_backup() ? _IO_read_base : _IO_save_base; }
    char *Bptr() { return _IO_backup_base; }
     
    char *eBptr() { return in_backup() ? _IO_read_end : _IO_save_end; }
    char *Nbase() { return _IO_save_base; }
    char *eNptr() { return _IO_save_end; }
    int have_backup() { return _IO_save_base != __null ; }
    int have_markers() { return _markers != __null ; }
    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 ~streambuf();
    virtual int overflow(int c = (-1) );  
    virtual int underflow();  
    virtual int uflow();  
    virtual int pbackfail(int c);
 
    virtual streamsize xsputn(const char* s, streamsize n);
    virtual streamsize xsgetn(char* s, streamsize n);
    virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
    virtual streampos seekpos(streampos pos, int mode = ios::in|ios::out);

    streampos pubseekoff(streamoff o, _seek_dir d, int mode=ios::in|ios::out)
      { return _IO_seekoff (this, o, d, mode); }
    streampos pubseekpos(streampos pos, int mode = ios::in|ios::out)
      { return _IO_seekpos (this, pos, mode); }
    streampos sseekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
    streampos sseekpos(streampos pos, int mode = ios::in|ios::out);
    virtual streambuf* setbuf(char* p, int len);
    virtual int sync();
    virtual int doallocate();

    int seekmark(streammarker& mark, int delta = 0);
    int sputbackc(char c);
    int sungetc();
    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() == __null ) doallocbuf(); }
    void doallocbuf();
    int in_avail() { return _IO_read_end - _IO_read_ptr; }
    int out_waiting() { return _IO_write_ptr - _IO_write_base; }
    streamsize sputn(const char* s, streamsize n) { return xsputn(s, n); }
    streamsize padn(char pad, streamsize n) { return _IO_padn(this, pad, n); }
    streamsize sgetn(char* s, streamsize n) { return _IO_sgetn(this, s, n); }
    int ignore(int);
    int get_column();
    int set_column(int);
    long sgetline(char* buf, _G_size_t  n, char delim, int putback_delim);
    int sputc(int c) { return _IO_putc(c, this); }
    int sbumpc() { return _IO_getc(this); }
    int sgetc() { return ((  this  )->_IO_read_ptr >= (  this  )->_IO_read_end && __underflow (  this  ) == (-1)  ? (-1)  : *(unsigned char *) (  this  )->_IO_read_ptr)  ; }
    int snextc() {
	if (_IO_read_ptr >= _IO_read_end && __underflow(this) == (-1) )
	  return (-1) ;
	else return _IO_read_ptr++, sgetc(); }
    void stossc() { if (_IO_read_ptr < _IO_read_end) _IO_read_ptr++; }
    int vscan(char const *fmt0, __gnuc_va_list  ap, ios* stream = __null );
    int scan(char const *fmt0 ...);
    int vform(char const *fmt0, __gnuc_va_list  ap);
    int form(char const *fmt0 ...);




    virtual streamsize sys_read(char* buf, streamsize size);
    virtual streamsize sys_write(const char*, streamsize);
    virtual streampos sys_seek(streamoff, _seek_dir);
    virtual int sys_close();
    virtual int sys_stat(void*);  




};

 
 

class filebuf : public streambuf {
  protected:
    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 _fileno >= 0; }
    int fd() const { return is_open() ? _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);
    streamsize xsputn(const char* s, streamsize n);
    streamsize xsgetn(char* s, streamsize n);
    virtual int sync();
  protected:  
 
    int is_reading() { return eback() != egptr(); }
    char* cur_ptr() { return is_reading() ?  gptr() : pptr(); }
     
    char* file_ptr() { return eGptr(); }
     
    virtual streamsize sys_read(char* buf, streamsize size);
    virtual streampos sys_seek(streamoff, _seek_dir);
    virtual streamsize sys_write(const char*, streamsize);
    virtual int sys_stat(void*);  
    virtual int sys_close();




};

inline void ios::init(streambuf* sb, ostream* tie_to) {
		_state = sb ? ios::goodbit : ios::badbit; _exceptions=0;
		_strbuf=sb; _tie = tie_to; _width=0; _fill=' ';

		_flags=ios::skipws|ios::dec;



		_precision=6; _arrays = 0; }

inline ios::ios(streambuf* sb, ostream* tie_to) { init(sb, tie_to); }

inline ios::~ios() {



    if (_arrays) delete [] _arrays;
}
}  

# 31 "/usr/local/egcs/include/g++/iostream.h" 2 3


extern "C++" {
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= __null );
    int opfx() {
	if (!good()) return 0;
	else { if (_tie) _tie->flush();  ; return 1;} }
    void osfx() {  ;
		  if (flags() & (ios::unitbuf|ios::stdio))
		      do_osfx(); }
    ostream& flush();
    ostream& put(char c) { _strbuf->sputc(c); return *this; }





    ostream& write(const char *s, streamsize n);
    ostream& write(const unsigned char *s, streamsize n)
      { return write((const char*)s, n);}
    ostream& write(const signed char *s, streamsize n)
      { return write((const char*)s, n);}
    ostream& write(const void *s, streamsize 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, __gnuc_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<<(const void *p);
    ostream& operator<<(int n);
    ostream& operator<<(unsigned int n);
    ostream& operator<<(long n);
    ostream& operator<<(unsigned long n);

    __extension__ ostream& operator<<(long long n);
    __extension__ 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<<(bool b) { return operator<<((int)b); }

    ostream& operator<<(double n);
    ostream& operator<<(float n) { return operator<<((double)n); }



    ostream& operator<<(long double 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
{
     
protected:
    _G_size_t  _gcount;

    int _skip_ws();
  public:
    istream(): _gcount (0) { }
    istream(streambuf* sb, ostream*tied= __null );
    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, streamsize n);
    istream& read(unsigned char *ptr, streamsize n)
      { return read((char*)ptr, n); }
    istream& read(signed char *ptr, streamsize n)
      { return read((char*)ptr, n); }
    istream& read(void *ptr, streamsize n)
      { return read((char*)ptr, n); }
    istream& get(streambuf& sb, char delim = '\n');
    istream& gets(char **s, char delim = '\n');
    int ipfx(int need = 0) {
	if (!good()) { set(ios::failbit); return 0; }
	else {
	   ;
	  if (_tie && (need == 0 || rdbuf()->in_avail() < need)) _tie->flush();
	  if (!need && (flags() & ios::skipws)) return _skip_ws();
	  else return 1;
	}
    }
    int ipfx0() {  
	if (!good()) { set(ios::failbit); return 0; }
	else {
	   ;
	  if (_tie) _tie->flush();
	  if (flags() & ios::skipws) return _skip_ws();
	  else return 1;
	}
    }
    int ipfx1() {  
	if (!good()) { set(ios::failbit); return 0; }
	else {
	   ;
	  if (_tie && rdbuf()->in_avail() == 0) _tie->flush();
	  return 1;
	}
    }
    void isfx() {  ; }
    int get() { if (!ipfx1()) return (-1) ;
		else { int ch = _strbuf->sbumpc();
		       if (ch == (-1) ) set(ios::eofbit);
		       return ch;
		     } }
    int peek();
    _G_size_t  gcount() { return _gcount; }
    istream& ignore(int n=1, int delim = (-1) );
    int sync ();
    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, __gnuc_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&);

    __extension__ istream& operator>>(long long&);
    __extension__ istream& operator>>(unsigned long long&);

    istream& operator>>(short&);
    istream& operator>>(unsigned int&);
    istream& operator>>(unsigned long&);
    istream& operator>>(unsigned short&);

    istream& operator>>(bool&);

    istream& operator>>(float&);
    istream& operator>>(double&);
    istream& operator>>(long 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
{
  public:
    iostream() { }
    iostream(streambuf* sb, ostream*tied= __null );
};

class _IO_istream_withassign : public istream {
public:
  _IO_istream_withassign& operator=(istream&);
  _IO_istream_withassign& operator=(_IO_istream_withassign& rhs)
    { return operator= (static_cast<istream&> (rhs)); }
};

class _IO_ostream_withassign : public ostream {
public:
  _IO_ostream_withassign& operator=(ostream&);
  _IO_ostream_withassign& operator=(_IO_ostream_withassign& rhs)
    { return operator= (static_cast<ostream&> (rhs)); }
};

extern _IO_istream_withassign cin;
 
extern _IO_ostream_withassign cout, cerr;

extern _IO_ostream_withassign clog

__asm__ ("__IO_clog")

;

extern istream& lock(istream& ins);
extern istream& unlock(istream& ins);
extern ostream& lock(ostream& outs);
extern ostream& unlock(ostream& outs);

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; }
}  


# 6 "/usr/local/egcs/include/g++/iostream" 2 3


# 2 "friend.cc" 2


namespace N {
    class X {
	int i;
    public:
	X(int i_i) : i(i_i) {}
	friend std::ostream& operator<<(std::ostream& os, const X& x);
    };
}

using namespace N;
std::ostream& operator<<(std::ostream& os, const X& x)
{
    return os << x.i;
}

main()
{
    X x(7);
    std::cout << x << std::endl;
}

=== friend.s ===
	.verstamp 3 11
	.set noreorder
	.set volatile
	.set noat
	.arch ev56
	.file	1 "friend.cc"
	#@stabs
 #.stabs "/carol/home/dooling/progs/c++/",100,0,0,$Ltext0
 #.stabs "friend.cc",100,0,0,$Ltext0
.text
$Ltext0:
 #.stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0
 #.stabs "char:t2=r2;0;127;",128,0,0,0
 #.stabs "long int:t3=r1;001000000000000000000000;000777777777777777777777;",128,0,0,0
 #.stabs "unsigned int:t4=r4;0;4294967295;",128,0,0,0
 #.stabs "long unsigned int:t5=r1;000000000000000000000000;001777777777777777777777;",128,0,0,0
 #.stabs "long long int:t6=r1;001000000000000000000000;000777777777777777777777;",128,0,0,0
 #.stabs "long long unsigned int:t7=r1;000000000000000000000000;001777777777777777777777;",128,0,0,0
 #.stabs "short int:t8=r8;-32768;32767;",128,0,0,0
 #.stabs "short unsigned int:t9=r9;0;65535;",128,0,0,0
 #.stabs "signed char:t10=r10;-128;127;",128,0,0,0
 #.stabs "unsigned char:t11=r11;0;255;",128,0,0,0
 #.stabs "float:t12=r1;4;0;",128,0,0,0
 #.stabs "double:t13=r1;8;0;",128,0,0,0
 #.stabs "long double:t14=r1;8;0;",128,0,0,0
 #.stabs "complex int:t15=s8real:1,0,32;imag:1,32,32;;",128,0,0,0
 #.stabs "complex float:t16=r16;4;0;",128,0,0,0
 #.stabs "complex double:t17=r17;8;0;",128,0,0,0
 #.stabs "complex long double:t18=r18;8;0;",128,0,0,0
 #.stabs "bool:t19=@s64;-16;",128,0,0,0
 #.stabs "void:t20=20",128,0,0,0
 #.stabs "__wchar_t:t21=r21;0;4294967295;",128,0,0,0
 #.stabs "__vtbl_ptr_type:t22=s16__delta:8,0,16;__index:8,16,16;__pfn:23=*20,64,64;__delta2:8,64,16;;",128,0,0,0
 #.stabs "_G_int8_t:t24=10",128,0,12,0
 #.stabs "_G_uint8_t:t25=11",128,0,13,0
 #.stabs "_G_int16_t:t26=8",128,0,14,0
 #.stabs "_G_uint16_t:t27=9",128,0,15,0
 #.stabs "_G_int32_t:t28=1",128,0,16,0
 #.stabs "_G_uint32_t:t29=4",128,0,17,0
 #.stabs "_G_int64_t:t30=3",128,0,18,0
 #.stabs "_G_uint64_t:t31=5",128,0,19,0
 #.stabs "_G_llong:t32=6",128,0,21,0
 #.stabs "_G_ullong:t33=7",128,0,22,0
 #.stabs "_G_clock_t:t34=1",128,0,31,0
 #.stabs "_G_dev_t:t35=1",128,0,32,0
 #.stabs "_G_fpos_t:t36=3",128,0,33,0
 #.stabs "_G_gid_t:t37=4",128,0,34,0
 #.stabs "_G_ino_t:t38=4",128,0,35,0
 #.stabs "_G_mode_t:t39=4",128,0,36,0
 #.stabs "_G_nlink_t:t40=9",128,0,37,0
 #.stabs "_G_off_t:t41=3",128,0,38,0
 #.stabs "_G_pid_t:t42=1",128,0,39,0
 #.stabs "_G_ptrdiff_t:t43=3",128,0,43,0
 #.stabs "_G_sigset_t:t44=5",128,0,44,0
 #.stabs "_G_size_t:t45=5",128,0,48,0
 #.stabs "_G_time_t:t46=1",128,0,49,0
 #.stabs "_G_uid_t:t47=4",128,0,50,0
 #.stabs "_G_wchar_t:t48=4",128,0,51,0
 #.stabs "_G_ssize_t:t49=3",128,0,67,0
 #.stabs "_G_wint_t:t50=4",128,0,68,0
 #.stabs "__gnuc_va_list:t51=s16__base:52=*2,0,64;__offset:1,64,32;__as::53=#51,54=&51,55=*51,56=&57=s16__base:52,0,64;__offset:1,64,32;__as::53:__as__3$_0RC3$_0;2A.;$_0::58=#51,55,55,56,20;:__3$_0RC3$_0;2A.59=#51,55,55,20;:__3$_0;2A.;;,20;:__as__3$_0RC3$_0;2A.;$_0::58:__3$_0RC3$_0;2A.59:__3$_0;2A.;;",128,0,23,0
 #.stabs "_IO_lock_t:t60=20",128,0,183,0
 #.stabs "_IO_marker:Tt61=s24_next:62=*61,0,64;_sbuf:63=*64=xs_IO_FILE:,64,64;_pos:1,128,32;__as::65=##66=&61;:RC10_IO_marker;2A.;_IO_marker::67=##62;:RC10_IO_marker;2A.68=##62;:;2A.;;",128,0,208,0
 #.stabs "_IO_FILE:Tt64=s136_flags:1,0,32;_IO_read_ptr:52,64,64;_IO_read_end:52,128,64;_IO_read_base:52,192,64;_IO_write_base:52,256,64;_IO_write_ptr:52,320,64;_IO_write_end:52,384,64;_IO_buf_base:52,448,64;_IO_buf_end:52,512,64;_IO_save_base:52,576,64;_IO_backup_base:52,640,64;_IO_save_end:52,704,64;_markers:62,768,64;_chain:63,832,64;_fileno:1,896,32;_blksize:1,928,32;_offset:41,960,64;_cur_column:9,1024,16;_unused:2,1040,8;_shortbuf:69=ar1;0;0;2,1048,8;__as::70=##71=&64;:RC8_IO_FILE;2A.;_IO_FILE::72=##63;:RC8_IO_FILE;2A.73=##63;:;2A.;;",128,0,256,0
 #.stabs "_IO_cookie_io_functions_t:t74=s32read:75=*76=f49,0,64;write:77=*78=f49,64,64;seek:79=*80=f36,128,64;close:81=*82=f1,192,64;__as::83=#74,84=&74,85=*74,86=&87=s32read:75,0,64;write:77,64,64;seek:79,128,64;close:81,192,64;__as::83:__as__3$_1RC3$_1;2A.;$_1::88=#74,85,85,86,20;:__3$_1RC3$_1;2A.89=#74,85,85,20;:__3$_1;2A.;;,20;:__as__3$_1RC3$_1;2A.;$_1::88:__3$_1RC3$_1;2A.89:__3$_1;2A.;;",128,0,282,0
 #.stabs "_IO_cookie_file:Tt90=s184file:64,0,1088;vtable:91=*20,1088,64;cookie:23,1152,64;io_functions:74,1216,256;__as::92=##93=&90;:RC15_IO_cookie_file;2A.;_IO_cookie_file::94=##95=*90;:RC15_IO_cookie_file;2A.96=##95;:;2A.;;",128,0,291,0
 #.stabs "streamoff:t97=41",128,0,77,0
 #.stabs "streampos:t98=36",128,0,78,0
 #.stabs "streamsize:t99=49",128,0,80,0
 #.stabs "__fmtflags:t100=5",128,0,82,0
 #.stabs "__iostate:t101=11",128,0,83,0
 #.stabs "io_state:t102=egoodbit:0,eofbit:1,failbit:2,badbit:4,;",128,0,135,0
 #.stabs "open_mode:t103=ein:1,out:2,ate:4,app:8,trunc:16,nocreate:32,noreplace:64,bin:128,binary:128,;",128,0,140,0
 #.stabs "seek_dir:t104=ebeg:0,cur:1,end:2,;",128,0,149,0
 #.stabs "_seek_dir:t105=104",128,0,265,0
 #.stabs "__manip:t106=107=*108=f109=&110=xsios:",128,0,35,0
 #.stabs "__imanip:t111=112=*113=f114=&115=xsistream:",128,0,36,0
 #.stabs "__omanip:t116=117=*118=f119=&120=xsostream:",128,0,37,0
 #.stabs "X:Tt121=s4i:/01,0,32;__as::122=##123=&121;:Q21N1XRCQ21N1X;2A.;X::124=##125=*121;:__Q21N1XRCQ21N1X;2A.126=##125;:__Q21N1Xi;2A.;;",128,0,10,0
	.align 5
	.globl __ls__FR7ostreamRCQ21N1X
	.ent __ls__FR7ostreamRCQ21N1X
__ls__FR7ostreamRCQ21N1X:
	.frame $15,32,$26,0
	.mask 0x4008000,-32
	ldgp $29,0($27)
$__ls__FR7ostreamRCQ21N1X..ng:
$LM1:
	 #.stabn 68,0,15,$LM1
	subq $30,32,$30
	stq $26,0($30)
	stq $15,8($30)
	bis $30,$30,$15
	.prologue 1
	stq $16,16($15)
	stq $17,24($15)
$LM2:
	 #.stabn 68,0,15,$LM2
$LBB2:
$LM3:
	 #.stabn 68,0,16,$LM3
	ldq $1,24($15)
	ldl $2,0($1)
	ldq $16,16($15)
	bis $2,$2,$17
	jsr $26,__ls__7ostreami
	ldgp $29,0($26)
	bis $0,$0,$1
	bis $1,$1,$0
	br $31,$L288
$LBE2:
$LM4:
	 #.stabn 68,0,17,$LM4
$L288:
	bis $15,$15,$30
	ldq $26,0($30)
	ldq $15,8($30)
	addq $30,32,$30
	ret $31,($26),1
	.end __ls__FR7ostreamRCQ21N1X
 #.stabs "__ls__FR7ostreamRCQ21N1X:F119",36,0,15,__ls__FR7ostreamRCQ21N1X
 #.stabs "os:p119",160,0,15,32
 #.stabs "x:p127=&121",160,0,15,40
 #.stabn 192,0,0,$LBB2
 #.stabn 224,0,0,$LBE2
	.align 5
	.globl main
	.ent main
main:
	.frame $15,32,$26,0
	.mask 0x4008000,-32
	ldgp $29,0($27)
$main..ng:
$LM5:
	 #.stabn 68,0,20,$LM5
	subq $30,32,$30
	stq $26,0($30)
	stq $15,8($30)
	bis $30,$30,$15
	.prologue 1
$LM6:
	 #.stabn 68,0,20,$LM6
$LBB3:
$LM7:
	 #.stabn 68,0,21,$LM7
	addq $15,16,$16
	bis $31,7,$17
	jsr $26,__Q21N1Xi
	ldgp $29,0($26)
$LM8:
	 #.stabn 68,0,22,$LM8
$LBE3:
	bis $31,$31,$0
	br $31,$L289
$LM9:
	 #.stabn 68,0,23,$LM9
$L289:
	bis $15,$15,$30
	ldq $26,0($30)
	ldq $15,8($30)
	addq $30,32,$30
	ret $31,($26),1
	.end main
 #.stabs "main:F1",36,0,20,main
 #.stabs "x:121",128,0,21,-16
 #.stabn 192,0,0,$LBB3
 #.stabn 224,0,0,$LBE3
	.align 5
	.ent __Q21N1Xi
__Q21N1Xi:
	.frame $15,16,$26,0
	.mask 0x4008000,-16
$__Q21N1Xi..ng:
$LM10:
	 #.stabn 68,0,8,$LM10
	subq $30,16,$30
	stq $26,0($30)
	stq $15,8($30)
	bis $30,$30,$15
	.prologue 0
	bis $16,$16,$2
	bis $17,$17,$1
$LM11:
	 #.stabn 68,0,8,$LM11
	stl $1,0($2)
$LBB4:
$LBE4:
$L287:
	bis $2,$2,$0
	br $31,$L286
$LM12:
	 #.stabn 68,0,8,$LM12
$L286:
	bis $15,$15,$30
	ldq $26,0($30)
	ldq $15,8($30)
	addq $30,16,$30
	ret $31,($26),1
	.end __Q21N1Xi
 #.stabs "__Q21N1Xi:f125",36,0,8,__Q21N1Xi
 #.stabs "this:P125",64,0,8,2
 #.stabs "i_i:P1",64,0,8,1
 #.stabn 192,0,0,$LBB4
 #.stabn 224,0,0,$LBE4


More information about the Gcc-bugs mailing list