mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-03 00:36:48 +00:00
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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user