Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1472,8 +1472,12 @@ void CppCheck::executeAddons(const std::vector<std::string>& files, const std::s
continue;
errmsg.severity = Severity::internal;
}
else if (!mSettings.severity.isEnabled(errmsg.severity))
continue;
else if (!mSettings.severity.isEnabled(errmsg.severity)) {
// Do not filter out premium misra/cert/autosar messages that has been
// explicitly enabled with a --premium option
if (!isPremiumCodingStandardId(errmsg.id))
continue;
}
errmsg.file0 = file0;

reportErr(errmsg);
Expand Down Expand Up @@ -1866,3 +1870,15 @@ void CppCheck::printTimerResults(SHOWTIME_MODES mode)
{
s_timerResults.showResults(mode);
}

bool CppCheck::isPremiumCodingStandardId(const std::string& id) const {
if (mSettings.premiumArgs.find("--misra") != std::string::npos) {
if (startsWith(id, "misra-") || startsWith(id, "premium-misra-"))
return true;
}
if (mSettings.premiumArgs.find("--cert") != std::string::npos && startsWith(id, "premium-cert-"))
return true;
if (mSettings.premiumArgs.find("--autosar") != std::string::npos && startsWith(id, "premium-autosar-"))
return true;
return false;
}
2 changes: 2 additions & 0 deletions lib/cppcheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
static void resetTimerResults();
static void printTimerResults(SHOWTIME_MODES mode);

bool isPremiumCodingStandardId(const std::string& id) const;

private:
#ifdef HAVE_RULES
/** Are there "simple" rules */
Expand Down
26 changes: 26 additions & 0 deletions test/testcppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class TestCppcheck : public TestFixture {
TEST_CASE(checkWithFS);
TEST_CASE(suppress_error_library);
TEST_CASE(unique_errors);
TEST_CASE(isPremiumCodingStandardId);
}

void getErrorMessages() const {
Expand Down Expand Up @@ -180,6 +181,31 @@ class TestCppcheck : public TestFixture {
ASSERT_EQUALS("nullPointer", it->id);
}

void isPremiumCodingStandardId() const {
ErrorLogger2 errorLogger;
CppCheck cppcheck(errorLogger, false, {});

cppcheck.settings().premiumArgs = "";
ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("misra-c2012-0.0"));
ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("misra-c2023-0.0"));
ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("premium-misra-c2012-0.0"));
ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("premium-misra-c2023-0.0"));
ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("premium-misra-c++2008-0.0.0"));
ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("premium-misra-c++2023-0.0.0"));
ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("premium-cert-int50-cpp"));
ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("premium-autosar-0-0-0"));

cppcheck.settings().premiumArgs = "--misra-c-2012 --cert-c++-2016 --autosar";
ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("misra-c2012-0.0"));
ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("misra-c2023-0.0"));
ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("premium-misra-c2012-0.0"));
ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("premium-misra-c2023-0.0"));
ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("premium-misra-c++2008-0.0.0"));
ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("premium-misra-c++2023-0.0.0"));
ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("premium-cert-int50-cpp"));
ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("premium-autosar-0-0-0"));
}

// TODO: test suppressions
// TODO: test all with FS
};
Expand Down