gh-118124: Use static_assert() in Py_BUILD_ASSERT() on C11 (#118398)

Use static_assert() in Py_BUILD_ASSERT() and Py_BUILD_ASSERT_EXPR()
on C11 and newer and C++11 and newer.

Add tests to test_cext and test_cppext.
This commit is contained in:
Victor Stinner 2024-04-30 22:29:48 +02:00 committed by GitHub
parent 6999d68d28
commit 587388ff22
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 45 additions and 16 deletions

View file

@ -225,6 +225,10 @@ _testcppext_exec(PyObject *module)
if (!result) return -1;
Py_DECREF(result);
// test Py_BUILD_ASSERT() and Py_BUILD_ASSERT_EXPR()
Py_BUILD_ASSERT(sizeof(int) == sizeof(unsigned int));
assert(Py_BUILD_ASSERT_EXPR(sizeof(int) == sizeof(unsigned int)) == 0);
return 0;
}