diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-09-20 13:14:40 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-09-21 15:45:49 +0200 |
| commit | a03ac672ade3492e6cbefc875e5911c0ec2a5ac9 (patch) | |
| tree | 4d3bf985933d34da860ab462a61bec809f3880e2 | |
| parent | 3fb8c260142c1bc928de40a6d063dd91bba33b8d (diff) | |
shiboken6: Fix wrapper destructor generation detection
Move the hardcoded constant from generator.h into headergenerator.cpp
and use the emulated compiler set on the command line.
Amends b20d6f6906f91f9df608d7800f4e27f7a7160abe.
Task-number: PYSIDE-2057
Task-number: PYSIDE-1812
Change-Id: I126a75ffe02514875422005027a1280234cf1770
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
| -rw-r--r-- | sources/shiboken6/generator/generator.h | 31 | ||||
| -rw-r--r-- | sources/shiboken6/generator/shiboken/headergenerator.cpp | 32 |
2 files changed, 29 insertions, 34 deletions
diff --git a/sources/shiboken6/generator/generator.h b/sources/shiboken6/generator/generator.h index 9d60f1f1a..0020b3057 100644 --- a/sources/shiboken6/generator/generator.h +++ b/sources/shiboken6/generator/generator.h @@ -34,37 +34,6 @@ QString getClassTargetFullName(const AbstractMetaClass *metaClass, bool includeP QString getClassTargetFullName(const AbstractMetaEnum &metaEnum, bool includePackageName = true); QString getFilteredCppSignatureString(QString signature); -/** - * PYSIDE-504: Handling the "protected hack" - * - * The problem: Creating wrappers when the class has private destructors. - * You can see an example on Windows in qclipboard_wrapper.h and others. - * Simply search for the text "// C++11: need to declare (unimplemented) destructor". - * - * The protected hack is the definition "#define protected public". - * For most compilers, this "hack" is enabled, because the problem of private - * destructors simply vanishes. - * - * If one does not want to use this hack, then a new problem arises: - * C++11 requires that a destructor is declared in a wrapper class when it is - * private in the base class. There is no implementation allowed! - * - * Unfortunately, MSVC in recent versions supports C++11, and due to restrictive - * rules, it is impossible to use the hack with this compiler. - * More unfortunate: Clang, when C++11 is enabled, also enforces a declaration - * of a private destructor, but it falsely then creates a linker error! - * - * Originally, we wanted to remove the protected hack. But due to the Clang - * problem, we gave up on removal of the protected hack and use it always - * when we can. This might change again when the Clang problem is solved. - */ - -#ifdef Q_CC_MSVC -const int alwaysGenerateDestructor = 1; -#else -const int alwaysGenerateDestructor = 0; -#endif - class DefaultValue { public: diff --git a/sources/shiboken6/generator/shiboken/headergenerator.cpp b/sources/shiboken6/generator/shiboken/headergenerator.cpp index f1da83ed6..80fb826c4 100644 --- a/sources/shiboken6/generator/shiboken/headergenerator.cpp +++ b/sources/shiboken6/generator/shiboken/headergenerator.cpp @@ -10,6 +10,7 @@ #include <abstractmetalang.h> #include <abstractmetalang_helpers.h> #include <codesnip.h> +#include <clangparser/compilersupport.h> #include <typedatabase.h> #include <reporthandler.h> #include <textstream.h> @@ -33,6 +34,32 @@ using namespace Qt::StringLiterals; +// PYSIDE-504: Handling the "protected hack" +// The problem: Creating wrappers when the class has private destructors. +// You can see an example on Windows in qclipboard_wrapper.h and others. +// Simply search for the text "// C++11: need to declare (unimplemented) destructor". +// The protected hack is the definition "#define protected public". +// For most compilers, this "hack" is enabled, because the problem of private +// destructors simply vanishes. +// +// If one does not want to use this hack, then a new problem arises: +// C++11 requires that a destructor is declared in a wrapper class when it is +// private in the base class. There is no implementation allowed! +// +// Unfortunately, MSVC in recent versions supports C++11, and due to restrictive +// rules, it is impossible to use the hack with this compiler. +// More unfortunate: Clang, when C++11 is enabled, also enforces a declaration +// of a private destructor, but it falsely then creates a linker error! +// +// Originally, we wanted to remove the protected hack. But due to the Clang +// problem, we gave up on removal of the protected hack and use it always +// when we can. This might change again when the Clang problem is solved. + +static bool alwaysGenerateDestructorDeclaration() +{ + return clang::compiler() == Compiler::Msvc; +} + QString HeaderGenerator::headerFileNameForContext(const GeneratorContext &context) { return fileNameForContextHelper(context, u"_wrapper.h"_s); @@ -133,9 +160,8 @@ void HeaderGenerator::generateClass(TextStream &s, const GeneratorContext &class //destructor // 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() + || alwaysGenerateDestructorDeclaration()) { if (avoidProtectedHack() && metaClass->hasPrivateDestructor()) s << "// C++11: need to declare (unimplemented) destructor because " "the base class destructor is private.\n"; |
