diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-02-04 16:13:28 +0100 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-02-04 17:13:41 +0000 |
| commit | d684ff99363fe89f6e73b1788a25fccb33aba2b5 (patch) | |
| tree | 5121dab8c3b4f8ebd77e2f9a8731d25c7a409c8d | |
| parent | 69028fc8d04ec566b4565f785d6e6897c2c67c5b (diff) | |
shiboken6: Enable building with --avoid-protected-hack for gcc, clang
Disable the C++ wrapper generation for classes with
private destructors for these compilers.
Fix one additional condition overlooked by
1d044f467070a040713c9566a8a8de3a56c571e7.
With that, it is in principle possible to build
with g++ and --avoid-protected-hack except for
the PrivateDtor shiboken test, which tests accessing
protected methods for classes with private destructors.
Task-number: PYSIDE-1202
Task-number: PYSIDE-504
Change-Id: Ie40ad56c913dd544303aa7d795e80282afb43705
Reviewed-by: Christian Tismer <tismer@stackless.com>
| -rw-r--r-- | sources/shiboken6/ApiExtractor/abstractmetalang.cpp | 10 | ||||
| -rw-r--r-- | sources/shiboken6/generator/shiboken/cppgenerator.cpp | 11 | ||||
| -rw-r--r-- | sources/shiboken6/generator/shiboken/headergenerator.cpp | 5 |
3 files changed, 17 insertions, 9 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetalang.cpp b/sources/shiboken6/ApiExtractor/abstractmetalang.cpp index d528fc60c..e80bc4371 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetalang.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetalang.cpp @@ -872,8 +872,16 @@ static AbstractMetaClass::CppWrapper determineCppWrapper(const AbstractMetaClass return result; } +#ifndef Q_CC_MSVC + // PYSIDE-504: When C++ 11 is used, then the destructor must always be + // declared. Only MSVC can handle this, the others generate a link error. + // See also HeaderGenerator::generateClass(). + if (metaClass->hasPrivateDestructor()) + return result; +#endif + // Need checking for Python overrides? - if (metaClass->isPolymorphic() && !metaClass->hasPrivateDestructor()) + if (metaClass->isPolymorphic()) result |= AbstractMetaClass::CppVirtualMethodWrapper; // Is there anything protected that needs to be made accessible? diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index d206a4c7d..40f98b642 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -3564,8 +3564,9 @@ void CppGenerator::writeMethodCall(TextStream &s, const AbstractMetaFunctionCPtr else if (func->ownerClass()) methodCallClassName = func->ownerClass()->qualifiedCppName(); - if (func->ownerClass()) { - if (!avoidProtectedHack() || !func->isProtected()) { + if (auto ownerClass = func->ownerClass()) { + const bool hasWrapper = shouldGenerateCppWrapper(ownerClass); + if (!avoidProtectedHack() || !func->isProtected() || !hasWrapper) { if (func->isStatic()) { mc << "::" << methodCallClassName << "::"; } else { @@ -3575,7 +3576,6 @@ void CppGenerator::writeMethodCall(TextStream &s, const AbstractMetaFunctionCPtr + QLatin1String(" *>(") + QLatin1String(CPP_SELF_VAR) + QLatin1Char(')'); if (func->isConstant()) { if (avoidProtectedHack()) { - auto ownerClass = func->ownerClass(); mc << "const_cast<const ::"; if (ownerClass->cppWrapper().testFlag(AbstractMetaClass::CppProtectedHackWrapper)) { // PYSIDE-500: Need a special wrapper cast when inherited @@ -3605,10 +3605,9 @@ void CppGenerator::writeMethodCall(TextStream &s, const AbstractMetaFunctionCPtr mc << func->originalName(); } else { if (!func->isStatic()) { - const auto *owner = func->ownerClass(); - const bool directInheritance = context.metaClass() == owner; + const bool directInheritance = context.metaClass() == ownerClass; mc << (directInheritance ? "static_cast" : "reinterpret_cast") - << "<::" << wrapperName(owner) << " *>(" << CPP_SELF_VAR << ")->"; + << "<::" << wrapperName(ownerClass) << " *>(" << CPP_SELF_VAR << ")->"; } if (!func->isAbstract()) diff --git a/sources/shiboken6/generator/shiboken/headergenerator.cpp b/sources/shiboken6/generator/shiboken/headergenerator.cpp index 39e23a680..a2108cc9f 100644 --- a/sources/shiboken6/generator/shiboken/headergenerator.cpp +++ b/sources/shiboken6/generator/shiboken/headergenerator.cpp @@ -161,8 +161,9 @@ void HeaderGenerator::generateClass(TextStream &s, const GeneratorContext &class maxOverrides = 1; //destructor - // PYSIDE-504: When C++ 11 is used, then the destructor must always be written. - // See generator.h for further reference. + // PYSIDE-504: When C++ 11 is used, then the destructor must always be declared. + // See abstractmetalang.cpp, determineCppWrapper() and generator.h for further + // reference. if (!avoidProtectedHack() || !metaClass->hasPrivateDestructor() || alwaysGenerateDestructor) { if (avoidProtectedHack() && metaClass->hasPrivateDestructor()) s << "// C++11: need to declare (unimplemented) destructor because " |
