bug in g++: cannot redefine endl

Alexandre Oliva oliva@dcc.unicamp.br
Wed Oct 7 12:03:00 GMT 1998


Reiner Suikat <Reiner.Suikat@dlr.de> writes:

>> From: oliva@araguaia.dcc.unicamp.br

>> Reiner Suikat <Reiner.Suikat@dlr.de> writes:

>> > I am unable to redefine iostream functions (e.g. endl).

>> You're not supposed to.  They're part of the standard library, you
>> can't redefine them.

> Sorry, I don't agree!

With the Standard?  It says [basic.def.odr]:

3 Every program shall contain exactly one definition of every non-inline
  function or object  that  is  used  in  that  program;  no  diagnostic
  required.  The definition can appear explicitly in the program, it can
  be found in the standard or a user-defined library, or (when appropri-
  ate)  it  is  implicitly  defined  (see _class.ctor_, _class.dtor_ and
  _class.copy_).  An inline function shall be defined in every  transla-
  tion unit in which it is used.

Since your program does not obey the One Definition Rule, it is ill
formed.  

> So, if it is not allowed to redefine parts of the standard library, why does gcc allow to do so on SGI?

Since this rule can only be detected across translation units with
help from the linker, the Standardization Committee made this
diagnostic optional, so smart linkers will provide an error message,
whereas dumb ones will not, and create a program that, if you're
lucky, will work properly, otherwise, will crash or even destroy the
universe :-)

> Besides, what is the big diference in redefining a function of the
> standard library vs redefinng a function in any other library?

There's no difference; none of these are allowed

-- 
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:oliva@gnu.org mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil




More information about the Gcc-bugs mailing list