Problems with gcc 3.3 and kdeedu

Thiago Macieira thiago at kde.org
Fri Oct 26 10:58:48 BST 2007


Em Friday 26 October 2007 11:02:47 Marc Espie escreveu:
> KDE4 is still supposed to compile with gcc 3.3, right ?

Yes.

> The kalzium beta3 barfs all over the place with stuff like:
>
> /home/ports/x11/kde4/edu/w-kdeedu-3.94.0/kdeedu-3.94.0/kalzium/libavogadro-
>kalzium/src/primitive.h:272: sorry, unimplemented: adjusting pointers for
> covariant returns
>
> I have idea how to fix it...

You have or you don't?

This feature of C++ that gcc 3.3 doesn't support is the following:

class Base
{
public:
    virtual Base *something();
};

class Derived: public Base
{
public:
    virtual Derived *something();
};

Note that "something" is virtual and is overriding the parent's 
implementation, since you cannot overload on return values only. It wouldn't 
be allowed, except for the fact that Derived is derived from Base.

The snippet above gcc 3.3 supports just fine. It doesn't support an adjusting 
covariant return, which would be something like:

class Derived2: public QObject, public Base
{
public:
    virtual Derived2 *something();
};

This is because the following assumption doesn't hold:
    Derived2 *ptr = new Derived2();
    Base *baseptr = ptr;
    assert(ptr == baseptr);    // OK
    assert(intptr_t(ptr) == intptr_t(baseptr));  // Not OK

That is, they ARE the same objects and compare for equality, but the values of 
the pointers are different. That means the value that Derived2::something() 
returns must be adjusted. That's what gcc 3.3 is missing.

Solutions:
1) invert the order of inheritance in Derived2, so that the first base is Base 
(this is not allowed with QObject, like above)

2) don't use covariant returns. That is, in Derived2, make something() return 
Base*. And wherever the up-cast is necessary, introduce a static_cast (where 
you're sure of the type) or a dynamic/qobject_cast.

-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20071026/44b4189b/attachment.sig>


More information about the kde-core-devel mailing list