Fix ticket #316 (\n is tokenized into \\ in a string when macro is used)

http://apps.sourceforge.net/trac/cppcheck/ticket/316
This commit is contained in:
Reijo Tomperi 2009-05-20 21:36:59 +03:00
parent 9c60391375
commit bb2b2e000b
2 changed files with 22 additions and 5 deletions

View File

@ -1130,11 +1130,6 @@ std::string Preprocessor::expandMacros(std::string code, const std::string &file
while (pos2 < code.length() && code[pos2] != ch)
{
par += code[pos2];
if (code[pos2] == '\\')
{
par += code[pos2];
++pos2;
}
++pos2;
}
if (pos2 == code.length())

View File

@ -125,6 +125,7 @@ private:
TEST_CASE(conditionalDefine);
TEST_CASE(multiline_comment);
TEST_CASE(macro_parameters);
TEST_CASE(newline_in_macro);
}
@ -1046,6 +1047,27 @@ private:
ASSERT_EQUALS("[file.c:6]: (error) Syntax error. Not enough parameters for macro 'BC'.\n", errout.str());
}
void newline_in_macro()
{
errout.str("");
const char filedata[] = "#define ABC(str) printf( str )\n"
"void f()\n"
"{\n"
" ABC(\"\\n\");\n"
"}\n";
// Preprocess => actual result..
std::istringstream istr(filedata);
std::map<std::string, std::string> actual;
Preprocessor preprocessor;
preprocessor.preprocess(istr, actual, "file.c", std::list<std::string>(), this);
// Compare results..
ASSERT_EQUALS(1, static_cast<unsigned int>(actual.size()));
ASSERT_EQUALS("\nvoid f()\n{\nprintf(\"\\n\");\n}\n", actual[""]);
ASSERT_EQUALS("", errout.str());
}
};