-
Notifications
You must be signed in to change notification settings - Fork 493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CTK pragma macros and fix "PythonQtInstanceWrapper.h" -Wold-style-cast warnings #837
base: master
Are you sure you want to change the base?
Add CTK pragma macros and fix "PythonQtInstanceWrapper.h" -Wold-style-cast warnings #837
Conversation
…-cast warnings The macros were adapted from ITK and allow to avoid warnings like the following: /path/to/Slicer-build/CTK-build/CMakeExternals/Install/include/PythonQt/PythonQtInstanceWrapper.h: In member function ‘PythonQtClassInfo* PythonQtInstanceWrapperStruct::classInfo()’: /path/to/Slicer-build/python-install/include/python2.7/object.h:115:49: warning: use of old-style cast [-Wold-style-cast] #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) ^ /path/to/Slicer-build/CTK-build/CMakeExternals/Install/include/PythonQt/PythonQtInstanceWrapper.h:68:37: note: in expansion of macro ‘Py_TYPE’ { return ((PythonQtClassWrapper*)Py_TYPE(this))->_classInfo; } ^
Since the can be of general use in the remaining of CTK (and also user code) I added them to
|
for reference, here is the email sent to the pythonqt discussion forum (not yet visible): Hi Florian, Would you accept a patch like the following to systematically ignore old-style cast warnings ? That would be very helpful and avoid user code to maintain their own guard headers. diff --git a/src/PythonQtPythonInclude.h b/src/PythonQtPythonInclude.h
index 00f0b07..bd20c76 100644
--- a/src/PythonQtPythonInclude.h
+++ b/src/PythonQtPythonInclude.h
@@ -44,6 +44,15 @@
#define PYTHONQT_RESTORE_KEYWORDS
#endif
+// Ignore "old-style-cast" warnings associated with use of macro like Py_TYPE
+// provided by pythonX.Y/object.h
+#if defined( __GNUC__ )
+#if ( __GNUC__ == 4 ) && ( __GNUC_MINOR__ == 9 ) || ( __GNUC__ >= 7 )
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
+#endif
+#endif
+
// If PYTHONQT_USE_RELEASE_PYTHON_FALLBACK is enabled, try to link
// release Python DLL if it is available by undefining _DEBUG while
// including Python.h
@@ -59,6 +68,12 @@
#include <Python.h>
#endif
+#if defined( __GNUC__ )
+#if ( __GNUC__ == 4 ) && ( __GNUC_MINOR__ == 9 ) || ( __GNUC__ >= 7 )
+#pragma GCC diagnostic pop
+#endif
+#endif
+
Example of warnings:
|
It turns out that (1) the patch was incorrect and (2) updating Instead the following should be done: diff --git a/src/PythonQt.h b/src/PythonQt.h
index fd2e28e..643d984 100644
--- a/src/PythonQt.h
+++ b/src/PythonQt.h
@@ -42,6 +42,15 @@
*/
//----------------------------------------------------------------------------------
+// Ignore "old-style-cast" warnings associated with use of macro like Py_TYPE
+// provided by pythonX.Y/object.h
+#if defined( __GNUC__ )
+#if ( __GNUC__ > 4 ) || (( __GNUC__ >= 4 ) && ( __GNUC_MINOR__ >= 6 ))
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
+#endif
+#endif
+
#include "PythonQtPythonInclude.h"
#include "PythonQtUtils.h"
#include "PythonQtSystem.h"
@@ -51,6 +60,13 @@
#include "PythonQtObjectPtr.h"
#include "PythonQtStdIn.h"
#include "PythonQtThreadSupport.h"
+
+#if defined( __GNUC__ )
+#if ( __GNUC__ > 4 ) || (( __GNUC__ >= 4 ) && ( __GNUC_MINOR__ >= 6 ))
+#pragma GCC diagnostic pop
+#endif
+#endif
+
#include <QObject>
#include <QVariant>
#include <QList> |
The macros were adapted from ITK and allow to avoid warnings like the following: