fix: Work around MSVC __VA_ARGS__ forwarding bug in XRPL_ASSERT_IF

MSVC's legacy preprocessor treats __VA_ARGS__ as a single token when
it is passed as an argument to another function-like macro, causing
ALWAYS_OR_UNREACHABLE to receive one argument instead of two and
triggering C4003. Wrap the inner XRPL_ASSERT call in an identity macro
(XRPL_ASSERT_IF_EXPAND) that forces a rescan, splitting the tokens back
into separate arguments before ALWAYS_OR_UNREACHABLE sees them.
This commit is contained in:
Vito
2026-06-02 12:10:43 +02:00
parent cd04055559
commit 5d187be11a

View File

@@ -22,10 +22,14 @@
#define XRPL_ASSERT_PARTS(cond, function, description, ...) \
XRPL_ASSERT(cond, function " : " description)
// clang-format off
// MSVC's legacy preprocessor treats __VA_ARGS__ as a single token when
// forwarded to another function-like macro. XRPL_ASSERT_IF_EXPAND forces a
// rescan that splits the tokens back into separate arguments.
#define XRPL_ASSERT_IF_EXPAND(x) x
#define XRPL_ASSERT_IF(guard, ...) \
do { \
if ((guard)) \
XRPL_ASSERT(__VA_ARGS__); \
XRPL_ASSERT_IF_EXPAND(XRPL_ASSERT(__VA_ARGS__)); \
} while (false)
// clang-format on