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]

Bug: Failure to compile legal code (gcc-2.95.2)


Hi,

The code below fails to compile. However, if the commented line in class B
is uncommented, it compiles fine. I assume this is a bug, or I am missing
something very obvious.

Regards,

/Mike

class A
{
public:

  virtual A& operator<<(const char*);
  virtual A& operator<<(int);
};

class B : public A
{
public:

  virtual A& operator<<(int);
  //virtual A& operator<<(const char* x) { return A::operator<<(x); }
};

class C : public B
{
};

class D : public C
{
};


void fooA(A& x)
{
  x << "Hello";
}

void fooB(B& x)
{
  x << "Hello";
}

void fooC(C& x)
{
  x << "Hello";
}

void fooD(D& x)
{
  x << "Hello";
}

[miko@mah21hpc2 src]$ g++ -v stream.cc -c
Reading specs from /usr/local/gcc-2.95.2/lib/gcc-lib/i586-pc-linux-gnu/2.95.2/specs
gcc version 2.95.2 19991024 (release)
 /usr/local/gcc-2.95.2/lib/gcc-lib/i586-pc-linux-gnu/2.95.2/cpp -lang-c++ -v -D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -D__ELF__ -Dunix -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__linux__ -D__unix -D__linux -Asystem(posix) -D__EXCEPTIONS -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -Di586 -Dpentium -D__i586 -D__i586__ -D__pentium -D__pentium__ stream.cc /tmp/ccoRKk4c.ii
GNU CPP version 2.95.2 19991024 (release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/gcc-2.95.2/lib/gcc-lib/i586-pc-linux-gnu/2.95.2/../../../../include/g++-3
 /usr/local/include
 /usr/local/gcc-2.95.2/lib/gcc-lib/i586-pc-linux-gnu/2.95.2/../../../../i586-pc-linux-gnu/include
 /usr/local/gcc-2.95.2/lib/gcc-lib/i586-pc-linux-gnu/2.95.2/include
 /usr/include
End of search list.
The following default directories have been omitted from the search path:
End of omitted list.
 /usr/local/gcc-2.95.2/lib/gcc-lib/i586-pc-linux-gnu/2.95.2/cc1plus /tmp/ccoRKk4c.ii -quiet -dumpbase stream.cc -version -o /tmp/cc63vmnl.s
GNU C++ version 2.95.2 19991024 (release) (i586-pc-linux-gnu) compiled by GNU C version 2.95.2 19991024 (release).
stream.cc: In function `void fooB(B &)':
stream.cc:33: no match for `B & << const char[6]'
stream.cc:13: candidates are: class A & B::operator <<(int)
stream.cc: In function `void fooC(C &)':
stream.cc:38: no match for `C & << const char[6]'
stream.cc:13: candidates are: class A & B::operator <<(int)
stream.cc: In function `void fooD(D &)':
stream.cc:43: no match for `D & << const char[6]'
stream.cc:13: candidates are: class A & B::operator <<(int)


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