The most recent version of python 2.7 (2.7.13) includes a header unicodeobject.h
that uses the register
keyword. My understanding is that C++ 17 has removed this keyword. When compiling against this header using C++ 17, unsurprising a slew of warnings are triggered including:
/opt/anaconda/include/python2.7/unicodeobject.h:534:24: warning: ISO C++1z does not allow ‘register’ storage class specifier [-Wregister]
register PyObject *obj, /* Object */
^~~
/opt/anaconda/include/python2.7/unicodeobject.h:553:24: warning: ISO C++1z does not allow ‘register’ storage class specifier [-Wregister]
register PyObject *obj /* Object */
^~~
/opt/anaconda/include/python2.7/unicodeobject.h:575:29: warning: ISO C++1z does not allow ‘register’ storage class specifier [-Wregister]
register const wchar_t *w, /* wchar_t buffer */
^
/opt/anaconda/include/python2.7/unicodeobject.h:593:23: warning: ISO C++1z does not allow ‘register’ storage class specifier [-Wregister]
register wchar_t *w, /* wchar_t buffer */
That said, I am still able to compile and run python extensions despite these warnings. Is it safe to continue doing so? Is there any way (besides explicitly ignoring the warnings) to resolve these messages such as upgrading to a different version of 2.7 (though as mentioned the newest version seems to still use the register
keyword)?
The use of register
has already been removed in the Python 3 version of this header, so if possible, you should use the Python 3 headers (Python 2 will no longer be maintained in a few years).
Otherwise, you have a few options.
register
yourself (there are only four in the file). This is obviously a poor solution if you are compiling against the system headersregister
keyword, so if the module you are compiling is written in C, you can use a C compiler (e.g. gcc
) instead of a C++ compiler. (I expect the module is written in C++, so this probably won't be an option).register
keyword, so you could consider living with it.Disable the register warning. You can do this for your entire project by passing the flag -Wno-register
on the command line, or you can just disable it for this header by doing this:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wregister"`
#include <unicodeobject.h> // or whatever header includes unicodeobject.h
#pragma GCC diagnostic pop
This will save the current warning settings, ignore the register
warning for that header, then restore the original warning settings after the header has been included. While the pragma says GCC, Clang will also understand this pragma and behave how you'd like.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With