From acd8a092f8a356b4da17f4d978404de3f73cb8d4 Mon Sep 17 00:00:00 2001 From: Miika-Petteri Matikainen Date: Wed, 28 Oct 2015 20:27:05 +0200 Subject: [PATCH] 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. --- lib/cppcheck.cpp | 2 +- test/testsuppressions.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 9353cde79..694207da7 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -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; } diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp index a331273d4..345d2cd1f 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -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 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 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)