Skip to content

Commit 0829a51

Browse files
committed
πŸ§‘β€πŸ’» "static_warning"
1 parent a3c78c4 commit 0829a51

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

β€ŽMarlin/src/inc/Warnings.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@
3131
// Warnings! Located here so they will appear just once in the build output.
3232
//
3333

34+
// static_warning works like a static_assert but only emits a (messy) warning.
35+
#ifdef __GNUC__
36+
namespace mfwarn {
37+
struct true_type {};
38+
struct false_type {};
39+
template <int test> struct converter : public true_type {};
40+
template <> struct converter<0> : public false_type {};
41+
}
42+
#define static_warning(cond, msg) \
43+
struct CAT(static_warning, __LINE__) { \
44+
void _(::mfwarn::false_type const&) __attribute__((deprecated(msg))) {}; \
45+
void _(::mfwarn::true_type const&) {}; \
46+
CAT(static_warning, __LINE__)() {_(::mfwarn::converter<(cond)>());} \
47+
}
48+
#else
49+
#define static_warning(...)
50+
#endif
51+
3452
#if ENABLED(MARLIN_DEV_MODE)
3553
#warning "WARNING! Disable MARLIN_DEV_MODE for the final build!"
3654
#ifdef __LONG_MAX__

0 commit comments

Comments
Β (0)