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()
|
void CheckExceptionSafety::unsafeNew()
|
||||||
{
|
{
|
||||||
// Check that "--exception-safety" was given
|
if (_settings->enableId != "*" && _settings->enableId.find(",exceptNew,") == std::string::npos)
|
||||||
if (!_settings->_exceptionSafety)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Inspect initializer lists..
|
// Inspect initializer lists..
|
||||||
|
@ -198,8 +197,7 @@ void CheckExceptionSafety::unsafeNew()
|
||||||
|
|
||||||
void CheckExceptionSafety::realloc()
|
void CheckExceptionSafety::realloc()
|
||||||
{
|
{
|
||||||
// Check that "--exception-safety" was given
|
if (_settings->enableId != "*" && _settings->enableId.find(",exceptRealloc,") == std::string::npos)
|
||||||
if (!_settings->_exceptionSafety)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
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)
|
else if (strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--style") == 0)
|
||||||
_settings._checkCodingStyle = true;
|
_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
|
// Filter errors
|
||||||
else if (strcmp(argv[i], "--suppressions") == 0)
|
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
|
// Check if there are unused functions
|
||||||
else if (strcmp(argv[i], "--unused-functions") == 0)
|
else if (strcmp(argv[i], "--unused-functions") == 0)
|
||||||
_settings._unusedFunctions = true;
|
{
|
||||||
|
if (_settings.enableId != "*")
|
||||||
|
_settings.enableId += ",unusedFunctions,";
|
||||||
|
}
|
||||||
|
|
||||||
// Append userdefined code to checked source code
|
// Append userdefined code to checked source code
|
||||||
else if (strncmp(argv[i], "--append=", 9) == 0)
|
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
|
// --error-exitcode=1
|
||||||
else if (strncmp(argv[i], "--error-exitcode=", 17) == 0)
|
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]);
|
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)
|
if (pathnames.size() > 0)
|
||||||
|
@ -467,7 +481,7 @@ unsigned int CppCheck::check()
|
||||||
|
|
||||||
// This generates false positives - especially for libraries
|
// This generates false positives - especially for libraries
|
||||||
_settings._verbose = false;
|
_settings._verbose = false;
|
||||||
if (_settings._unusedFunctions)
|
if (_settings.enableId != "*" && _settings.enableId.find(",unusedFunctions,") != std::string::npos)
|
||||||
{
|
{
|
||||||
_errout.str("");
|
_errout.str("");
|
||||||
if (_settings._errorsOnly == false)
|
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);
|
_checkUnusedFunctions.parseTokens(_tokenizer);
|
||||||
|
|
||||||
// call all "runSimplifiedChecks" in all registered Check classes
|
// call all "runSimplifiedChecks" in all registered Check classes
|
||||||
|
|
|
@ -31,12 +31,10 @@ Settings::Settings()
|
||||||
_verbose = false;
|
_verbose = false;
|
||||||
_force = false;
|
_force = false;
|
||||||
_xml = false;
|
_xml = false;
|
||||||
_unusedFunctions = false;
|
|
||||||
_jobs = 1;
|
_jobs = 1;
|
||||||
_exitCode = 0;
|
_exitCode = 0;
|
||||||
_showtime = false;
|
_showtime = false;
|
||||||
_append = "";
|
_append = "";
|
||||||
_exceptionSafety = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings::~Settings()
|
Settings::~Settings()
|
||||||
|
|
|
@ -56,18 +56,12 @@ public:
|
||||||
bool _errorsOnly;
|
bool _errorsOnly;
|
||||||
bool _verbose;
|
bool _verbose;
|
||||||
|
|
||||||
/** extra checks for exception safety */
|
|
||||||
bool _exceptionSafety;
|
|
||||||
|
|
||||||
/** Force checking t he files with "too many" configurations. */
|
/** Force checking t he files with "too many" configurations. */
|
||||||
bool _force;
|
bool _force;
|
||||||
|
|
||||||
/** write xml results */
|
/** write xml results */
|
||||||
bool _xml;
|
bool _xml;
|
||||||
|
|
||||||
/** Checking if there are unused functions */
|
|
||||||
bool _unusedFunctions;
|
|
||||||
|
|
||||||
/** How many processes/threads should do checking at the same
|
/** How many processes/threads should do checking at the same
|
||||||
time. Default is 1. */
|
time. Default is 1. */
|
||||||
unsigned int _jobs;
|
unsigned int _jobs;
|
||||||
|
@ -123,6 +117,9 @@ public:
|
||||||
|
|
||||||
/** get append code */
|
/** get append code */
|
||||||
std::string append() const;
|
std::string append() const;
|
||||||
|
|
||||||
|
/** enable extra checks by id */
|
||||||
|
std::string enableId;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
@ -54,7 +54,7 @@ private:
|
||||||
// Check char variable usage..
|
// Check char variable usage..
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings._checkCodingStyle = true;
|
settings._checkCodingStyle = true;
|
||||||
settings._exceptionSafety = true;
|
settings.enableId = "*";
|
||||||
CheckExceptionSafety checkExceptionSafety(&tokenizer, &settings, this);
|
CheckExceptionSafety checkExceptionSafety(&tokenizer, &settings, this);
|
||||||
checkExceptionSafety.runSimplifiedChecks(&tokenizer, &settings, this);
|
checkExceptionSafety.runSimplifiedChecks(&tokenizer, &settings, this);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue