Skip to content

Commit 802380d

Browse files
committed
py/misc.h: prevent clang warning
1 parent d585b1d commit 802380d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

py/misc.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@ typedef unsigned int uint;
5454
#define MP_STRINGIFY(x) MP_STRINGIFY_HELPER(x)
5555

5656
// Static assertion macro
57+
#if __cplusplus
58+
#define MP_STATIC_ASSERT(cond) static_assert((cond), #cond)
59+
#elif __GNUC__ >= 5 || __STDC_VERSION__ >= 201112L
60+
#define MP_STATIC_ASSERT(cond) _Static_assert((cond), #cond)
61+
#else
5762
#define MP_STATIC_ASSERT(cond) ((void)sizeof(char[1 - 2 * !(cond)]))
63+
#endif
64+
5865
// In C++ things like comparing extern const pointers are not constant-expressions so cannot be used
5966
// in MP_STATIC_ASSERT. Note that not all possible compiler versions will reject this. Some gcc versions
6067
// do, others only with -Werror=vla, msvc always does.
@@ -63,7 +70,10 @@ typedef unsigned int uint;
6370
#if defined(_MSC_VER) || defined(__cplusplus)
6471
#define MP_STATIC_ASSERT_NONCONSTEXPR(cond) ((void)1)
6572
#else
66-
#define MP_STATIC_ASSERT_NONCONSTEXPR(cond) MP_STATIC_ASSERT(cond)
73+
#if __clang__
74+
#pragma GCC diagnostic ignored "-Wgnu-folding-constant"
75+
#endif
76+
#define MP_STATIC_ASSERT_NONCONSTEXPR(cond) ((void)sizeof(char[1 - 2 * !(cond)]))
6777
#endif
6878

6979
// Round-up integer division

0 commit comments

Comments
 (0)