diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index b8d5c2525..33a24d35e 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -451,14 +451,16 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string locationList.push_back(loc); ErrorLogger::ErrorMessage errmsg(locationList, mTokenizer.list.getSourceFilePath(), - Severity::error, + e.type == InternalError::UNKNOWN_MACRO ? Severity::information : Severity::error, e.errorMessage, e.id, false); - reportErr(errmsg); - if (!mSuppressInternalErrorFound) - internalErrorFound = true; + if (errmsg._severity == Severity::error || mSettings.isEnabled(errmsg._severity)) { + reportErr(errmsg); + if (!mSuppressInternalErrorFound) + internalErrorFound = true; + } } } diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index 534f859ce..52621912d 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -34,7 +34,7 @@ #include InternalError::InternalError(const Token *tok, const std::string &errorMsg, Type type) : - token(tok), errorMessage(errorMsg) + token(tok), errorMessage(errorMsg), type(type) { switch (type) { case AST: @@ -43,6 +43,9 @@ InternalError::InternalError(const Token *tok, const std::string &errorMsg, Type case SYNTAX: id = "syntaxError"; break; + case UNKNOWN_MACRO: + id = "unknownMacro"; + break; case INTERNAL: id = "cppcheckError"; break; diff --git a/lib/errorlogger.h b/lib/errorlogger.h index a241a2da7..832b42ad9 100644 --- a/lib/errorlogger.h +++ b/lib/errorlogger.h @@ -54,10 +54,11 @@ namespace tinyxml2 { /** @brief Simple container to be thrown when internal error is detected. */ struct InternalError { - enum Type {AST, SYNTAX, INTERNAL}; + enum Type {AST, SYNTAX, UNKNOWN_MACRO, INTERNAL}; InternalError(const Token *tok, const std::string &errorMsg, Type type = INTERNAL); const Token *token; std::string errorMessage; + Type type; std::string id; }; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 1e04ee8d7..5e8424d4a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7923,7 +7923,7 @@ void Tokenizer::syntaxErrorC(const Token *tok, const std::string &what) const void Tokenizer::unknownMacroError(const Token *tok1) const { printDebugOutput(0); - throw InternalError(tok1, "There is an unknown macro here somewhere. Configuration is required. If " + tok1->str() + " is a macro then please configure it.", InternalError::SYNTAX); + throw InternalError(tok1, "There is an unknown macro here somewhere. Configuration is required. If " + tok1->str() + " is a macro then please configure it.", InternalError::UNKNOWN_MACRO); } void Tokenizer::unhandled_macro_class_x_y(const Token *tok) const