Fix ticket #598 (Preprocessor: Multiline comments add line change to wrong location)

http://sourceforge.net/apps/trac/cppcheck/ticket/598
This commit is contained in:
Reijo Tomperi 2009-08-20 00:27:47 +03:00
parent 8b46172bcf
commit 7d44ce7736
2 changed files with 23 additions and 2 deletions

View File

@ -368,8 +368,7 @@ std::string Preprocessor::removeComments(const std::string &str)
ch = str[i];
if (ch == '\n')
{
code << "\n";
previous = '\n';
++newlines;
++lineno;
}
}

View File

@ -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<std::string, std::string> actual;
Preprocessor preprocessor;
preprocessor.preprocess(istr, actual, "file.c");
// Compare results..
ASSERT_EQUALS(1, static_cast<unsigned int>(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"