Improve fix to ticket #261: Allow macro definition to have uncoupled double quote.

http://apps.sourceforge.net/trac/cppcheck/ticket/261
This commit is contained in:
Reijo Tomperi 2009-04-26 22:19:08 +03:00
parent 7b58e09a07
commit d8f6636673
2 changed files with 24 additions and 0 deletions

View File

@ -801,6 +801,17 @@ std::string Preprocessor::expandMacros(std::string code, const std::string &file
// End of line/file was reached without finding pair
if (pos1 >= code.size() || code[pos1] == '\n')
{
std::string::size_type lineStart = code.rfind('\n', pos1 - 1);
if (lineStart != std::string::npos)
{
if (code.substr(lineStart + 1, 7) == "#define")
{
// There is nothing wrong #define containing quote without
// a pair.
continue;
}
}
if (errorLogger)
{
std::string fname(filename);

View File

@ -849,6 +849,19 @@ private:
ASSERT_EQUALS("", actual);
ASSERT_EQUALS("[abc.h:2]: (error) No pair for character (\"). Can't process file. File is either invalid or unicode, which is currently not supported.\n", errout.str());
}
{
const char filedata[] = "#define A 1\n"
"#define B \"\n"
"int a = A;\n";
// expand macros..
errout.str("");
const std::string actual(OurPreprocessor::expandMacros(filedata, this));
ASSERT_EQUALS("\n\nint a = 1;\n", actual);
ASSERT_EQUALS("", errout.str());
}
}
};