Make syntaxError suppressable (fixes #5917 and #7076)

syntaxErrors were not suppressable, because they were treated as
InternalErrors which were thrown and catched during the checking,
and normal suppression rules were not applied for those.

We fix this by calling the normal reportErr() function that does
suppression matching.
This commit is contained in:
Miika-Petteri Matikainen 2015-10-28 20:27:05 +02:00
parent 963008089d
commit acd8a092f8
2 changed files with 27 additions and 1 deletions

View File

@ -426,7 +426,7 @@ bool CppCheck::checkFile(const std::string &code, const char FileName[], std::se
e.id,
false);
_errorLogger.reportErr(errmsg);
reportErr(errmsg);
}
return true;
}

View File

@ -46,6 +46,8 @@ private:
TEST_CASE(inlinesuppress_unusedFunction); // #4210 - unusedFunction
TEST_CASE(globalsuppress_unusedFunction); // #4946
TEST_CASE(suppressionWithRelativePaths); // #4733
TEST_CASE(suppressingSyntaxErrors); // #7076
TEST_CASE(suppressingSyntaxErrorsInline); // #5917
}
void suppressionsBadId1() const {
@ -384,6 +386,30 @@ private:
cppCheck.check("/somewhere/test.cpp", code);
ASSERT_EQUALS("",errout.str());
}
void suppressingSyntaxErrors() { // syntaxErrors should be suppressable (#7076)
std::map<std::string, std::string> files;
files["test.cpp"] = "if if\n";
checkSuppression(files, "syntaxError:test.cpp:1");
ASSERT_EQUALS("", errout.str());
}
void suppressingSyntaxErrorsInline() { // syntaxErrors should be suppressable (#5917)
std::map<std::string, std::string> files;
files["test.cpp"] = "double result(0.0);\n"
"_asm\n"
"{\n"
" // cppcheck-suppress syntaxError\n"
" push EAX ; save EAX for callers \n"
" mov EAX,Real10 ; get the address pointed to by Real10\n"
" fld TBYTE PTR [EAX] ; load an extended real (10 bytes)\n"
" fstp QWORD PTR result ; store a double (8 bytes)\n"
" pop EAX ; restore EAX\n"
"}";
checkSuppression(files, "");
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestSuppressions)