Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ports/analog/common-hal/digitalio/DigitalInOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(

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

if ((port->en0 & mask) && (port->outen & mask)) {
return DIRECTION_OUTPUT;
Expand Down
12 changes: 11 additions & 1 deletion py/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ typedef unsigned int uint;
#define MP_STRINGIFY(x) MP_STRINGIFY_HELPER(x)

// Static assertion macro
#if defined(__cplusplus)
#define MP_STATIC_ASSERT(cond) static_assert((cond), #cond)
#elif __GNUC__ >= 5 || __STDC_VERSION__ >= 201112L
#define MP_STATIC_ASSERT(cond) _Static_assert((cond), #cond)
#else
#define MP_STATIC_ASSERT(cond) ((void)sizeof(char[1 - 2 * !(cond)]))
#endif

// In C++ things like comparing extern const pointers are not constant-expressions so cannot be used
// in MP_STATIC_ASSERT. Note that not all possible compiler versions will reject this. Some gcc versions
// do, others only with -Werror=vla, msvc always does.
Expand All @@ -63,7 +70,10 @@ typedef unsigned int uint;
#if defined(_MSC_VER) || defined(__cplusplus)
#define MP_STATIC_ASSERT_NONCONSTEXPR(cond) ((void)1)
#else
#define MP_STATIC_ASSERT_NONCONSTEXPR(cond) MP_STATIC_ASSERT(cond)
#if defined(__clang__)
#pragma GCC diagnostic ignored "-Wgnu-folding-constant"
#endif
#define MP_STATIC_ASSERT_NONCONSTEXPR(cond) ((void)sizeof(char[1 - 2 * !(cond)]))
#endif

// Round-up integer division
Expand Down