Disabled C++ specific checks and simplifications when checking a C or non-C++ file.
This commit is contained in:
parent
87131f6105
commit
5940d77a62
|
@ -45,6 +45,9 @@ public:
|
||||||
|
|
||||||
/** Simplified checks. The token list is simplified. */
|
/** Simplified checks. The token list is simplified. */
|
||||||
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
|
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
|
||||||
|
if (!tokenizer->isCPP())
|
||||||
|
return;
|
||||||
|
|
||||||
CheckBoost checkBoost(tokenizer, settings, errorLogger);
|
CheckBoost checkBoost(tokenizer, settings, errorLogger);
|
||||||
|
|
||||||
checkBoost.checkBoostForeachModification();
|
checkBoost.checkBoostForeachModification();
|
||||||
|
|
|
@ -44,6 +44,9 @@ public:
|
||||||
|
|
||||||
/** @brief Run checks on the normal token list */
|
/** @brief Run checks on the normal token list */
|
||||||
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
|
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
|
||||||
|
if (tokenizer->isC())
|
||||||
|
return;
|
||||||
|
|
||||||
CheckClass checkClass(tokenizer, settings, errorLogger);
|
CheckClass checkClass(tokenizer, settings, errorLogger);
|
||||||
|
|
||||||
// can't be a simplified check .. the 'sizeof' is used.
|
// can't be a simplified check .. the 'sizeof' is used.
|
||||||
|
@ -52,6 +55,9 @@ public:
|
||||||
|
|
||||||
/** @brief Run checks on the simplified token list */
|
/** @brief Run checks on the simplified token list */
|
||||||
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
|
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
|
||||||
|
if (tokenizer->isC())
|
||||||
|
return;
|
||||||
|
|
||||||
CheckClass checkClass(tokenizer, settings, errorLogger);
|
CheckClass checkClass(tokenizer, settings, errorLogger);
|
||||||
|
|
||||||
// Coding style checks
|
// Coding style checks
|
||||||
|
|
|
@ -53,6 +53,9 @@ public:
|
||||||
|
|
||||||
/** Checks that uses the simplified token list */
|
/** Checks that uses the simplified token list */
|
||||||
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
|
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
|
||||||
|
if (tokenizer->isC())
|
||||||
|
return;
|
||||||
|
|
||||||
CheckExceptionSafety checkExceptionSafety(tokenizer, settings, errorLogger);
|
CheckExceptionSafety checkExceptionSafety(tokenizer, settings, errorLogger);
|
||||||
checkExceptionSafety.destructors();
|
checkExceptionSafety.destructors();
|
||||||
checkExceptionSafety.deallocThrow();
|
checkExceptionSafety.deallocThrow();
|
||||||
|
|
|
@ -363,7 +363,7 @@ public:
|
||||||
|
|
||||||
void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) {
|
void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) {
|
||||||
// Don't use these check for Java and C# programs..
|
// Don't use these check for Java and C# programs..
|
||||||
if (tokenizr->isJavaOrCSharp())
|
if (!tokenizr->isCPP())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CheckMemoryLeakInClass checkMemoryLeak(tokenizr, settings, errLog);
|
CheckMemoryLeakInClass checkMemoryLeak(tokenizr, settings, errLog);
|
||||||
|
|
|
@ -1871,7 +1871,7 @@ void CheckOther::variableScopeError(const Token *tok, const std::string &varname
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
void CheckOther::checkConstantFunctionParameter()
|
void CheckOther::checkConstantFunctionParameter()
|
||||||
{
|
{
|
||||||
if (!_settings->isEnabled("performance"))
|
if (!_settings->isEnabled("performance") || _tokenizer->isC())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase();
|
const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||||
|
@ -3276,7 +3276,7 @@ In most scenarios, "const A & a = getA()" will be more efficient.
|
||||||
*/
|
*/
|
||||||
void CheckOther::checkRedundantCopy()
|
void CheckOther::checkRedundantCopy()
|
||||||
{
|
{
|
||||||
if (!_settings->isEnabled("performance"))
|
if (!_settings->isEnabled("performance") || _tokenizer->isC())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
|
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||||
|
|
|
@ -44,6 +44,9 @@ public:
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
|
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
|
||||||
|
if (tokenizer->isC())
|
||||||
|
return;
|
||||||
|
|
||||||
CheckPostfixOperator checkPostfixOperator(tokenizer, settings, errorLogger);
|
CheckPostfixOperator checkPostfixOperator(tokenizer, settings, errorLogger);
|
||||||
checkPostfixOperator.postfixOperator();
|
checkPostfixOperator.postfixOperator();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1072,9 +1072,6 @@ static bool isLocal(const SymbolDatabase* symbolDatabase, unsigned int varid)
|
||||||
|
|
||||||
void CheckStl::string_c_str()
|
void CheckStl::string_c_str()
|
||||||
{
|
{
|
||||||
if (!_tokenizer->isCPP())
|
|
||||||
return;
|
|
||||||
|
|
||||||
const SymbolDatabase* symbolDatabase = _tokenizer->getSymbolDatabase();
|
const SymbolDatabase* symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||||
|
|
||||||
// Find all functions that take std::string as argument
|
// Find all functions that take std::string as argument
|
||||||
|
@ -1238,9 +1235,6 @@ static bool hasArrayEndParen(const Token *tok1)
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
void CheckStl::checkAutoPointer()
|
void CheckStl::checkAutoPointer()
|
||||||
{
|
{
|
||||||
if (!_tokenizer->isCPP())
|
|
||||||
return;
|
|
||||||
|
|
||||||
std::set<unsigned int> autoPtrVarId;
|
std::set<unsigned int> autoPtrVarId;
|
||||||
static const char STL_CONTAINER_LIST[] = "array|bitset|deque|list|forward_list|map|multimap|multiset|priority_queue|queue|set|stack|vector|hash_map|hash_multimap|hash_set|unordered_map|unordered_multimap|unordered_set|unordered_multiset|basic_string";
|
static const char STL_CONTAINER_LIST[] = "array|bitset|deque|list|forward_list|map|multimap|multiset|priority_queue|queue|set|stack|vector|hash_map|hash_multimap|hash_set|unordered_map|unordered_multimap|unordered_set|unordered_multiset|basic_string";
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,9 @@ public:
|
||||||
|
|
||||||
/** Simplified checks. The token list is simplified. */
|
/** Simplified checks. The token list is simplified. */
|
||||||
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
|
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
|
||||||
|
if (!tokenizer->isCPP())
|
||||||
|
return;
|
||||||
|
|
||||||
CheckStl checkStl(tokenizer, settings, errorLogger);
|
CheckStl checkStl(tokenizer, settings, errorLogger);
|
||||||
|
|
||||||
checkStl.stlOutOfBounds();
|
checkStl.stlOutOfBounds();
|
||||||
|
|
|
@ -2075,6 +2075,9 @@ bool Tokenizer::hasComplicatedSyntaxErrorsInTemplates()
|
||||||
|
|
||||||
void Tokenizer::simplifyDefaultAndDeleteInsideClass()
|
void Tokenizer::simplifyDefaultAndDeleteInsideClass()
|
||||||
{
|
{
|
||||||
|
if (isC())
|
||||||
|
return;
|
||||||
|
|
||||||
// Remove "= default|delete" inside class|struct definitions
|
// Remove "= default|delete" inside class|struct definitions
|
||||||
// Todo: Remove it if it is used "externally" too.
|
// Todo: Remove it if it is used "externally" too.
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
|
@ -2487,6 +2490,9 @@ void Tokenizer::simplifyLabelsCaseDefault()
|
||||||
|
|
||||||
void Tokenizer::simplifyTemplates()
|
void Tokenizer::simplifyTemplates()
|
||||||
{
|
{
|
||||||
|
if (isC())
|
||||||
|
return;
|
||||||
|
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
// #2648 - simple fix for sizeof used as template parameter
|
// #2648 - simple fix for sizeof used as template parameter
|
||||||
// TODO: this is a bit hardcoded. make a bit more generic
|
// TODO: this is a bit hardcoded. make a bit more generic
|
||||||
|
@ -6640,6 +6646,9 @@ bool Tokenizer::simplifyRedundantParenthesis()
|
||||||
|
|
||||||
void Tokenizer::simplifyReference()
|
void Tokenizer::simplifyReference()
|
||||||
{
|
{
|
||||||
|
if (isC())
|
||||||
|
return;
|
||||||
|
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
// starting executable scope..
|
// starting executable scope..
|
||||||
if (Token::Match(tok, ") const| {")) {
|
if (Token::Match(tok, ") const| {")) {
|
||||||
|
@ -7432,6 +7441,9 @@ void Tokenizer::simplifyEnum()
|
||||||
|
|
||||||
void Tokenizer::simplifyStd()
|
void Tokenizer::simplifyStd()
|
||||||
{
|
{
|
||||||
|
if (isC())
|
||||||
|
return;
|
||||||
|
|
||||||
std::set<std::string> f;
|
std::set<std::string> f;
|
||||||
f.insert("strcat");
|
f.insert("strcat");
|
||||||
f.insert("strcpy");
|
f.insert("strcpy");
|
||||||
|
@ -7946,6 +7958,9 @@ void Tokenizer::simplifyComma()
|
||||||
|
|
||||||
void Tokenizer::removeExceptionSpecifications()
|
void Tokenizer::removeExceptionSpecifications()
|
||||||
{
|
{
|
||||||
|
if (isC())
|
||||||
|
return;
|
||||||
|
|
||||||
for (Token* tok = list.front(); tok; tok = tok->next()) {
|
for (Token* tok = list.front(); tok; tok = tok->next()) {
|
||||||
if (Token::Match(tok, ") const| throw (")) {
|
if (Token::Match(tok, ") const| throw (")) {
|
||||||
if (tok->next()->str() == "const") {
|
if (tok->next()->str() == "const") {
|
||||||
|
@ -9063,6 +9078,9 @@ void Tokenizer::deleteSymbolDatabase()
|
||||||
|
|
||||||
void Tokenizer::simplifyOperatorName()
|
void Tokenizer::simplifyOperatorName()
|
||||||
{
|
{
|
||||||
|
if (isC())
|
||||||
|
return;
|
||||||
|
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
if (tok->str() == "operator") {
|
if (tok->str() == "operator") {
|
||||||
// operator op
|
// operator op
|
||||||
|
@ -9117,6 +9135,9 @@ void Tokenizer::simplifyOperatorName()
|
||||||
// remove unnecessary member qualification..
|
// remove unnecessary member qualification..
|
||||||
void Tokenizer::removeUnnecessaryQualification()
|
void Tokenizer::removeUnnecessaryQualification()
|
||||||
{
|
{
|
||||||
|
if (isC())
|
||||||
|
return;
|
||||||
|
|
||||||
std::vector<Space> classInfo;
|
std::vector<Space> classInfo;
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
if (Token::Match(tok, "class|struct|namespace %type% :|{") &&
|
if (Token::Match(tok, "class|struct|namespace %type% :|{") &&
|
||||||
|
|
Loading…
Reference in New Issue