This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
g++ 2.95.1/2 inheritance bug
- To: gcc-bugs at gcc dot gnu dot org
- Subject: g++ 2.95.1/2 inheritance bug
- From: Karsten Otto <Karsten dot Otto at xtradyne dot de>
- Date: Wed, 9 Feb 2000 11:04:34 +0100 (MET)
Hello,
I am currently using g++ version 2.95.1/2 on SuSE Linux 6.2 (2.2.10 kernel).
It seems to compile the following code incorrectly (stream_test.ii):
# 1 "stream_test.cc"
class myinsuper
{
public:
virtual myinsuper& operator>>(bool &b) = 0;
virtual myinsuper& operator>>(myinsuper& (*f)(myinsuper*)) { return f(this); }
};
class myinstream : public myinsuper
{
public:
myinstream() : myinsuper() {}
virtual myinsuper& operator>>(bool &b)
{
return *this;
}
};
myinsuper& op(myinsuper *s)
{
return *s;
}
int main(int argc, char **argv)
{
myinstream inp;
inp >> op;
}
Compilation results in the following error messages:
$ g++ -v --save-temps -c stream_test.cc
Reading specs from /net/linux/egcs/lib/gcc-lib/i586-pc-linux-gnu/2.95.1/specs
gcc version 2.95.1 19990816 (release)
/net/linux/egcs/lib/gcc-lib/i586-pc-linux-gnu/2.95.1/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_test.cc stream_test.ii
GNU CPP version 2.95.1 19990816 (release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
/net/linux/egcs/lib/gcc-lib/i586-pc-linux-gnu/2.95.1/../../../../include/g++-3
/usr/local/include
/net/linux/egcs/lib/gcc-lib/i586-pc-linux-gnu/2.95.1/../../../../i586-pc-linux-gnu/include
/net/linux/egcs/lib/gcc-lib/i586-pc-linux-gnu/2.95.1/include
/usr/include
End of search list.
The following default directories have been omitted from the search path:
End of omitted list.
/net/linux/egcs/lib/gcc-lib/i586-pc-linux-gnu/2.95.1/cc1plus stream_test.ii -quiet -dumpbase stream_test.cc -version -o stream_test.s
GNU C++ version 2.95.1 19990816 (release) (i586-pc-linux-gnu) compiled by GNU C version 2.95.1 19990816 (release).
stream_test.cc: In function `int main(int, char **)':
stream_test.cc:32: initializing non-const `bool &' with `myinsuper & (*)(myinsuper *)' will use a temporary
stream_test.cc:16: in passing argument 1 of `myinstream::operator >>(bool &)'
Funnily enough, there is a different error message when I use -pedantic:
$ g++ -v --save-temps -pedantic -c stream_test.cc
Reading specs from /net/linux/egcs/lib/gcc-lib/i586-pc-linux-gnu/2.95.1/specs
gcc version 2.95.1 19990816 (release)
/net/linux/egcs/lib/gcc-lib/i586-pc-linux-gnu/2.95.1/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 -pedantic -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -Di586 -Dpentium -D__i586 -D__i586__ -D__pentium -D__pentium__ stream_test.cc stream_test.ii
GNU CPP version 2.95.1 19990816 (release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
/net/linux/egcs/lib/gcc-lib/i586-pc-linux-gnu/2.95.1/../../../../include/g++-3
/usr/local/include
/net/linux/egcs/lib/gcc-lib/i586-pc-linux-gnu/2.95.1/../../../../i586-pc-linux-gnu/include
/net/linux/egcs/lib/gcc-lib/i586-pc-linux-gnu/2.95.1/include
/usr/include
End of search list.
The following default directories have been omitted from the search path:
End of omitted list.
/net/linux/egcs/lib/gcc-lib/i586-pc-linux-gnu/2.95.1/cc1plus stream_test.ii -quiet -dumpbase stream_test.cc -pedantic -version -o stream_test.s
GNU C++ version 2.95.1 19990816 (release) (i586-pc-linux-gnu) compiled by GNU C version 2.95.1 19990816 (release).
stream_test.cc: In function `int main(int, char **)':
stream_test.cc:32: no match for `myinstream & >> myinsuper & (&)(myinsuper *)'
stream_test.cc:16: candidates are: class myinsuper & myinstream::operator >>(bool &) <near match>
Obviously, the operator>> taking the function pointer argument is not properly
inherited from class myinsuper to class myinstream. When I copy the definition
line from class myinsuper to class myinstream, the code is compiled correctly.
I also tried changing the line in main() from inp >> op; to inp >> &op;
(which should be equivalent), then the error stated matches the definition
of function op:
stream_test.cc: In function `int main(int, char **)':
stream_test.cc:32: no match for `myinstream & >> myinsuper & (*)(myinsuper *)'
stream_test.cc:16: candidates are: class myinsuper & myinstream::operator >>(bool &) <near match>
I also tried compilation with the newer g++ 2.95.2, but it results in the same
error messages.
Sincerely,
Karsten Otto (kao@xtradyne.de)