This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: bug in g++: cannot redefine endl



Reiner Suikat (Reiner.Suikat@dlr.de) writes:
> Testprog:
> #include <iostream.h>
> ostream & endl(ostream& os) {
> // nothing
> 	  return os;
> }
> void main() {
> 	  cout << endl;
> }
> 
> compiling this with g++ testprog.cpp yields:
> 
> /usr/local/lib/libstdc++.a(iostream.o): In function `endl(ostream &)':
> /root/pdsw/egcs-1.1b/objdir/i686-pc-linux-gnulibc1/libio/../../../libio/iostream.cc:914:
> multiple definition of `endl(ostream &)'/tmp/ccVhRWoJ.o(.text+0x0):
> first defined here
> /usr/bin/ld: Warning: size of symbol `endl(ostream &) ' changed from 20
> to 35 in iostream.o
> collect2: ld returned 1 exit status
> 
> What is the problem? Is this a bug or is something wrong with my
> installation? I have installed egcs (and gcc2.8.1 before that) following
> the instructions.

It is a bug in your program.

In the CD2 [basic.def.odr], clause 3 you find:
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 explicitely in the program, it can
be found in the standard or a user-defined library, ... [rest
snipped, typos mine].

You try to provide two definitions, thus the linker is right when it
complains. 

> 
> BTW, the same program compiles fine with gcc2.8.1 on an SGI machine.
> 
And the SGI linker is right as well, as no diagnostic is required.

-- kga
PS: main() returns int ([basic.start.main]).
-------------------------------------------------------------------------
Klaus-Georg Adams        Email: Klaus-Georg.Adams@chemie.uni-karlsruhe.de
Institut f. Anorg. Chemie, Lehrstuhl II            Tel: 49(0)721 608 3485
Universität Karlsruhe, D-76128 Karlsruhe
-------------------------------------------------------------------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]