diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-09-05 08:20:01 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-09-06 11:23:03 +0000 |
commit | 66690e5c082d0de7058f9624f7651601ec50e57a (patch) | |
tree | f4caf8bfdbf445e1d8dbc996f5671a688d7a1a48 | |
parent | 10b3dd1e586af0ac5293f2444979e439b4dfc72b (diff) |
Fix default parameters for containers without indirections
e48b696ffab552785d38d72dff6c9dda796c9628 disabled default parameters
for containers since indirections of the argument type can cause
clashes. Enable it for the case of no indirections.
Fixes: PYSIDE-2454
Change-Id: Ie23b2e90244d7fe9e52e31c8314d51293fdbd8fa
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
(cherry picked from commit 1fabac91e548fdb537dce25b3b9a58235275804c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
4 files changed, 23 insertions, 4 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index a87584856..71f8576cd 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -2951,7 +2951,7 @@ qsizetype CppGenerator::writePythonToCppTypeConversion(TextStream &s, // conversion for &cppOut s << ' ' << cppOutAux; // No default value for containers which can also be passed by pointer. - if (arg.type != GeneratorArgument::Type::Container) + if (arg.type != GeneratorArgument::Type::Container || type.indirections() == 0) writeMinimalConstructorExpression(s, api(), type, isPrimitive, defaultValue); s << ";\n" << typeName << " *" << cppOut << " = &" << cppOutAux; } @@ -2983,7 +2983,7 @@ qsizetype CppGenerator::writePythonToCppTypeConversion(TextStream &s, || arg.type == GeneratorArgument::Type::Enum || arg.type == GeneratorArgument::Type::Flags) { writeMinimalConstructorExpression(s, api(), typeEntry, isPrimitive, defaultValue); - } else if (!type.isContainer() && !type.isSmartPointer()) { + } else if ((!type.isContainer() || type.indirections() == 0) && !type.isSmartPointer()) { writeMinimalConstructorExpression(s, api(), type, isPrimitive, defaultValue); } break; diff --git a/sources/shiboken6/tests/libminimal/listuser.cpp b/sources/shiboken6/tests/libminimal/listuser.cpp index 54acc6e05..ba8f43902 100644 --- a/sources/shiboken6/tests/libminimal/listuser.cpp +++ b/sources/shiboken6/tests/libminimal/listuser.cpp @@ -20,6 +20,16 @@ int ListUser::sumIntList(std::list<int> intList) return std::accumulate(intList.begin(), intList.end(), 0); } +int ListUser::sumIntListDefaultParamConstRef(const std::list<int> &intList) +{ + return sumIntList(intList); +} + +int ListUser::sumIntListDefaultParam(std::list<int> intList) +{ + return sumIntList(intList); +} + std::list<MinBool> ListUser::createMinBoolList(MinBool mb1, MinBool mb2) { std::list<MinBool> retval; diff --git a/sources/shiboken6/tests/libminimal/listuser.h b/sources/shiboken6/tests/libminimal/listuser.h index 8d16927ea..e77e156f5 100644 --- a/sources/shiboken6/tests/libminimal/listuser.h +++ b/sources/shiboken6/tests/libminimal/listuser.h @@ -22,6 +22,9 @@ struct LIBMINIMAL_API ListUser virtual int sumIntList(std::list<int> intList); int callSumIntList(std::list<int> intList) { return sumIntList(intList); } + int sumIntListDefaultParamConstRef(const std::list<int> &intList = {1, 2, 3}); + int sumIntListDefaultParam(std::list<int> intList = {1, 2, 3}); + // List of C++ MinBool objects used as primitives in Python virtual std::list<MinBool> createMinBoolList(MinBool mb1, MinBool mb2); std::list<MinBool> callCreateMinBoolList(MinBool mb1, MinBool mb2) { return createMinBoolList(mb1, mb2); } diff --git a/sources/shiboken6/tests/minimalbinding/listuser_test.py b/sources/shiboken6/tests/minimalbinding/listuser_test.py index fc108950f..4d092b33c 100644 --- a/sources/shiboken6/tests/minimalbinding/listuser_test.py +++ b/sources/shiboken6/tests/minimalbinding/listuser_test.py @@ -95,8 +95,14 @@ class IntListConversionTest(unittest.TestCase): def testSumIntList(self): lu = ListUser() lst = range(4) - self.assertEqual(lu.sumIntList(lst), sum(lst)) - self.assertEqual(lu.callSumIntList(lst), sum(lst)) + expected = sum(lst) + self.assertEqual(lu.sumIntList(lst), expected) + self.assertEqual(lu.callSumIntList(lst), expected) + self.assertEqual(lu.sumIntListDefaultParam(lst), expected) + self.assertEqual(lu.sumIntListDefaultParamConstRef(lst), expected) + # PYSIDE-2454: Check container default parameters (1,2,3) + self.assertEqual(lu.sumIntListDefaultParam(), 6) + self.assertEqual(lu.sumIntListDefaultParamConstRef(), 6) def testSumIntListFromExtendedClass(self): lu = ExtListUser() |