Bug report
Example:
#include <Python.h>
int main()
{
int array[] = {1, 2, 3};
return Py_ARRAY_LENGTH(array);
}
Building this example with g++ -std=gnu++11 example.cpp or just g++ example.cpp fails with:
In file included from Include/Python.h:70,
from x.cpp:1:
x.cpp: In function ‘int main()’:
Include/pymacro.h:217:30: error: ‘__builtin_types_compatible_p’ was not declared in this scope
217 | + Py_BUILD_ASSERT_EXPR(!__builtin_types_compatible_p(typeof(array), \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
The example builds correctly if I use -std=c++11 (g++ -std=c++11 example.cpp).
The macro is currently defined as:
#define Py_ARRAY_LENGTH(array) \
(sizeof(array) / sizeof((array)[0]) \
+ Py_BUILD_ASSERT_EXPR(!__builtin_types_compatible_p(typeof(array), \
typeof(&(array)[0]))))
#else
#define Py_ARRAY_LENGTH(array) \
(sizeof(array) / sizeof((array)[0]))
#endif
I'm not sure why __builtin_types_compatible_p() is available with -std=c++11, but not with -std=gnu++11.
I made my tests using g++ (GCC) 16.2.1 on Fedora 44.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
Bug report
Example:
Building this example with
g++ -std=gnu++11 example.cppor justg++ example.cppfails with:The example builds correctly if I use
-std=c++11(g++ -std=c++11 example.cpp).The macro is currently defined as:
I'm not sure why
__builtin_types_compatible_p()is available with-std=c++11, but not with-std=gnu++11.I made my tests using g++ (GCC) 16.2.1 on Fedora 44.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs