From 510bc5b2cf2196d31e950f16d5cfcf6ee1238f47 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 23 Sep 2020 13:31:50 +0200 Subject: shiboken2: Correctly generate final classes with protected methods without protected hack Add a missing check for final class. Amends 170756fa1e5de0ce7ba33521f1eb168d70ad276d. Fixes: PYSIDE-1388 Change-Id: I6b7cd5c9a769838287ac7165bdc2d5ad63b289a1 Reviewed-by: Renato Araujo Oliveira Filho Reviewed-by: Christian Tismer --- sources/shiboken2/generator/shiboken2/cppgenerator.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'sources/shiboken2/generator/shiboken2/cppgenerator.cpp') diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index 6ec8c0d3c..676cb4985 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -2188,7 +2188,8 @@ void CppGenerator::writeCppSelfDefinition(QTextStream &s, Q_ASSERT(!(cppSelfAsReference && hasStaticOverload)); const AbstractMetaClass *metaClass = context.metaClass(); - bool useWrapperClass = avoidProtectedHack() && metaClass->hasProtectedMembers(); + bool useWrapperClass = avoidProtectedHack() && metaClass->hasProtectedMembers() + && !metaClass->attributes().testFlag(AbstractMetaAttributes::FinalCppClass); Q_ASSERT(!useWrapperClass || context.useWrapper()); QString className; if (!context.forSmartPointer()) { @@ -3488,14 +3489,16 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f + QLatin1String(" *>(") + QLatin1String(CPP_SELF_VAR) + QLatin1Char(')'); if (func->isConstant()) { if (avoidProtectedHack()) { + auto ownerClass = func->ownerClass(); mc << "const_castownerClass()->hasProtectedMembers()) { + if (ownerClass->hasProtectedMembers() + && !ownerClass->attributes().testFlag(AbstractMetaAttributes::FinalCppClass)) { // PYSIDE-500: Need a special wrapper cast when inherited - const QString selfWrapCast = func->ownerClass() == func->implementingClass() + const QString selfWrapCast = ownerClass == func->implementingClass() ? QLatin1String(CPP_SELF_VAR) - : QLatin1String("reinterpret_cast<") + wrapperName(func->ownerClass()) + : QLatin1String("reinterpret_cast<") + wrapperName(ownerClass) + QLatin1String(" *>(") + QLatin1String(CPP_SELF_VAR) + QLatin1Char(')'); - mc << wrapperName(func->ownerClass()); + mc << wrapperName(ownerClass); mc << " *>(" << selfWrapCast << ")->"; } else { -- cgit v1.2.3