Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,21 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
ch = stream.readChar();
}
stream.ungetChar();
push_back(new Token(currentToken, location));
location.adjust(currentToken);
std::string::size_type pos = 0;
unsigned int spliced = 0;
while ((pos = currentToken.find('\\', pos)) != std::string::npos) {
if (pos + 1 < currentToken.size() && currentToken[pos + 1] == '\n') {
Comment thread
danmar marked this conversation as resolved.
currentToken.erase(pos, 2);
++spliced;
} else {
++pos;
}
}
if (!currentToken.empty()) {
push_back(new Token(currentToken, location));
location.adjust(currentToken);
}
location.line += spliced;
continue;
}
}
Expand Down
40 changes: 40 additions & 0 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,43 @@ static void error5()
ASSERT_EQUALS("file0,1,#error,#error x\n", toString(outputList));
}

static void error6()
{
// "#error\<LF>"
const char code[] = "\xFF\xFE\x23\x00\x65\x00\x72\x00\x72\x00\x6f\x00\x72\x00\x20\x00\x5c\x00\x0a\x00";
std::vector<std::string> files;
simplecpp::FileDataCache cache;
simplecpp::OutputList outputList;
simplecpp::TokenList tokens2(files);
const simplecpp::TokenList rawtokens = makeTokenList(code, sizeof(code),files,"test.c");
simplecpp::preprocess(tokens2, rawtokens, files, cache, simplecpp::DUI(), &outputList);
ASSERT_EQUALS("file0,1,#error,#error \n", toString(outputList));
}

static void error7()
{
const char code[] = "#error bla\\\nbla\n";
std::vector<std::string> files;
simplecpp::FileDataCache cache;
simplecpp::OutputList outputList;
simplecpp::TokenList tokens2(files);
const simplecpp::TokenList rawtokens = makeTokenList(code, sizeof(code),files,"test.c");
simplecpp::preprocess(tokens2, rawtokens, files, cache, simplecpp::DUI(), &outputList);
ASSERT_EQUALS("file0,1,#error,#error blabla\n", toString(outputList));
}

static void error8()
{
const char code[] = "#error bla\\\r\nbla\n";
std::vector<std::string> files;
simplecpp::FileDataCache cache;
simplecpp::OutputList outputList;
simplecpp::TokenList tokens2(files);
const simplecpp::TokenList rawtokens = makeTokenList(code, sizeof(code),files,"test.c");
simplecpp::preprocess(tokens2, rawtokens, files, cache, simplecpp::DUI(), &outputList);
ASSERT_EQUALS("file0,1,#error,#error blabla\n", toString(outputList));
}

static void garbage()
{
simplecpp::OutputList outputList;
Expand Down Expand Up @@ -3933,6 +3970,9 @@ static void runTests(int argc, char **argv, Input input)
TEST_CASE(error3);
TEST_CASE(error4);
TEST_CASE(error5);
TEST_CASE(error6);
TEST_CASE(error7);
TEST_CASE(error8);

TEST_CASE(garbage);
TEST_CASE(garbage_endif);
Expand Down
Loading