File tree Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change 4848
4949#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
5050# define Py_BUILD_ASSERT_EXPR (cond ) \
51- (sizeof(struct { _Static_assert(cond, #cond); int dummy ; }), \
51+ (( void ) sizeof (struct { int dummy; _Static_assert (cond, #cond); }), \
5252 0 )
5353#else
5454 /* Assert a build-time dependency, as an expression.
6868 (sizeof (char [1 - 2 *!(cond)]) - 1 )
6969#endif
7070
71- #if defined(__STDC_VERSION__ ) && __STDC_VERSION__ >= 201112L
71+ #if ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) \
72+ || (defined (__cplusplus) && __cplusplus >= 201103L ))
7273 // Use static_assert() on C11 and newer
73- # define Py_BUILD_ASSERT (cond ) static_assert((cond), #cond)
74+ # define Py_BUILD_ASSERT (cond ) \
75+ do { \
76+ static_assert ((cond), #cond); \
77+ } while (0 )
7478#else
7579# define Py_BUILD_ASSERT (cond ) \
7680 do { \
Original file line number Diff line number Diff line change @@ -44,6 +44,11 @@ _testcext_exec(PyObject *module)
4444 return -1 ;
4545 }
4646#endif
47+
48+ // test Py_BUILD_ASSERT() and Py_BUILD_ASSERT_EXPR()
49+ Py_BUILD_ASSERT (sizeof (int ) == sizeof (unsigned int ));
50+ assert (Py_BUILD_ASSERT_EXPR (sizeof (int ) == sizeof (unsigned int )) == 0 );
51+
4752 return 0 ;
4853}
4954
Original file line number Diff line number Diff line change @@ -225,6 +225,10 @@ _testcppext_exec(PyObject *module)
225225 if (!result) return -1 ;
226226 Py_DECREF (result);
227227
228+ // test Py_BUILD_ASSERT() and Py_BUILD_ASSERT_EXPR()
229+ Py_BUILD_ASSERT (sizeof (int ) == sizeof (unsigned int ));
230+ assert (Py_BUILD_ASSERT_EXPR (sizeof (int ) == sizeof (unsigned int )) == 0 );
231+
228232 return 0 ;
229233}
230234
You can’t perform that action at this time.
0 commit comments