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
10 changes: 8 additions & 2 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1117,12 +1117,14 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
mSettings.premiumArgs += " ";
const std::string p(argv[i] + 10);
const std::string p2(p.find('=') != std::string::npos ? p.substr(0, p.find('=')) : "");
if (!valid.count(p) && !valid2.count(p2)) {
const bool isCodingStandard = startsWith(p, "autosar") || startsWith(p,"cert-") || startsWith(p,"misra-");
const std::string p3(endsWith(p,":all") && isCodingStandard ? p.substr(0,p.rfind(':')) : p);
if (!valid.count(p3) && !valid2.count(p2)) {
mLogger.printError("invalid --premium option '" + (p2.empty() ? p : p2) + "'.");
return Result::Fail;
}
mSettings.premiumArgs += "--" + p;
if (startsWith(p, "autosar") || startsWith(p, "cert") || startsWith(p, "misra")) {
if (isCodingStandard) {
// All checkers related to the coding standard should be enabled. The coding standards
// do not all undefined behavior or portability issues.
mSettings.addEnabled("warning");
Expand Down Expand Up @@ -1888,9 +1890,13 @@ void CmdLineParser::printHelp() const
" * misra-c-2025 Misra C 2025\n"
" * misra-c++-2008 Misra C++ 2008\n"
" * misra-c++-2023 Misra C++ 2023\n"
" By default 'Misra/Cert C' only checks C files.\n"
" By default 'Autosar/Misra/Cert C++' only checks C++ files.\n"
" To check all files, append \":all\" i.e. --premium=misra-c++-2023:all.\n"
" Other:\n"
" * bughunting Soundy analysis\n"
" * cert-c-int-precision=BITS Integer precision to use in Cert C analysis.\n"
" * metrics Calculate metrics. Metrics are only reported in xmlv3 output.\n"
" * safety Turn on safety certified behavior (ON by default)\n"
" * safety-off Turn off safety certified behavior\n";
}
Expand Down
15 changes: 15 additions & 0 deletions man/manual-premium.md
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,21 @@ Command to activate Misra C++ 2023 checkers:

cppcheck --premium=misra-c++-2023 ....

### Checking all C and C++ files

The `cert-c` and `misra-c-*` coding standards target C and therefore the checkers only check C files by default.

The `autosar`, `cert-c++` and `misra-c++-*` coding standards target C++ and therefore the checkers only check C++ files by default.

If you want to check all files you can append ":all" to the coding standard. Example:

# Misra C checkers are executed on C files, not on C++ files
cppcheck --premium=misra-c-2025 path

# Misra C checkers are executed on C and C++ files
cppcheck --premium=misra-c-2025:all path


## Compliance report

### Graphical user interface
Expand Down
18 changes: 18 additions & 0 deletions test/testcmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ class TestCmdlineParser : public TestFixture {
TEST_CASE(premiumOptions3);
TEST_CASE(premiumOptions4);
TEST_CASE(premiumOptions5);
TEST_CASE(premiumOptionsAll);
TEST_CASE(premiumOptionsMetrics);
TEST_CASE(premiumOptionsCertCIntPrecision);
TEST_CASE(premiumOptionsLicenseFile);
Expand Down Expand Up @@ -1498,6 +1499,23 @@ class TestCmdlineParser : public TestFixture {
ASSERT_EQUALS(false, settings->severity.isEnabled(Severity::warning));
}

void premiumOptionsAll() {
REDIRECT;
asPremium();
const char * const argv[] = {
"cppcheck",
"--premium=autosar:all",
"--premium=cert-c:all",
"--premium=cert-c++:all",
"--premium=misra-c-2023:all",
"--premium=misra-c++-2023:all",
"file.c"
};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
ASSERT_EQUALS("--autosar:all --cert-c:all --cert-c++:all --misra-c-2023:all --misra-c++-2023:all",
settings->premiumArgs);
}

void premiumOptionsMetrics() {
REDIRECT;
asPremium();
Expand Down
Loading