fix ticket #586 (Preprocessor: Lines like "#error don't" can cause "no pair for character" errors)
http://sourceforge.net/apps/trac/cppcheck/ticket/586
This commit is contained in:
parent
51365c4b9d
commit
c8da301f83
|
@ -403,7 +403,7 @@ std::string Preprocessor::removeComments(const std::string &str)
|
|||
previous = chNext;
|
||||
}
|
||||
}
|
||||
while (i < str.length() && chNext != ch);
|
||||
while (i < str.length() && chNext != ch && chNext != '\n');
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -136,6 +136,7 @@ private:
|
|||
TEST_CASE(pragma_asm);
|
||||
TEST_CASE(endifsemicolon);
|
||||
TEST_CASE(missing_doublequote);
|
||||
TEST_CASE(handle_error);
|
||||
|
||||
TEST_CASE(unicodeInCode);
|
||||
TEST_CASE(unicodeInComment);
|
||||
|
@ -1105,6 +1106,35 @@ private:
|
|||
"}\n", actual[""]);
|
||||
}
|
||||
|
||||
void handle_error()
|
||||
{
|
||||
{
|
||||
const char filedata[] = "#define A \n"
|
||||
"#error don't want to \\\n"
|
||||
"more text\n"
|
||||
"void f()\n"
|
||||
"{\n"
|
||||
" char a = 'a'; // '\n"
|
||||
"}\n";
|
||||
const char expected[] = "\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"void f()\n"
|
||||
"{\n"
|
||||
"char a = 'a';\n"
|
||||
"}\n";
|
||||
errout.str("");
|
||||
// Preprocess => actual result..
|
||||
std::istringstream istr(filedata);
|
||||
std::map<std::string, std::string> actual;
|
||||
Preprocessor preprocessor;
|
||||
preprocessor.preprocess(istr, actual, "file.c");
|
||||
|
||||
ASSERT_EQUALS(expected, actual[""]);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
}
|
||||
|
||||
void missing_doublequote()
|
||||
{
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue