From 62be4c484b1cbc7d4832ae825a9a6d6e5dc73d1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 12 Dec 2024 22:01:06 +0100 Subject: [PATCH] Fix #397 (Debracket macro not expanded) --- simplecpp.cpp | 11 +++++++++-- test.cpp | 6 +++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/simplecpp.cpp b/simplecpp.cpp index 476f42f..f3ac13a 100755 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -2046,13 +2046,20 @@ namespace simplecpp { calledMacro.expand(&temp, loc, tok, macros, expandedmacros); return recursiveExpandToken(output, temp, loc, tok, macros, expandedmacros2, parametertokens); } - if (!sameline(tok, tok->next) || tok->next->op != '(') { + if (!sameline(tok, tok->next)) { output->push_back(newMacroToken(tok->str(), loc, true, tok)); return tok->next; } TokenList tokens(files); tokens.push_back(new Token(*tok)); - const Token * const tok2 = appendTokens(&tokens, loc, tok->next, macros, expandedmacros, parametertokens); + const Token * tok2 = nullptr; + if (tok->next->op == '(') + tok2 = appendTokens(&tokens, loc, tok->next, macros, expandedmacros, parametertokens); + else if (tok->next->name && tok->next->next && tok->next->next->op != '(') { + expandToken(&tokens, loc, tok->next, macros, expandedmacros2, parametertokens); + if (tokens.cfront()->next && tokens.cfront()->next->op == '(') + tok2 = tok->next; + } if (!tok2) { output->push_back(newMacroToken(tok->str(), loc, true, tok)); return tok->next; diff --git a/test.cpp b/test.cpp index afa93a8..daa31b6 100644 --- a/test.cpp +++ b/test.cpp @@ -823,9 +823,9 @@ static void define_define_20() // #384 arg contains comma static void define_define_21() // #397 DEBRACKET macro { - const char code[] = "#define A(ignore_this, val, ...) DEBRACKET val\n" - "#define DEBRACKET(...) __VA_ARGS__\n" - "A(_ , (2))\n"; + const char code[] = "#define A(val) B val\n" + "#define B(val) val\n" + "A((2))\n"; ASSERT_EQUALS("\n\n2", preprocess(code)); }