From 7d44ce7736933c551f08400e9c8120907390e39e Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Thu, 20 Aug 2009 00:27:47 +0300 Subject: [PATCH] Fix ticket #598 (Preprocessor: Multiline comments add line change to wrong location) http://sourceforge.net/apps/trac/cppcheck/ticket/598 --- src/preprocessor.cpp | 3 +-- test/testpreprocessor.cpp | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/preprocessor.cpp b/src/preprocessor.cpp index dc8d77392..5803bda4e 100644 --- a/src/preprocessor.cpp +++ b/src/preprocessor.cpp @@ -368,8 +368,7 @@ std::string Preprocessor::removeComments(const std::string &str) ch = str[i]; if (ch == '\n') { - code << "\n"; - previous = '\n'; + ++newlines; ++lineno; } } diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 788d33bed..6687f2453 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -98,6 +98,7 @@ private: TEST_CASE(multiline2); TEST_CASE(multiline3); TEST_CASE(multiline4); + TEST_CASE(multiline5); TEST_CASE(if_defined); // "#if defined(AAA)" => "#ifdef AAA" TEST_CASE(if_not_defined); // "#if !defined(AAA)" => "#ifndef AAA" @@ -718,6 +719,27 @@ private: ASSERT_EQUALS("", errout.str()); } + void multiline5() + { + errout.str(""); + const char filedata[] = "#define ABC int a /*\n" + "*/= 4;\n" + "int main(){\n" + "ABC\n" + "}\n"; + + // Preprocess => actual result.. + std::istringstream istr(filedata); + std::map actual; + Preprocessor preprocessor; + preprocessor.preprocess(istr, actual, "file.c"); + + // Compare results.. + ASSERT_EQUALS(1, static_cast(actual.size())); + ASSERT_EQUALS("\n\nint main(){\nint a = 4;\n}\n", actual[""]); + ASSERT_EQUALS("", errout.str()); + } + void if_defined() { const char filedata[] = "#if defined(AAA)\n"