Skip to content

Commit d0f2b99

Browse files
authored
Fix #471 (preserve line splicing information in '// ..' comments) (#472)
1 parent 29abbc6 commit d0f2b99

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

simplecpp.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,12 +775,13 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
775775
if(tmp_ch != '\n') {
776776
currentToken += tmp;
777777
} else {
778-
TokenString check_portability = currentToken + tmp;
778+
const TokenString check_portability = currentToken + tmp;
779779
const std::string::size_type pos = check_portability.find_last_not_of(" \t");
780780
if (pos < check_portability.size() - 1U && check_portability[pos] == '\\')
781781
portabilityBackslash(outputList, files, location);
782782
++multiline;
783783
tmp_ch = stream.readChar();
784+
currentToken += '\n';
784785
}
785786
ch = tmp_ch;
786787
}

test.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,9 @@ static void comment_multiline()
458458

459459
const char code6[] = "void f() {// \\\n\n\n}\n";
460460
ASSERT_EQUALS("void f ( ) {\n\n\n}", preprocess(code6));
461+
462+
// #471 ensure there is newline in comment so that line-splicing can be detected by tools
463+
ASSERT_EQUALS("// abc\ndef", readfile("// abc\\\ndef"));
461464
}
462465

463466

0 commit comments

Comments
 (0)