refactor: Simplify XRPL_ASSERT_IF to fixed 3-parameter form

The __VA_ARGS__ approach required an MSVC-specific EXPAND workaround.
Switch back to explicit (guard, cond, message) parameters and document
the bare-comma restriction on cond instead.
This commit is contained in:
Vito
2026-06-02 12:58:00 +02:00
parent 5d187be11a
commit f9f07704d2

View File

@@ -22,14 +22,12 @@
#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_IF_EXPAND(XRPL_ASSERT(__VA_ARGS__)); \
// NOTE: cond must not contain bare commas outside () or []. Commas inside {}
// are not protected by the preprocessor and would be parsed as extra arguments.
#define XRPL_ASSERT_IF(guard, cond, message) \
do { \
if ((guard)) \
XRPL_ASSERT(cond, message); \
} while (false)
// clang-format on