diff options
| author | 2026-03-01 13:35:45 +0100 | |
|---|---|---|
| committer | 2026-03-01 18:31:02 +0100 | |
| commit | a498f851ef2f50c9b8ac47e238137af52b54057d (patch) | |
| tree | 371e4ef6a36358b0637ab97397926fdd8931ea41 /c/lex.c | |
| parent | 1ebf3669f92e7ea0cf9ef97e4d61ee24db2f0b6a (diff) | |
cpp: fix token spacing edge case when empty macros are involved
Diffstat (limited to 'c/lex.c')
| -rw-r--r-- | c/lex.c | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -1214,8 +1214,10 @@ expandfnmacro(struct lexer *lx, struct span *span, internstr mname, struct macro arg->idx2 = argsbuf.n; arg->nfirstx = arg->nlastx = 1; int ilastx = -1; - for (;;) { + for (bool pad = 0;;) { + struct macrostack *sprev = lx->macstk; if (!advancemacstk(lx, &tk)) { + pad |= tk.space && lx->macstk == sprev; /* preserve whitespace empty macro */ if (lx->macstk == l && l->idx == 1) arg->nfirstx = argsbuf.n - arg->idx2; if (lx->macstk == l+1 && lx->macstk->idx == 0 && l->idx == l->rl.n) @@ -1224,8 +1226,10 @@ expandfnmacro(struct lexer *lx, struct span *span, internstr mname, struct macro } if (tk.t == TKEOF) break; size_t off = l->rl.p - argsbuf.p; + tk.space |= pad; vpush(&argsbuf, tk); l->rl.p = argsbuf.p + off; + pad = 0; } arg->n2 = argsbuf.n - arg->idx2; arg->nlastx = ilastx < 0 ? 1 : args->n2 - ilastx; |