Skip to content

Commit 91f42e6

Browse files
committed
Temporarily bypass macro expansion during hash expansion (#296)
1 parent eed5b7c commit 91f42e6

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

simplecpp.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2140,7 +2140,8 @@ namespace simplecpp {
21402140
*/
21412141
const Token *expandHash(TokenList *output, const Location &loc, const Token *tok, const MacroMap &macros, const std::set<TokenString> &expandedmacros, const std::vector<const Token*> &parametertokens) const {
21422142
TokenList tokenListHash(files);
2143-
tok = expandToken(&tokenListHash, loc, tok->next, macros, expandedmacros, parametertokens);
2143+
const MacroMap macros2; // temporarily bypass macro expansion
2144+
tok = expandToken(&tokenListHash, loc, tok->next, macros2, expandedmacros, parametertokens);
21442145
std::ostringstream ostr;
21452146
ostr << '\"';
21462147
for (const Token *hashtok = tokenListHash.cfront(); hashtok; hashtok = hashtok->next)

test.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,11 @@ static void hash()
10301030
preprocess("#define A(x) (x)\n"
10311031
"#define B(x) A(#x)\n"
10321032
"B(123)"));
1033+
1034+
ASSERT_EQUALS("\n\nprintf ( \"bar(3)\" \"\\n\" ) ;",
1035+
preprocess("#define bar(x) x % 2\n"
1036+
"#define foo(x) printf(#x \"\\n\")\n"
1037+
"foo(bar(3));"));
10331038
}
10341039

10351040
static void hashhash1() // #4703

0 commit comments

Comments
 (0)