[PyKDE] Sip problem with narrowed return types
Phil Thompson
phil at riverbankcomputing.co.uk
Thu Aug 26 17:35:21 BST 2004
On Thursday 26 August 2004 4:46 pm, Lőrentey Károly wrote:
> Hi,
>
> (I'm sorry if this is a known issue, I could not find it mentioned in
> the list archives.)
>
> To try my hand on writing SIP specifications, I chose to write a
> simple Python interface to Scott Wheeler's TagLib. Unfortunately I
> met an obstacle when I came across a situation similar to the
> following:
>
> /* File test.h */
>
> #ifndef TEST_H
> #define TEST_H
>
> class Test
> {
> public:
> virtual Test *foo ();
> };
>
> class Child : public Test
> {
> public:
> virtual Child *foo (); /* Note the return value! */
> };
>
> #endif /* TEST_H */
>
> That is, Child::foo overrides Test::foo, but changes the type of the
> returned value to a subclass of the original type. (See TagLib's
> TagLib::File::audioProperties vs. TagLib::MPEG::File::audioProperties.)
>
> I tried to write a SIP specification for this class hierarchy, but the
> narrowed return type of Child::foo seems to have confused sip. Here
> is my (simple-minded) attempt:
>
> /* File test.sip */
> %Module test 0
>
> class Test
> {
>
> %TypeHeaderCode
> #include "test.h"
> %End
>
> public:
> virtual Test *foo ();
> };
>
> class Child : Test
> {
>
> %TypeHeaderCode
> #include "test.h"
> %End
>
> public:
> virtual Child *foo ();
> };
>
> Running `sip -c . test.sip' produces the following code in
> siptestChild.h:
>
> ...
> class sipChild : public Child
> {
> public:
> ...
> /*
> * There is a public method for every virtual method visible from
> * this class.
> */
> Test * foo(); /* <---- Invalid */
> Child * foo();
> ...
> };
> ...
>
> That is, sip fails to recognize that Child::foo overrides Test::foo,
> and tries to produce code for both. Unfortunately, this is not valid
> C++ code. The `Test * foo ()' declaration has the same signature as
> `Child * foo ()', therefore the C++ compiler signals an error.
>
> Is this a bug in sip, or is there something obvious missing from my
> specification?
It's a bug. I'll fix it before 4.1 which I plan to release in a week or two.
Phil
More information about the PyQt
mailing list