From 7971eec3ccf05719fb497ee026c0ecc610819865 Mon Sep 17 00:00:00 2001 From: acqn Date: Sun, 7 Aug 2022 12:45:48 +0800 Subject: [PATCH] Fixed parentheses handling when a function-like macro name itself is used as an macro argument. --- src/cc65/preproc.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/cc65/preproc.c b/src/cc65/preproc.c index d33bef34c..3fd994e80 100644 --- a/src/cc65/preproc.c +++ b/src/cc65/preproc.c @@ -1142,17 +1142,27 @@ static void MacroReplacement (StrBuf* Source, StrBuf* Target, int MultiLine) if (Whitespace > 0) { SB_AppendChar (Target, ' '); } - if (CurC == '#') { - if (OLine == 0) { - OLine = Target; - ParseDirectives (0); - OLine = 0; - } else { - ParseDirectives (0); + + /* Directives can only be found in an argument list + ** that spans multiple lines. + */ + if (MultiLine) { + if (CurC == '#') { + /* If we were going to support #pragma in + ** macro argument list, it would be output + ** to OLine. + */ + if (OLine == 0) { + OLine = Target; + ParseDirectives (0); + OLine = 0; + } else { + ParseDirectives (0); + } } + /* Add the source info to preprocessor output if needed */ + AddPreLine (Target); } - /* Add the source info to preprocessor output if needed */ - AddPreLine (Target); } else { /* Function-like macro */ if (OLine == 0) {