diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 5c85a23e3cc..722e68817ed 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3484,6 +3484,8 @@ bool Tokenizer::simplifyTokens1(const std::string &configuration) mSymbolDatabase->setArrayDimensionsUsingValueFlow(); } + validateTypes(); + printDebugOutput(1, std::cout); return true; @@ -5926,25 +5928,29 @@ void Tokenizer::printDebugOutput(int simplification, std::ostream &out) const if (mSettings.xml) out << "" << std::endl; } +} - if (mSymbolDatabase && simplification == 2U && mSettings.debugwarnings) { - printUnknownTypes(); +void Tokenizer::validateTypes() const +{ + if (!mSymbolDatabase || !mSettings.debugwarnings) + return; - // the typeStartToken() should come before typeEndToken() - for (const Variable *var : mSymbolDatabase->variableList()) { - if (!var) - continue; + printUnknownTypes(); - const Token * typetok = var->typeStartToken(); - while (typetok && typetok != var->typeEndToken()) - typetok = typetok->next(); + // the typeStartToken() should come before typeEndToken() + for (const Variable *var : mSymbolDatabase->variableList()) { + if (!var) + continue; - if (typetok != var->typeEndToken()) { - reportError(var->typeStartToken(), - Severity::debug, - "debug", - "Variable::typeStartToken() of variable '" + var->name() + "' is not located before Variable::typeEndToken(). The location of the typeStartToken() is '" + var->typeStartToken()->str() + "' at line " + std::to_string(var->typeStartToken()->linenr())); - } + const Token * typetok = var->typeStartToken(); + while (typetok && typetok != var->typeEndToken()) + typetok = typetok->next(); + + if (typetok != var->typeEndToken()) { + reportError(var->typeStartToken(), + Severity::debug, + "debug", + "Variable::typeStartToken() of variable '" + var->name() + "' is not located before Variable::typeEndToken(). The location of the typeStartToken() is '" + var->typeStartToken()->str() + "' at line " + std::to_string(var->typeStartToken()->linenr())); } } } diff --git a/lib/tokenize.h b/lib/tokenize.h index 49f622d1f49..451ea75c935 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -562,6 +562,8 @@ class CPPCHECKLIB Tokenizer { static bool operatorEnd(const Token * tok); + void validateTypes() const; + public: const SymbolDatabase *getSymbolDatabase() const { return mSymbolDatabase;