From 86f3d8e33105435946383aee52487b5ddf918140 Mon Sep 17 00:00:00 2001 From: grischka Date: Fri, 7 Apr 2023 00:45:20 +0200 Subject: [PATCH] tccpp: remove unwanted space with __VA_ARGS__ reported by "vsfos" https://lists.gnu.org/archive/html/tinycc-devel/2023-04/msg00007.html --- tccpp.c | 8 ++++---- tests/pp/11.c | 5 +++++ tests/pp/11.expect | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tccpp.c b/tccpp.c index 64de770f..cef93826 100644 --- a/tccpp.c +++ b/tccpp.c @@ -2985,7 +2985,6 @@ static int *macro_arg_subst(Sym **nested_list, const int *macro_str, Sym *args) } else if (t >= TOK_IDENT) { s = sym_find2(args, t); if (s) { - int l0 = str.len; st = s->d; /* if '##' is present before or after, no arg substitution */ if (*macro_str == TOK_PPJOIN || t1 == TOK_PPJOIN) { @@ -3017,15 +3016,16 @@ static int *macro_arg_subst(Sym **nested_list, const int *macro_str, Sym *args) } st = s->next->d; } - for(;;) { + if (*st <= 0) { + /* expanded to empty string */ + tok_str_add(&str, TOK_PLCHLDR); + } else for (;;) { int t2; TOK_GET(&t2, &st, &cval); if (t2 <= 0) break; tok_str_add2(&str, t2, &cval); } - if (str.len == l0) /* expanded to empty string */ - tok_str_add(&str, TOK_PLCHLDR); } else { tok_str_add(&str, t); } diff --git a/tests/pp/11.c b/tests/pp/11.c index c0edf629..5ce868b1 100644 --- a/tests/pp/11.c +++ b/tests/pp/11.c @@ -29,3 +29,8 @@ __NORETURN #define X(...) #define Y(...) 1 __VA_ARGS__ 2 Y(X X() ()) + +#define DDD(A, B) D_ ## B ## _D_ ## A +#define CCC(X, ...) DDD(X, ##__VA_ARGS__) +/* must be D_B_D_A (not D_B _D_A) */ +CCC(A,B) diff --git a/tests/pp/11.expect b/tests/pp/11.expect index 6b9806c6..bb5d6b78 100644 --- a/tests/pp/11.expect +++ b/tests/pp/11.expect @@ -13,3 +13,4 @@ x A y x y __attribute__((__noreturn__)) 1 2 +D_B_D_A