Skip to content

Commit c307d03

Browse files
authored
Fix #12342 (Show premium autosar/misra/cert style issues even if --enable is not used) (danmar#5874)
1 parent b397caa commit c307d03

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

lib/cppcheck.cpp

+18-2
Original file line numberDiff line numberDiff line change
@@ -1472,8 +1472,12 @@ void CppCheck::executeAddons(const std::vector<std::string>& files, const std::s
14721472
continue;
14731473
errmsg.severity = Severity::internal;
14741474
}
1475-
else if (!mSettings.severity.isEnabled(errmsg.severity))
1476-
continue;
1475+
else if (!mSettings.severity.isEnabled(errmsg.severity)) {
1476+
// Do not filter out premium misra/cert/autosar messages that has been
1477+
// explicitly enabled with a --premium option
1478+
if (!isPremiumCodingStandardId(errmsg.id))
1479+
continue;
1480+
}
14771481
errmsg.file0 = file0;
14781482

14791483
reportErr(errmsg);
@@ -1866,3 +1870,15 @@ void CppCheck::printTimerResults(SHOWTIME_MODES mode)
18661870
{
18671871
s_timerResults.showResults(mode);
18681872
}
1873+
1874+
bool CppCheck::isPremiumCodingStandardId(const std::string& id) const {
1875+
if (mSettings.premiumArgs.find("--misra") != std::string::npos) {
1876+
if (startsWith(id, "misra-") || startsWith(id, "premium-misra-"))
1877+
return true;
1878+
}
1879+
if (mSettings.premiumArgs.find("--cert") != std::string::npos && startsWith(id, "premium-cert-"))
1880+
return true;
1881+
if (mSettings.premiumArgs.find("--autosar") != std::string::npos && startsWith(id, "premium-autosar-"))
1882+
return true;
1883+
return false;
1884+
}

lib/cppcheck.h

+2
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
150150
static void resetTimerResults();
151151
static void printTimerResults(SHOWTIME_MODES mode);
152152

153+
bool isPremiumCodingStandardId(const std::string& id) const;
154+
153155
private:
154156
#ifdef HAVE_RULES
155157
/** Are there "simple" rules */

test/testcppcheck.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class TestCppcheck : public TestFixture {
5555
TEST_CASE(checkWithFS);
5656
TEST_CASE(suppress_error_library);
5757
TEST_CASE(unique_errors);
58+
TEST_CASE(isPremiumCodingStandardId);
5859
}
5960

6061
void getErrorMessages() const {
@@ -180,6 +181,31 @@ class TestCppcheck : public TestFixture {
180181
ASSERT_EQUALS("nullPointer", it->id);
181182
}
182183

184+
void isPremiumCodingStandardId() const {
185+
ErrorLogger2 errorLogger;
186+
CppCheck cppcheck(errorLogger, false, {});
187+
188+
cppcheck.settings().premiumArgs = "";
189+
ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("misra-c2012-0.0"));
190+
ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("misra-c2023-0.0"));
191+
ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("premium-misra-c2012-0.0"));
192+
ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("premium-misra-c2023-0.0"));
193+
ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("premium-misra-c++2008-0.0.0"));
194+
ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("premium-misra-c++2023-0.0.0"));
195+
ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("premium-cert-int50-cpp"));
196+
ASSERT_EQUALS(false, cppcheck.isPremiumCodingStandardId("premium-autosar-0-0-0"));
197+
198+
cppcheck.settings().premiumArgs = "--misra-c-2012 --cert-c++-2016 --autosar";
199+
ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("misra-c2012-0.0"));
200+
ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("misra-c2023-0.0"));
201+
ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("premium-misra-c2012-0.0"));
202+
ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("premium-misra-c2023-0.0"));
203+
ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("premium-misra-c++2008-0.0.0"));
204+
ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("premium-misra-c++2023-0.0.0"));
205+
ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("premium-cert-int50-cpp"));
206+
ASSERT_EQUALS(true, cppcheck.isPremiumCodingStandardId("premium-autosar-0-0-0"));
207+
}
208+
183209
// TODO: test suppressions
184210
// TODO: test all with FS
185211
};

0 commit comments

Comments
 (0)