Skip to content

Commit 5d274f5

Browse files
authored
Merge pull request #10656 from dhalbert/clang-warning-fix
py/misc.h: prevent clang warning
2 parents d585b1d + d5d6a8e commit 5d274f5

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

ports/analog/common-hal/digitalio/DigitalInOut.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(
107107

108108
if (self->pin->port < 4) {
109109
// Check that I/O mode is enabled and we don't have in AND out on at the same time
110-
MP_STATIC_ASSERT(!((port->en0 & mask) && (port->inen & mask) && (port->outen & mask)));
110+
MP_STATIC_ASSERT_NONCONSTEXPR(!((port->en0 & mask) && (port->inen & mask) && (port->outen & mask)));
111111

112112
if ((port->en0 & mask) && (port->outen & mask)) {
113113
return DIRECTION_OUTPUT;

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 defined(__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 defined(__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)