From 4c0d70ab07b4a5a5040e53259f8e9cedd4ec89b2 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Mon, 16 Apr 2012 00:21:40 +0200 Subject: [PATCH 6/9] Fix parsing function macro invocations If a function macro name is separated from the parentheses in an macro invocation the substitution doesn't take place. Fix this by handling comments. --- tccpp.c | 21 ++++++++++++++++++--- tests/tcctest.c | 4 ++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/tccpp.c b/tccpp.c index f3dd232..aff5a53 100644 --- a/tccpp.c +++ b/tccpp.c @@ -2697,10 +2697,25 @@ static int macro_subst_tok(TokenString *tok_str, goto redo; } } else { - /* XXX: incorrect with comments */ ch = file->buf_ptr[0]; - while (is_space(ch) || ch == '\n') - cinp(); + while (is_space(ch) || ch == '\n' || ch == '/') + { + if (ch == '/') + { + int c; + uint8_t *p = file->buf_ptr; + PEEKC(c, p); + if (c == '*') { + p = parse_comment(p); + file->buf_ptr = p - 1; + } else if (c == '/') { + p = parse_line_comment(p); + file->buf_ptr = p - 1; + } else + break; + } + cinp(); + } t = ch; } if (t != '(') /* no macro subst */ diff --git a/tests/tcctest.c b/tests/tcctest.c index eee7039..eeabb7c 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -288,6 +288,10 @@ comment /* test function macro substitution when the function name is substituted */ TEST2(); + + /* And again when the name and parenthes are separated by a + comment. */ + TEST2 /* the comment */ (); } -- 1.7.3.4