Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sources/shiboken6/tests/smartbinding/std_optional_test.py9
-rw-r--r--sources/shiboken6/tests/smartbinding/typesystem_smart.xml13
2 files changed, 22 insertions, 0 deletions
diff --git a/sources/shiboken6/tests/smartbinding/std_optional_test.py b/sources/shiboken6/tests/smartbinding/std_optional_test.py
index cd97facfa..9e8bc8d47 100644
--- a/sources/shiboken6/tests/smartbinding/std_optional_test.py
+++ b/sources/shiboken6/tests/smartbinding/std_optional_test.py
@@ -26,6 +26,15 @@ def integer_from_value(v):
class StdOptionalTests(unittest.TestCase):
+ def testConversionFromInt(self):
+ """PYSIDE-3107: Test whether a parameter taking a 'std::optional<int>'
+ accepts 'int'."""
+ b = StdOptionalTestBench()
+ b.setOptionalInt(43)
+ self.assertEqual(b.optionalInt().value(), 43)
+ b.setOptionalInt(None)
+ self.assertFalse(b.optionalInt().has_value())
+
def testCInt(self):
b = StdOptionalTestBench()
ci = b.optionalInt()
diff --git a/sources/shiboken6/tests/smartbinding/typesystem_smart.xml b/sources/shiboken6/tests/smartbinding/typesystem_smart.xml
index 14b181b61..4024036fa 100644
--- a/sources/shiboken6/tests/smartbinding/typesystem_smart.xml
+++ b/sources/shiboken6/tests/smartbinding/typesystem_smart.xml
@@ -50,6 +50,19 @@
value-check-method="has_value"
instantiations="Integer,int">
<include file-name="optional" location="global"/>
+ <!-- PYSIDE-3107: Generic rule constructing std::optional<T>' from 'T'. -->
+ <conversion-rule>
+ <target-to-native>
+ <add-conversion type="Py_None">
+ SBK_UNUSED(pyIn)
+ %out = std::nullopt;
+ </add-conversion>
+ <add-conversion type="InstType" check="%CHECKTYPE[%OUTTYPE_0](%in)">
+ %OUTTYPE_0 v = %CONVERTTOCPP[%OUTTYPE_0](%in);
+ %out = %OUTTYPE(v);
+ </add-conversion>
+ </target-to-native>
+ </conversion-rule>
</smart-pointer-type>
</namespace-type>