diff --git a/simplecpp.cpp b/simplecpp.cpp index 476f42f..050a5d0 100755 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -2046,13 +2046,19 @@ 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 (expandArg(&tokens, tok->next, loc, macros, expandedmacros, 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 0f7ebe7..bf83763 100644 --- a/test.cpp +++ b/test.cpp @@ -821,6 +821,20 @@ static void define_define_20() // #384 arg contains comma ASSERT_EQUALS("\n\n\n\n\n\na = 1", preprocess(code)); } +static void define_define_21() // #397 DEBRACKET macro +{ + const char code1[] = "#define A(val) B val\n" + "#define B(val) val\n" + "A((2))\n"; + ASSERT_EQUALS("\n\n2", preprocess(code1)); + + const char code2[] = "#define x (2)\n" + "#define A B x\n" + "#define B(val) val\n" + "A\n"; + ASSERT_EQUALS("\n\n\nB ( 2 )", preprocess(code2)); +} + static void define_va_args_1() { const char code[] = "#define A(fmt...) dostuff(fmt)\n" @@ -2999,6 +3013,7 @@ int main(int argc, char **argv) TEST_CASE(define_define_18); TEST_CASE(define_define_19); TEST_CASE(define_define_20); // 384 arg contains comma + TEST_CASE(define_define_21); TEST_CASE(define_va_args_1); TEST_CASE(define_va_args_2); TEST_CASE(define_va_args_3);