Fix ticket #302 (White space between "\" and newline not handled correctly)
http://apps.sourceforge.net/trac/cppcheck/ticket/302
This commit is contained in:
parent
15bbd4613e
commit
fede702bf5
|
@ -159,7 +159,21 @@ std::string Preprocessor::read(std::istream &istr)
|
|||
// <backspace><newline>..
|
||||
else if (ch == '\\')
|
||||
{
|
||||
char chNext = (char)istr.peek();
|
||||
char chNext = 0;
|
||||
while (true)
|
||||
{
|
||||
chNext = (char)istr.peek();
|
||||
if (chNext != '\n' && chNext != '\r' &&
|
||||
(std::isspace(chNext) || std::iscntrl(chNext)))
|
||||
{
|
||||
// Skip whitespace between <backspace> and <newline>
|
||||
(void)readChar(istr);
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (chNext == '\n' || chNext == '\r')
|
||||
{
|
||||
++newlines;
|
||||
|
|
|
@ -86,6 +86,7 @@ private:
|
|||
TEST_CASE(multiline1);
|
||||
TEST_CASE(multiline2);
|
||||
TEST_CASE(multiline3);
|
||||
TEST_CASE(multiline4);
|
||||
|
||||
TEST_CASE(if_defined); // "#if defined(AAA)" => "#ifdef AAA"
|
||||
|
||||
|
@ -516,7 +517,24 @@ private:
|
|||
ASSERT_EQUALS("const char *str = \"abcdefghi\"\n\n\n", preprocessor.read(istr));
|
||||
}
|
||||
|
||||
void multiline4()
|
||||
{
|
||||
errout.str("");
|
||||
const char filedata[] = "#define A int a = 4;\\ \n"
|
||||
" int b = 5;\n"
|
||||
"A\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 a = 4; int b = 5;\n", actual[""]);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void if_defined()
|
||||
{
|
||||
|
@ -892,6 +910,7 @@ private:
|
|||
|
||||
void define_part_of_func()
|
||||
{
|
||||
errout.str("");
|
||||
const char filedata[] = "#define A g(\n"
|
||||
"void f() {\n"
|
||||
" A );\n"
|
||||
|
|
Loading…
Reference in New Issue