diff --git a/Marlin/src/inc/Warnings.cpp b/Marlin/src/inc/Warnings.cpp index c2c0e63a52..f889ce38e0 100644 --- a/Marlin/src/inc/Warnings.cpp +++ b/Marlin/src/inc/Warnings.cpp @@ -31,6 +31,24 @@ // Warnings! Located here so they will appear just once in the build output. // +// static_warning works like a static_assert but only emits a (messy) warning. +#ifdef __GNUC__ + namespace mfwarn { + struct true_type {}; + struct false_type {}; + template struct converter : public true_type {}; + template <> struct converter<0> : public false_type {}; + } + #define static_warning(cond, msg) \ + struct CAT(static_warning, __LINE__) { \ + void _(::mfwarn::false_type const&) __attribute__((deprecated(msg))) {}; \ + void _(::mfwarn::true_type const&) {}; \ + CAT(static_warning, __LINE__)() {_(::mfwarn::converter<(cond)>());} \ + } +#else + #define static_warning(...) +#endif + #if ENABLED(MARLIN_DEV_MODE) #warning "WARNING! Disable MARLIN_DEV_MODE for the final build!" #ifdef __LONG_MAX__