From 5d187be11a76ffa23e0f831d315066c40d7bd01b Mon Sep 17 00:00:00 2001 From: Vito <5780819+Tapanito@users.noreply.github.com> Date: Tue, 2 Jun 2026 12:10:43 +0200 Subject: [PATCH] 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. --- include/xrpl/beast/utility/instrumentation.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/xrpl/beast/utility/instrumentation.h b/include/xrpl/beast/utility/instrumentation.h index 9d84ccaeff..afc36e7842 100644 --- a/include/xrpl/beast/utility/instrumentation.h +++ b/include/xrpl/beast/utility/instrumentation.h @@ -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