diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-09-23 13:31:50 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-09-29 18:26:47 +0200 |
commit | 510bc5b2cf2196d31e950f16d5cfcf6ee1238f47 (patch) | |
tree | 9e8c24faf2ebc76a598aa9013d509aae3444703e | |
parent | 043e74028e55319654685ad97ef5061eb2fda5d2 (diff) |
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 <renato.araujo@kdab.com>
Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r-- | sources/shiboken2/generator/shiboken2/cppgenerator.cpp | 13 | ||||
-rw-r--r-- | sources/shiboken2/tests/libsample/virtualmethods.h | 4 |
2 files changed, 12 insertions, 5 deletions
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_cast<const ::"; - if (func->ownerClass()->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 { diff --git a/sources/shiboken2/tests/libsample/virtualmethods.h b/sources/shiboken2/tests/libsample/virtualmethods.h index 4937fab0d..4b2d25805 100644 --- a/sources/shiboken2/tests/libsample/virtualmethods.h +++ b/sources/shiboken2/tests/libsample/virtualmethods.h @@ -108,6 +108,10 @@ public: virtual const Str & returnConstRef() const; +protected: + // PYSIDE-1388: Protected hack with final classes (see VirtualFinalDaughter). + void protectedMethod() {} + private: Str m_name; int m_left; |