Skip to content

Commit e1d61e3

Browse files
committed
Add static assert on IS_ENABLED() macro
This patch adds a build-time oracle for IS_ENABLED(). MSVC's legacy preprocessor mis-handles the token-paste + rescan and silently returns 0 for a defined-as-1 flag, disabling every IS_ENABLED-gated feature. Related-to: goToMain/libosdp#289 Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
1 parent 654e73c commit e1d61e3

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/utils.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212

1313
#include <utils/utils.h>
1414

15+
#define _IS_ENABLED_SELFTEST_ON 1
16+
_Static_assert(IS_ENABLED(_IS_ENABLED_SELFTEST_ON) == 1,
17+
"IS_ENABLED(): defined-as-1 flag must evaluate to 1");
18+
_Static_assert(IS_ENABLED(_IS_ENABLED_SELFTEST_OFF) == 0,
19+
"IS_ENABLED(): undefined flag must evaluate to 0");
20+
#undef _IS_ENABLED_SELFTEST_ON
21+
1522
int randint(int limit)
1623
{
1724
int r;

0 commit comments

Comments
 (0)