Skip to content

Commit dd3d097

Browse files
committed
Fix hashhash bug when there is null statement on the next line
1 parent a4964e8 commit dd3d097

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

simplecpp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2132,7 +2132,7 @@ namespace simplecpp {
21322132
for (Token *b = tokensB.front(); b; b = b->next)
21332133
b->location = loc;
21342134
output->takeTokens(tokensB);
2135-
} else if (nextTok->op == '#' && nextTok->next->op == '#') {
2135+
} else if (sameline(B, nextTok) && sameline(B, nextTok->next) && nextTok->op == '#' && nextTok->next->op == '#') {
21362136
TokenList output2(files);
21372137
output2.push_back(new Token(strAB, tok->location));
21382138
nextTok = expandHashHash(&output2, loc, nextTok, macros, expandedmacros, parametertokens);

test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,18 @@ static void hashhash_invalid_missing_args()
12071207
ASSERT_EQUALS("file0,1,syntax_error,failed to expand 'BAD', Invalid ## usage when expanding 'BAD': Missing first argument\n", toString(outputList));
12081208
}
12091209

1210+
static void hashhash_null_stmt()
1211+
{
1212+
const char code[] =
1213+
"# define B(x) C ## x\n"
1214+
"#\n"
1215+
"# define C0 1\n"
1216+
"\n"
1217+
"B(0);\n";
1218+
simplecpp::OutputList outputList;
1219+
ASSERT_EQUALS("\n\n\n\n1 ;", preprocess(code, &outputList));
1220+
}
1221+
12101222
static void hashhash_universal_character()
12111223
{
12121224
const char code[] =
@@ -2636,6 +2648,7 @@ int main(int argc, char **argv)
26362648
TEST_CASE(hashhash_invalid_2);
26372649
TEST_CASE(hashhash_invalid_string_number);
26382650
TEST_CASE(hashhash_invalid_missing_args);
2651+
TEST_CASE(hashhash_null_stmt);
26392652
// C standard, 5.1.1.2, paragraph 4:
26402653
// If a character sequence that matches the syntax of a universal
26412654
// character name is produced by token concatenation (6.10.3.3),

0 commit comments

Comments
 (0)