Skip to content

Commit c2b2aa9

Browse files
committed
Fix #397 (Debracket macro not expanded)
1 parent d4323f7 commit c2b2aa9

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

simplecpp.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,13 +2046,20 @@ namespace simplecpp {
20462046
calledMacro.expand(&temp, loc, tok, macros, expandedmacros);
20472047
return recursiveExpandToken(output, temp, loc, tok, macros, expandedmacros2, parametertokens);
20482048
}
2049-
if (!sameline(tok, tok->next) || tok->next->op != '(') {
2049+
if (!sameline(tok, tok->next)) {
20502050
output->push_back(newMacroToken(tok->str(), loc, true, tok));
20512051
return tok->next;
20522052
}
20532053
TokenList tokens(files);
20542054
tokens.push_back(new Token(*tok));
2055-
const Token * const tok2 = appendTokens(&tokens, loc, tok->next, macros, expandedmacros, parametertokens);
2055+
const Token * tok2 = nullptr;
2056+
if (tok->next->op == '(')
2057+
tok2 = appendTokens(&tokens, loc, tok->next, macros, expandedmacros, parametertokens);
2058+
else if (tok->next->name && tok->next->next && tok->next->next->op != '(') {
2059+
expandToken(&tokens, loc, tok->next, macros, expandedmacros2, parametertokens);
2060+
if (tokens.cfront()->next && tokens.cfront()->next->op == '(')
2061+
tok2 = tok->next;
2062+
}
20562063
if (!tok2) {
20572064
output->push_back(newMacroToken(tok->str(), loc, true, tok));
20582065
return tok->next;

test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,14 @@ static void define_define_20() // #384 arg contains comma
821821
ASSERT_EQUALS("\n\n\n\n\n\na = 1", preprocess(code));
822822
}
823823

824+
static void define_define_21() // #397 DEBRACKET macro
825+
{
826+
const char code[] = "#define A(val) B val\n"
827+
"#define B(val) val\n"
828+
"A((2))\n";
829+
ASSERT_EQUALS("\n\n2", preprocess(code));
830+
}
831+
824832
static void define_va_args_1()
825833
{
826834
const char code[] = "#define A(fmt...) dostuff(fmt)\n"
@@ -2999,6 +3007,7 @@ int main(int argc, char **argv)
29993007
TEST_CASE(define_define_18);
30003008
TEST_CASE(define_define_19);
30013009
TEST_CASE(define_define_20); // 384 arg contains comma
3010+
TEST_CASE(define_define_21);
30023011
TEST_CASE(define_va_args_1);
30033012
TEST_CASE(define_va_args_2);
30043013
TEST_CASE(define_va_args_3);

0 commit comments

Comments
 (0)