From 0378168c1318352bf13f24f210a23aa2fbeb1895 Mon Sep 17 00:00:00 2001 From: herman ten brugge Date: Tue, 4 May 2021 11:22:11 +0200 Subject: [PATCH] Fix macro processing The code: printf("%d\n", CALL(CONST)); did not work because we did not check for TOK_PLCHLDR. --- tccpp.c | 3 ++- tests/tcctest.c | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tccpp.c b/tccpp.c index a72f29e5..815ffe46 100644 --- a/tccpp.c +++ b/tccpp.c @@ -3424,7 +3424,8 @@ static int macro_subst_tok( for(;;) { do { next_argstream(nested_list, NULL); - } while (is_space(tok) || TOK_LINEFEED == tok); + } while (tok == TOK_PLCHLDR || is_space(tok) || + TOK_LINEFEED == tok); empty_arg: /* handle '()' case */ if (!args && !sa && tok == ')') diff --git a/tests/tcctest.c b/tests/tcctest.c index eef1c4a2..e58a97fc 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -115,6 +115,9 @@ static int onetwothree = 123; #define MACRO_NOARGS() +#define TEST_CALL(f, ...) f(__VA_ARGS__) +#define TEST_CONST() 123 + #define AAA 3 #undef AAA #define AAA 4 @@ -223,6 +226,8 @@ void macro_test(void) MACRO_NOARGS(); + printf("%d\n", TEST_CALL(TEST_CONST)); + /* not strictly preprocessor, but we test it there */ #ifdef C99_MACROS printf("__func__ = %s\n", __func__);