diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 608e1844716..7010e5c3f5e 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -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"); @@ -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"; } diff --git a/man/manual-premium.md b/man/manual-premium.md index 4e35dd1850d..bf89cb3d67c 100644 --- a/man/manual-premium.md +++ b/man/manual-premium.md @@ -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 diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index 1e811586345..65bf6906841 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -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); @@ -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();