From c8da301f830297dc46dbe37bcdbf595ba81458bf Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Fri, 14 Aug 2009 00:22:51 +0300 Subject: [PATCH] fix ticket #586 (Preprocessor: Lines like "#error don't" can cause "no pair for character" errors) http://sourceforge.net/apps/trac/cppcheck/ticket/586 --- src/preprocessor.cpp | 2 +- test/testpreprocessor.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) 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() { {