From acc9315288db07cf73d1f7f44d3b9879044b664a Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 23 Feb 2018 16:52:41 +0100 Subject: shiboken: Fix generated initialization code for enum classes Wrap value in int(), which is required for enum classes. Add a compile test to libsample. Task-number: PYSIDE-487 Change-Id: I78f07ae66da64caad1f75722308256e40e91eded Reviewed-by: Alexandru Croitor --- sources/shiboken2/generator/shiboken2/cppgenerator.cpp | 3 ++- sources/shiboken2/tests/libsample/samplenamespace.h | 4 ++++ sources/shiboken2/tests/samplebinding/typesystem_sample.xml | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) (limited to 'sources/shiboken2') diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index 838770e89..3176bcbab 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -1070,7 +1070,8 @@ void CppGenerator::writeEnumConverterFunctions(QTextStream& s, const TypeEntry* code.clear(); - c << INDENT << "int castCppIn = *((" << cppTypeName << "*)cppIn);" << endl; + c << INDENT << "const int castCppIn = int(*reinterpret_cast(cppIn));" << endl; c << INDENT; c << "return "; if (enumType->isFlags()) diff --git a/sources/shiboken2/tests/libsample/samplenamespace.h b/sources/shiboken2/tests/libsample/samplenamespace.h index 3ce410941..93cafa29c 100644 --- a/sources/shiboken2/tests/libsample/samplenamespace.h +++ b/sources/shiboken2/tests/libsample/samplenamespace.h @@ -110,6 +110,10 @@ public: NiceValue1, NiceValue2 }; + enum class NiceEnumClass { + NiceClassValue1, NiceClassValue2 + }; + inline int someMethod(SomeInnerClass*) { return 0; } virtual OkThisIsRecursiveEnough* someVirtualMethod(OkThisIsRecursiveEnough* arg) { return arg; } }; diff --git a/sources/shiboken2/tests/samplebinding/typesystem_sample.xml b/sources/shiboken2/tests/samplebinding/typesystem_sample.xml index c44a5408d..ffb5c976f 100644 --- a/sources/shiboken2/tests/samplebinding/typesystem_sample.xml +++ b/sources/shiboken2/tests/samplebinding/typesystem_sample.xml @@ -548,6 +548,7 @@ + -- cgit v1.2.3