Details
Description
The heuristic used by shiboken to find the fully qualified enumeration name for default value does not correctly support expression.
Let's consider the following code:
enum class Color { Red = 1, Blue = 2 }; class Foo { public: Foo(): mSize{0}, mColor{Color::Red} {} void configure(int size=10, Color c=Color::Red) { mSize = size; mColor = c;} Color getColor() const { return mColor; } int getSize() const { return mSize; } private: int mSize; Color mColor; };
And the typesystem
<?xml version="1.0"?> <typesystem package="test"> <enum-type name="Color"/> <primitive-type name="int"/> <object-type name="Foo"> <modify-function signature="configure(Color)"> <modify-argument index="1"> <replace-default-expression with="cppSelf->getSize()"/> </modify-argument> <modify-argument index="2"> <replace-default-expression with="cppSelf->getColor()"/> </modify-argument> </modify-function> </object-type> </typesystem>
Here shiboken will not detect that the default value is an expression and not an enumeration value. It generates the following wrong code: the enumeration name (Color) is added as a prefix whereas it should not (here the default value has been replaced by an expression, not a valid enumeration value)
::Color cppArg1 = Color::cppSelf->getColor(); if (pythonToCpp[1]) pythonToCpp[1](pyArgs[1], &cppArg1);
The resolveScopePrefix function could check that the default value is actually an enumeration value and not an expression.
Attachments
Issue Links
- is duplicated by
-
PYSIDE-1161 Shiboken fails on enum conversion when used as default parameter
- Closed