Fixed #4351 (Escaped whitespace gives wrong error)

This commit is contained in:
Daniel Marjamäki 2012-12-02 18:04:19 +01:00
parent 94930c3bd7
commit cb06d07ae7
2 changed files with 14 additions and 2 deletions

View File

@ -153,9 +153,11 @@ std::string Preprocessor::read(std::istream &istr, const std::string &filename)
if (ch == '\\') { if (ch == '\\') {
unsigned char chNext; unsigned char chNext;
unsigned int spaces = 0;
#ifdef __GNUC__ #ifdef __GNUC__
// gcc-compatibility: ignore spaces // gcc-compatibility: ignore spaces
for (;;) { for (;; spaces++) {
chNext = (unsigned char)istr.peek(); chNext = (unsigned char)istr.peek();
if (chNext != '\n' && chNext != '\r' && if (chNext != '\n' && chNext != '\r' &&
(std::isspace(chNext) || std::iscntrl(chNext))) { (std::isspace(chNext) || std::iscntrl(chNext))) {
@ -174,7 +176,7 @@ std::string Preprocessor::read(std::istream &istr, const std::string &filename)
++newlines; ++newlines;
(void)readChar(istr,bom); // Skip the "<backslash><newline>" (void)readChar(istr,bom); // Skip the "<backslash><newline>"
} else } else
code << "\\"; code << "\\" << (spaces?" ":"");
} else { } else {
code << char(ch); code << char(ch);

View File

@ -68,6 +68,7 @@ private:
TEST_CASE(readCode1); TEST_CASE(readCode1);
TEST_CASE(readCode2); // #4308 - convert C++11 raw string to plain old C string TEST_CASE(readCode2); // #4308 - convert C++11 raw string to plain old C string
TEST_CASE(readCode3); TEST_CASE(readCode3);
TEST_CASE(readCode4); // #4351 - escaped whitespace in gcc
// reading utf-16 file // reading utf-16 file
TEST_CASE(utf16); TEST_CASE(utf16);
@ -315,6 +316,15 @@ private:
ASSERT_EQUALS("func(#errorname)", codestr); ASSERT_EQUALS("func(#errorname)", codestr);
} }
void readCode4() {
const char code[] = "char c = '\\ ';";
Settings settings;
Preprocessor preprocessor(&settings, this);
std::istringstream istr(code);
ASSERT_EQUALS("char c = '\\ ';", preprocessor.read(istr,"test.c"));
ASSERT_EQUALS("", errout.str());
}
void utf16() { void utf16() {
Settings settings; Settings settings;