Skip to content

Commit

Permalink
Fix #400 (inner macro not expanded after hash hash) (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar authored Dec 14, 2024
1 parent 6a6865d commit a853253
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2066,7 +2066,7 @@ namespace simplecpp {
}
TokenList temp(files);
calledMacro.expand(&temp, loc, tokens.cfront(), macros, expandedmacros);
return recursiveExpandToken(output, temp, loc, tok2, macros, expandedmacros2, parametertokens);
return recursiveExpandToken(output, temp, loc, tok2, macros, expandedmacros, parametertokens);
}

if (tok->str() == DEFINED) {
Expand Down
10 changes: 10 additions & 0 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,15 @@ static void define_define_21() // #397 DEBRACKET macro
ASSERT_EQUALS("\n#line 5 \"a.c\"\nB", preprocess(code3));
}

static void define_define_22() // #400 inner macro not expanded after hash hash
{
const char code[] = "#define FOO(a) CAT(DO, STUFF)(1,2)\n"
"#define DOSTUFF(a, b) CAT(3, 4)\n"
"#define CAT(a, b) a##b\n"
"FOO(1)\n";
ASSERT_EQUALS("\n\n\n34", preprocess(code));
}

static void define_va_args_1()
{
const char code[] = "#define A(fmt...) dostuff(fmt)\n"
Expand Down Expand Up @@ -3020,6 +3029,7 @@ int main(int argc, char **argv)
TEST_CASE(define_define_19);
TEST_CASE(define_define_20); // 384 arg contains comma
TEST_CASE(define_define_21);
TEST_CASE(define_define_22); // #400
TEST_CASE(define_va_args_1);
TEST_CASE(define_va_args_2);
TEST_CASE(define_va_args_3);
Expand Down

0 comments on commit a853253

Please sign in to comment.