diff --git a/src/parser/cxx/preprocessor.cc b/src/parser/cxx/preprocessor.cc index aaa4dbbf..fdf06e51 100644 --- a/src/parser/cxx/preprocessor.cc +++ b/src/parser/cxx/preprocessor.cc @@ -2355,6 +2355,22 @@ auto Preprocessor::Private::substitute(TokList *pointOfSubstitution, continue; } + if (lookat(ts, TokenKind::T_COMMA, TokenKind::T_HASH_HASH, "__VA_ARGS__")) { + auto comma = ts->tok; + ts = ts->next->next; + + if (auto actual = lookupMacroArgument(ts, macro, actuals)) { + auto [startArg, endArg] = *actual; + if (startArg != endArg) { + appendToken(comma); + for (auto it = startArg; it != endArg; ++it) { + appendToken(&*it); + } + } + continue; + } + } + if (lookat(ts, TokenKind::T_IDENTIFIER, TokenKind::T_HASH_HASH)) { if (auto actual = lookupMacroArgument(ts, macro, actuals)) { auto [startArg, endArg] = *actual; diff --git a/tests/unit_tests/preprocessor/va_args_003.cc b/tests/unit_tests/preprocessor/va_args_003.cc new file mode 100644 index 00000000..b54270dc --- /dev/null +++ b/tests/unit_tests/preprocessor/va_args_003.cc @@ -0,0 +1,10 @@ +// RUN: %cxx -E -P %s -o - | %filecheck %s + +#define X(a, ...) static_assert(a, ## __VA_ARGS__) + +static_assert(true); +static_assert(true, "it must be true"); + +// CHECK: static_assert(true); +// CHECK-NEXT: static_assert(true, "it must be true"); +