Skip to content

Commit 3eed07b

Browse files
author
William Jakobsson
committed
fix
1 parent cc67864 commit 3eed07b

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

simplecpp.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,8 +771,22 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
771771
ch = stream.readChar();
772772
}
773773
stream.ungetChar();
774+
std::string::size_type pos = 0;
775+
unsigned int spliced = 0;
776+
while ((pos = currentToken.find('\\', pos)) != std::string::npos) {
777+
if (pos + 1 < currentToken.size() && currentToken[pos + 1] == '\n') {
778+
currentToken.erase(pos, 2);
779+
++spliced;
780+
} else if (pos + 2 < currentToken.size() && currentToken[pos + 1] == '\r' && currentToken[pos + 2] == '\n') {
781+
currentToken.erase(pos, 3);
782+
++spliced;
783+
} else {
784+
++pos;
785+
}
786+
}
774787
push_back(new Token(currentToken, location));
775788
location.adjust(currentToken);
789+
location.line += spliced;
776790
continue;
777791
}
778792
}

test.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,19 @@ static void error5()
14231423
ASSERT_EQUALS("file0,1,#error,#error x\n", toString(outputList));
14241424
}
14251425

1426+
static void error6()
1427+
{
1428+
// "#error\<LF>"
1429+
const char code[] = "\xFF\xFE\x23\x00\x65\x00\x72\x00\x72\x00\x6f\x00\x72\x00\x20\x00\x5c\x00\x0a\x00";
1430+
std::vector<std::string> files;
1431+
simplecpp::FileDataCache cache;
1432+
simplecpp::OutputList outputList;
1433+
simplecpp::TokenList tokens2(files);
1434+
const simplecpp::TokenList rawtokens = makeTokenList(code, sizeof(code),files,"test.c");
1435+
simplecpp::preprocess(tokens2, rawtokens, files, cache, simplecpp::DUI(), &outputList);
1436+
ASSERT_EQUALS("file0,1,#error,#error \n", toString(outputList));
1437+
}
1438+
14261439
static void garbage()
14271440
{
14281441
simplecpp::OutputList outputList;
@@ -3933,6 +3946,7 @@ static void runTests(int argc, char **argv, Input input)
39333946
TEST_CASE(error3);
39343947
TEST_CASE(error4);
39353948
TEST_CASE(error5);
3949+
TEST_CASE(error6);
39363950

39373951
TEST_CASE(garbage);
39383952
TEST_CASE(garbage_endif);

0 commit comments

Comments
 (0)