Skip to content

Commit d6fcb8c

Browse files
committed
Implement GCC extended semantics of __VA_ARGS__
1 parent e6760ab commit d6fcb8c

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/parser/cxx/preprocessor.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,6 +2355,22 @@ auto Preprocessor::Private::substitute(TokList *pointOfSubstitution,
23552355
continue;
23562356
}
23572357

2358+
if (lookat(ts, TokenKind::T_COMMA, TokenKind::T_HASH_HASH, "__VA_ARGS__")) {
2359+
auto comma = ts->tok;
2360+
ts = ts->next->next;
2361+
2362+
if (auto actual = lookupMacroArgument(ts, macro, actuals)) {
2363+
auto [startArg, endArg] = *actual;
2364+
if (startArg != endArg) {
2365+
appendToken(comma);
2366+
for (auto it = startArg; it != endArg; ++it) {
2367+
appendToken(&*it);
2368+
}
2369+
}
2370+
continue;
2371+
}
2372+
}
2373+
23582374
if (lookat(ts, TokenKind::T_IDENTIFIER, TokenKind::T_HASH_HASH)) {
23592375
if (auto actual = lookupMacroArgument(ts, macro, actuals)) {
23602376
auto [startArg, endArg] = *actual;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %cxx -E -P %s -o - | %filecheck %s
2+
3+
#define X(a, ...) static_assert(a, ## __VA_ARGS__)
4+
5+
static_assert(true);
6+
static_assert(true, "it must be true");
7+
8+
// CHECK: static_assert(true);
9+
// CHECK-NEXT: static_assert(true, "it must be true");
10+

0 commit comments

Comments
 (0)