Fixed #883 (Add new command line argument --enable)
This commit is contained in:
parent
6669a50634
commit
2b1b7f78f5
|
@ -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())
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
/// @}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue