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:
parent
7b58e09a07
commit
d8f6636673
|
@ -801,6 +801,17 @@ std::string Preprocessor::expandMacros(std::string code, const std::string &file
|
||||||
// End of line/file was reached without finding pair
|
// End of line/file was reached without finding pair
|
||||||
if (pos1 >= code.size() || code[pos1] == '\n')
|
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)
|
if (errorLogger)
|
||||||
{
|
{
|
||||||
std::string fname(filename);
|
std::string fname(filename);
|
||||||
|
|
|
@ -849,6 +849,19 @@ private:
|
||||||
ASSERT_EQUALS("", actual);
|
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());
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue