Title: [C API] Py_ARRAY_LENGTH() macro is incompatible with g++ -std=gnu++11 · Issue #158810 · python/cpython · GitHub
Open Graph Title: [C API] Py_ARRAY_LENGTH() macro is incompatible with g++ -std=gnu++11 · Issue #158810 · python/cpython
X Title: [C API] Py_ARRAY_LENGTH() macro is incompatible with g++ -std=gnu++11 · Issue #158810 · python/cpython
Description: Bug report Example: #include
Open Graph Description: Bug report Example: #include
X Description: 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 ...
Opengraph URL: https://github.com/python/cpython/issues/158810
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[C API] Py_ARRAY_LENGTH() macro is incompatible with g++ -std=gnu++11","articleBody":"### Bug report\n\nExample:\n\n```c++\n#include \u003cPython.h>\n\nint main()\n{\n int array[] = {1, 2, 3};\n return Py_ARRAY_LENGTH(array);\n}\n```\n\nBuilding this example with `g++ -std=gnu++11 example.cpp` or just `g++ example.cpp` fails with:\n\n```\nIn file included from Include/Python.h:70,\n from x.cpp:1:\nx.cpp: In function ‘int main()’:\nInclude/pymacro.h:217:30: error: ‘__builtin_types_compatible_p’ was not declared in this scope\n 217 | + Py_BUILD_ASSERT_EXPR(!__builtin_types_compatible_p(typeof(array), \\\n | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~\n```\n\nThe example builds correctly if I use `-std=c++11` (`g++ -std=c++11 example.cpp`).\n\nThe macro is currently defined as:\n\n```c++\n#define Py_ARRAY_LENGTH(array) \\\n (sizeof(array) / sizeof((array)[0]) \\\n + Py_BUILD_ASSERT_EXPR(!__builtin_types_compatible_p(typeof(array), \\\n typeof(&(array)[0]))))\n#else\n#define Py_ARRAY_LENGTH(array) \\\n (sizeof(array) / sizeof((array)[0]))\n#endif\n```\n\nI'm not sure why `__builtin_types_compatible_p()` is available with `-std=c++11`, but not with `-std=gnu++11`.\n\nI made my tests using g++ (GCC) 16.2.1 on Fedora 44.\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-158812\n* gh-158838\n* gh-159315\n* gh-159317\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/vstinner","@type":"Person","name":"vstinner"},"datePublished":"2026-10-04T22:24:08Z","url":"https://github.com/python/cpython/issues/158810"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:dbd34675-de1e-2342-490f-e894b221e49a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8900:21AC3F:42C9BE2:547E37B:6B0207C4 |
| html-safe-nonce | 3cfc03cb247d0067dfa624a017ab845b5372bbaad2316266dd5491eb7074578d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OTAwOjIxQUMzRjo0MkM5QkUyOjU0N0UzN0I6NkIwMjA3QzQiLCJ2aXNpdG9yX2lkIjoiNjU2MDk1MTcyMjAxMTkyMDMyNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 507e819ef74c57044ddfd949e63c34eab8abfdb48880291b06b3fbfd886de64d |
| hovercard-subject-tag | issue:5703873401 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/158810/issue_layout |
| twitter:image | https://opengraph.githubassets.com/91aa300192c7193d33eedf574d1272ff515c567b8022105793433e9920135d2e/python/cpython/issues/158810 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/91aa300192c7193d33eedf574d1272ff515c567b8022105793433e9920135d2e/python/cpython/issues/158810 |
| og:image:alt | Bug report Example: #include |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | vstinner |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width