diff --git a/src/preprocessor.cpp b/src/preprocessor.cpp index 55d81bc68..f19aa80ef 100644 --- a/src/preprocessor.cpp +++ b/src/preprocessor.cpp @@ -403,7 +403,7 @@ std::string Preprocessor::removeComments(const std::string &str) previous = chNext; } } - while (i < str.length() && chNext != ch); + while (i < str.length() && chNext != ch && chNext != '\n'); } diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 4c11e47df..788d33bed 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -136,6 +136,7 @@ private: TEST_CASE(pragma_asm); TEST_CASE(endifsemicolon); TEST_CASE(missing_doublequote); + TEST_CASE(handle_error); TEST_CASE(unicodeInCode); TEST_CASE(unicodeInComment); @@ -1105,6 +1106,35 @@ private: "}\n", actual[""]); } + void handle_error() + { + { + const char filedata[] = "#define A \n" + "#error don't want to \\\n" + "more text\n" + "void f()\n" + "{\n" + " char a = 'a'; // '\n" + "}\n"; + const char expected[] = "\n" + "\n" + "\n" + "void f()\n" + "{\n" + "char a = 'a';\n" + "}\n"; + errout.str(""); + // Preprocess => actual result.. + std::istringstream istr(filedata); + std::map actual; + Preprocessor preprocessor; + preprocessor.preprocess(istr, actual, "file.c"); + + ASSERT_EQUALS(expected, actual[""]); + ASSERT_EQUALS("", errout.str()); + } + } + void missing_doublequote() { {