This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: no rtti polymorphism
- To: Frank Joppe <frankj at delta-n dot com>
- Subject: Re: no rtti polymorphism
- From: <llewelly at dbritsch dot dsl dot xmission dot com>
- Date: Fri, 16 Jun 2000 02:19:48 -0600 (MDT)
- Cc: gcc-bugs at gcc dot gnu dot org
On Fri, 16 Jun 2000, Frank Joppe wrote:
> Hi, I've encountered the following in all egcs versions I've used. I'm not sure whether this should be regarded as a bug, but it feels like it does. I've attached reproducing source code in polyinh.C, the makefile and the testresults.
>
> One of the first things I learned about C++ OO properties was that I would not have to use 'while' or 'switch / case' constructions anymore, this is why I feel like I'm reporting a bug.
>
> class A
> {
> virtual void foo( const A & par )
> {
> // report incompatible
> }
> }
>
> class B : public A
> {
> virtual void foo( const B & par )
> {
> // report compatible
> }
> }
Note: For B::foo() to overited A::foo(), both must have the same name and
parameter types. So B::foo(const B&) does not overide A::foo(const A&),
so you can not expect calls to foo() through an A* to be dynamicaly
bound to B::foo(const B&). If you want B::foo() to override A::foo(),
change its parameter types to match: B::foo(const A&) .
I do not know if the above note has anything to do with your problems; I
am pointing it out in the hope that it may be relevant.
>
> With these two classes any combination of B::foo( x ) should be incompatible for any x not of type B. It should be compatible with x being of type B.
>
> Running the program tells us that calling 'foo' is incompatible in any case. I've also tried a polymorphic variant where all polymorphic methods also exist in class B, this gives us the same result.
>
> Current work-around I've used is to dynamic cast a pointer ( for foo( const A *par) ) and check whether it returns NULL.
>
> Could you give me your opinion on this?
>
It is very hard to tell exactly what kind of problem you encountered, so I
cannot tell if this is a bug in gcc, or a bug in your code.
In the future, please see gcc.gnu.org/bugs.html, and follow the
bug reporting directions there.
Thank you for your bug report.