[PyKDE] still a problem with protected static member functions

Phil Thompson phil at riverbankcomputing.co.uk
Sun Mar 5 12:57:51 GMT 2006


On Sunday 05 March 2006 5:27 am, Gerard Vermeulen wrote:
> Hi Phil,
>
> SIP-4.3 (snapshot-20060304) has still a problem with protected static
> member functions in the sense that it does not generate all include
> statements in the C++ source files (and maybe a deeper problem -- see end
> of mail).
>
> The problem occurs with the following hierarchy:
>
> #ifndef S_H
> #define S_H
>
> class A
> {
> public:
>     A() {}
>     virtual ~A() {}
> protected:
>     static int bar() { return 3; }
> };
>
> class B: public A
> {
> public:
>     B(): A() {}
>     virtual ~B() {}
> private:
>     static int bar(int oops) { return 0; }
> };
>
> class C: public A
> {
> protected:
>     C(): A() {}
>     virtual ~C() {}
>     static int bar(int oops) { return 3*oops; }
> };
>
> class D: public C
> {
> protected:
>     D(): C() {}
>     virtual ~D() {}
> };
>
> class E: public D
> {
> public:
>     E(): D() {}
>     virtual ~E() {}
> };
>
> #endif // S_H
>
> When I define method code for static int C::bar(int) in the following
> SIP specification:
> %Module s 0
>
> class A
> {
> %TypeHeaderCode
> #include <s.h>
> %End
>
> public:
>     A();
>     ~A();
> protected:
>     static int bar();
> };
>
> class B: A
> {
> %TypeHeaderCode
> #include <s.h>
> %End
>
> public:
>     B();
>     ~B();
> };
>
> class C: A
> {
> %TypeHeaderCode
> #include <s.h>
> %End
>
> protected:
>     C();
>     ~C();
>     static int bar(int);
> %MethodCode
> // dummy method code which breaks compilation
> // of classes which are derived a child class
> sipRes = sipC::sipProtect_bar(a0);
> %End
> };
>
> class D: C
> {
> %TypeHeaderCode
> #include <s.h>
> %End
>
> protected:
>     D();
>     ~D();
> };
>
> class E: D
> {
> %TypeHeaderCode
> #include <s.h>
> %End
>
> public:
>     E();
>     ~E();
> };
>
> // End of SIP file
>
> then I have to patch the source code as follows:
>
> --- s-0.3/sipsE.cpp.fix 2006-03-05 05:44:11.000000000 +0100
> +++ s-0.3/sipsE.cpp     2006-03-05 05:44:11.000000000 +0100
> @@ -7,6 +7,7 @@
>  #include "sipAPIs.h"
>  #include "sipsE.h"
>
> +#include "sipsC.h"
>  #include "sipsD.h"
>
> because the method code for bar() gets copied in the generated C++ file
> for class E.

Whoops - I was testing with concatenated files. Will be fixed in tonight's 
snapshot.

> I think that SIP's resolution of static member functions is still broken.
> When SIP is generating the code for class E, it should see that class C
> defines a static member function and use that one.  Class D only has a
> a static member function by inheritance and its inherited static member
> function should not be used in the generated code.

I don't understand - it isn't used in the generated code.

Phil




More information about the PyQt mailing list