aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/generator
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-07-13 13:32:50 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-07-14 11:34:43 +0000
commit27186df9e1ddbf625b73ae9a6c26769d2363a3b4 (patch)
treed7a19d9ab92c4b33fa78ab665d4fa7ade6e62dda /sources/shiboken2/generator
parent871a7e2ea74e093d862f954b7ddca374c02cd5b8 (diff)
shiboken2: Handle virtual methods returning a reference
Although it is a questionable practice, it occurs in Qt 6: virtual const QEventPoint &QPointerEvent::point(int i) const; Previously, the generated return statement return QEventPoint(); would cause a warning about returning a temporary. Fix by creating a static variable and returning a reference to it. Task-number: PYSIDE-1339 Task-number: PYSIDE-904 Change-Id: Id6467be22a166e99e8dcf08b2c7c14df33cd2786 Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2/generator')
-rw-r--r--sources/shiboken2/generator/shiboken2/cppgenerator.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
index 65e12c7bc..54af34180 100644
--- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
@@ -869,6 +869,11 @@ QString CppGenerator::virtualMethodReturn(QTextStream &s,
qCWarning(lcShiboken).noquote().nospace() << errorMsg;
s << Qt::endl << INDENT << "#error " << errorMsg << Qt::endl;
}
+ if (returnType->referenceType() == LValueReference) {
+ s << INDENT << "static " << returnType->typeEntry()->qualifiedCppName()
+ << " result;\n";
+ return QLatin1String("return result;");
+ }
return QLatin1String("return ") + defaultReturnExpr.returnValue()
+ QLatin1Char(';');
}