From 0829a511f03d75121f2a8aa557fc0b45f5f2069c Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 7 Feb 2024 18:09:36 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20"static=5Fw?= =?UTF-8?q?arning"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/inc/Warnings.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Marlin/src/inc/Warnings.cpp b/Marlin/src/inc/Warnings.cpp index c2c0e63a5240..f889ce38e05c 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__