From 2b1b7f78f555a9be3f526e5bc6859a659d2e472f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 15 Nov 2009 15:24:33 +0100 Subject: [PATCH] Fixed #883 (Add new command line argument --enable) --- lib/checkexceptionsafety.cpp | 6 ++--- lib/cppcheck.cpp | 45 ++++++++++++++++++++++++------------ lib/settings.cpp | 2 -- lib/settings.h | 9 +++----- test/testexceptionsafety.cpp | 2 +- 5 files changed, 36 insertions(+), 28 deletions(-) diff --git a/lib/checkexceptionsafety.cpp b/lib/checkexceptionsafety.cpp index 73eb9e739..0e0b584ce 100644 --- a/lib/checkexceptionsafety.cpp +++ b/lib/checkexceptionsafety.cpp @@ -84,8 +84,7 @@ static bool autodealloc(const Token * const C, const Token * const tokens) void CheckExceptionSafety::unsafeNew() { - // Check that "--exception-safety" was given - if (!_settings->_exceptionSafety) + if (_settings->enableId != "*" && _settings->enableId.find(",exceptNew,") == std::string::npos) return; // Inspect initializer lists.. @@ -198,8 +197,7 @@ void CheckExceptionSafety::unsafeNew() void CheckExceptionSafety::realloc() { - // Check that "--exception-safety" was given - if (!_settings->_exceptionSafety) + if (_settings->enableId != "*" && _settings->enableId.find(",exceptRealloc,") == std::string::npos) return; for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index ff9c69195..e59385d0f 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -109,16 +109,6 @@ void CppCheck::parseFromArgs(int argc, const char* const argv[]) else if (strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--style") == 0) _settings._checkCodingStyle = true; - // Checking exception safety - else if (strcmp(argv[i], "--enable") == 0) - { - // enable all checking - _settings._showAll = true; - _settings._checkCodingStyle = true; - _settings._exceptionSafety = true; - _settings._unusedFunctions = true; - } - // Filter errors else if (strcmp(argv[i], "--suppressions") == 0) { @@ -147,7 +137,10 @@ void CppCheck::parseFromArgs(int argc, const char* const argv[]) // Check if there are unused functions else if (strcmp(argv[i], "--unused-functions") == 0) - _settings._unusedFunctions = true; + { + if (_settings.enableId != "*") + _settings.enableId += ",unusedFunctions,"; + } // Append userdefined code to checked source code else if (strncmp(argv[i], "--append=", 9) == 0) @@ -167,6 +160,27 @@ void CppCheck::parseFromArgs(int argc, const char* const argv[]) } + else if (strcmp(argv[i], "--enable") == 0) + { + _settings.enableId = "*"; + _settings._showAll = true; + _settings._checkCodingStyle = true; + } + + else if (strncmp(argv[i], "--enable=", 9) == 0) + { + if (_settings.enableId != "*") + { + std::string s(9 + argv[i]); + if (s[0] == '\"') + s[0] = ','; + std::string::size_type pos = s.find("\""); + if (pos != std::string::npos) + s.erase(pos, 1); + _settings.enableId += "," + s + ","; + } + } + // --error-exitcode=1 else if (strncmp(argv[i], "--error-exitcode=", 17) == 0) { @@ -316,9 +330,9 @@ void CppCheck::parseFromArgs(int argc, const char* const argv[]) pathnames.push_back(argv[i]); } - if (_settings._unusedFunctions && _settings._jobs > 1) + if (_settings.enableId.find(",unusedFunctions,") != std::string::npos && _settings._jobs > 1) { - throw std::runtime_error("cppcheck: error: --unused-functions can't be used with -j option."); + throw std::runtime_error("cppcheck: error: the unusedFunctions check can't be used with -j option."); } if (pathnames.size() > 0) @@ -467,7 +481,7 @@ unsigned int CppCheck::check() // This generates false positives - especially for libraries _settings._verbose = false; - if (_settings._unusedFunctions) + if (_settings.enableId != "*" && _settings.enableId.find(",unusedFunctions,") != std::string::npos) { _errout.str(""); if (_settings._errorsOnly == false) @@ -529,7 +543,8 @@ void CppCheck::checkFile(const std::string &code, const char FileName[]) } } - if (_settings._unusedFunctions) + + if (_settings.enableId != "*" || _settings.enableId.find(",unusedFunctions,") != std::string::npos) _checkUnusedFunctions.parseTokens(_tokenizer); // call all "runSimplifiedChecks" in all registered Check classes diff --git a/lib/settings.cpp b/lib/settings.cpp index f1758d54f..761df5df9 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -31,12 +31,10 @@ Settings::Settings() _verbose = false; _force = false; _xml = false; - _unusedFunctions = false; _jobs = 1; _exitCode = 0; _showtime = false; _append = ""; - _exceptionSafety = false; } Settings::~Settings() diff --git a/lib/settings.h b/lib/settings.h index 9476af968..e287ba04b 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -56,18 +56,12 @@ public: bool _errorsOnly; bool _verbose; - /** extra checks for exception safety */ - bool _exceptionSafety; - /** Force checking t he files with "too many" configurations. */ bool _force; /** write xml results */ bool _xml; - /** Checking if there are unused functions */ - bool _unusedFunctions; - /** How many processes/threads should do checking at the same time. Default is 1. */ unsigned int _jobs; @@ -123,6 +117,9 @@ public: /** get append code */ std::string append() const; + + /** enable extra checks by id */ + std::string enableId; }; /// @} diff --git a/test/testexceptionsafety.cpp b/test/testexceptionsafety.cpp index cb532ba6c..fdc8c3c3a 100644 --- a/test/testexceptionsafety.cpp +++ b/test/testexceptionsafety.cpp @@ -54,7 +54,7 @@ private: // Check char variable usage.. Settings settings; settings._checkCodingStyle = true; - settings._exceptionSafety = true; + settings.enableId = "*"; CheckExceptionSafety checkExceptionSafety(&tokenizer, &settings, this); checkExceptionSafety.runSimplifiedChecks(&tokenizer, &settings, this); }