Inconclusive checking: Report inconclusive errors with reportInconclusiveError. It takes the same parameters as reportError.

This commit is contained in:
Daniel Marjamäki 2011-04-14 18:02:01 +02:00
parent 7021e3224b
commit 58dbbb0cab
12 changed files with 95 additions and 60 deletions

View File

@ -254,7 +254,8 @@ unsigned int ThreadExecutor::check()
const ErrorLogger::ErrorMessage errmsg(locations,
Severity::error,
oss.str(),
"cppcheckError");
"cppcheckError",
false);
_errorLogger.reportErr(errmsg);
}
}

View File

@ -128,6 +128,32 @@ protected:
/** report an error */
void reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, std::string msg)
{
reportError(callstack, severity, id, msg, false);
}
/** report an inconclusive error */
void reportInconclusiveError(const Token *tok, const Severity::SeverityType severity, const std::string &id, const std::string &msg)
{
std::list<const Token *> callstack;
if (tok)
callstack.push_back(tok);
reportInconclusiveError(callstack, severity, id, msg);
}
/** report an inconclusive error */
void reportInconclusiveError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, std::string msg)
{
reportError(callstack, severity, id, msg, true);
}
private:
/** disabled assignment operator */
void operator=(const Check &);
/** report an error */
void reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, std::string msg, bool inconclusive)
{
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
for (std::list<const Token *>::const_iterator it = callstack.begin(); it != callstack.end(); ++it)
@ -142,7 +168,7 @@ protected:
locationList.push_back(loc);
}
ErrorLogger::ErrorMessage errmsg(locationList, severity, msg, id);
ErrorLogger::ErrorMessage errmsg(locationList, severity, msg, id, inconclusive);
if (_tokenizer && _tokenizer->getFiles() && !_tokenizer->getFiles()->empty())
errmsg.file0 = _tokenizer->getFiles()->at(0);
if (_errorLogger)
@ -151,12 +177,6 @@ protected:
reportError(errmsg);
}
private:
/** disabled assignment operator */
void operator=(const Check &);
};
namespace std

View File

@ -352,7 +352,7 @@ void CheckMemoryLeak::reportErr(const std::list<const Token *> &callstack, Sever
locations.push_back(loc);
}
const ErrorLogger::ErrorMessage errmsg(locations, severity, msg, id);
const ErrorLogger::ErrorMessage errmsg(locations, severity, msg, id, false);
if (errorLogger)
errorLogger->reportErr(errmsg);

View File

@ -192,7 +192,7 @@ void CheckUnusedFunctions::unusedFunctionError(ErrorLogger * const errorLogger,
locationList.push_back(fileLoc);
}
const ErrorLogger::ErrorMessage errmsg(locationList, Severity::style, "The function '" + funcname + "' is never used", "unusedFunction");
const ErrorLogger::ErrorMessage errmsg(locationList, Severity::style, "The function '" + funcname + "' is never used", "unusedFunction", false);
if (errorLogger)
errorLogger->reportErr(errmsg);
else

View File

@ -164,7 +164,8 @@ unsigned int CppCheck::check()
ErrorLogger::ErrorMessage errmsg(loclist,
Severity::information,
msg,
"toomanyconfigs");
"toomanyconfigs",
false);
_errorLogger.reportErr(errmsg);
break;
}
@ -333,7 +334,8 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
ErrorLogger::ErrorMessage errmsg(std::list<ErrorLogger::ErrorMessage::FileLocation>(),
Severity::error,
error,
"pcre_compile");
"pcre_compile",
false);
reportErr(errmsg);
}
@ -375,7 +377,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
summary = "found '" + str.substr(pos1, pos2 - pos1) + "'";
else
summary = rule.summary;
ErrorLogger::ErrorMessage errmsg(callStack, Severity::fromString(rule.severity), summary, rule.id);
const ErrorLogger::ErrorMessage errmsg(callStack, Severity::fromString(rule.severity), summary, rule.id, false);
// Report error
reportErr(errmsg);

View File

@ -26,10 +26,10 @@
ErrorLogger::ErrorMessage::ErrorMessage()
:_severity(Severity::none)
{
_inconclusive = false;
}
ErrorLogger::ErrorMessage::ErrorMessage(const std::list<FileLocation> &callStack, Severity::SeverityType severity, const std::string &msg, const std::string &id)
ErrorLogger::ErrorMessage::ErrorMessage(const std::list<FileLocation> &callStack, Severity::SeverityType severity, const std::string &msg, const std::string &id, bool inconclusive)
{
// locations for this error message
_callStack = callStack;
@ -42,6 +42,8 @@ ErrorLogger::ErrorMessage::ErrorMessage(const std::list<FileLocation> &callStack
// set the message id
_id = id;
_inconclusive = inconclusive;
}
void ErrorLogger::ErrorMessage::setmsg(const std::string &msg)
@ -68,6 +70,7 @@ std::string ErrorLogger::ErrorMessage::serialize() const
std::ostringstream oss;
oss << _id.length() << " " << _id;
oss << Severity::toString(_severity).length() << " " << Severity::toString(_severity);
oss << (_inconclusive ? "12 inconclusive" : "");
oss << _shortMessage.length() << " " << _shortMessage;
oss << _verboseMessage.length() << " " << _verboseMessage;
oss << _callStack.size() << " ";
@ -84,6 +87,7 @@ std::string ErrorLogger::ErrorMessage::serialize() const
bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
{
_inconclusive = false;
_callStack.clear();
std::istringstream iss(data);
std::vector<std::string> results;
@ -101,6 +105,12 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
temp.append(1, c);
}
if (temp == "inconclusive")
{
_inconclusive = true;
break;
}
results.push_back(temp);
if (results.size() == 4)
break;
@ -205,7 +215,7 @@ std::string ErrorLogger::ErrorMessage::toXML(bool verbose, int version) const
if (version == 1)
{
// No inconclusive messages in the xml version 1
if (Severity::toString(_severity).compare(0,12,"inconclusive")==0)
if (_inconclusive)
return "";
xml << "<error";
@ -224,7 +234,7 @@ std::string ErrorLogger::ErrorMessage::toXML(bool verbose, int version) const
else if (version == 2)
{
// TODO: How should inconclusive messages be saved in the xml version 2?
if (Severity::toString(_severity).compare(0,12,"inconclusive")==0)
if (_inconclusive)
return "";
xml << " <error";
@ -305,7 +315,7 @@ void ErrorLogger::reportUnmatchedSuppressions(const std::list<Settings::Suppress
{
std::list<ErrorLogger::ErrorMessage::FileLocation> callStack;
callStack.push_back(ErrorLogger::ErrorMessage::FileLocation(i->file, i->line));
reportErr(ErrorLogger::ErrorMessage(callStack, Severity::information, "Unmatched suppression: " + i->id, "unmatchedSuppression"));
reportErr(ErrorLogger::ErrorMessage(callStack, Severity::information, "Unmatched suppression: " + i->id, "unmatchedSuppression", false));
}
}

View File

@ -88,13 +88,7 @@ public:
* Debug message.
* Debug-mode message useful for the developers.
*/
debug,
/** inconclusive error */
inconclusive_error,
/** inconclusive warning */
inconclusive_warning
debug
};
static std::string toString(SeverityType severity)
@ -117,10 +111,6 @@ public:
return "information";
case debug:
return "debug";
case inconclusive_error:
return "inconclusive error";
case inconclusive_warning:
return "inconclusive warning";
};
return "???";
}
@ -144,10 +134,6 @@ public:
return information;
if (severity == "debug")
return debug;
if (severity == "inconclusive error")
return inconclusive_error;
if (severity == "inconclusive warning")
return inconclusive_warning;
return none;
}
};
@ -202,7 +188,7 @@ public:
};
ErrorMessage(const std::list<FileLocation> &callStack, Severity::SeverityType severity, const std::string &msg, const std::string &id);
ErrorMessage(const std::list<FileLocation> &callStack, Severity::SeverityType severity, const std::string &msg, const std::string &id, bool inconclusive);
ErrorMessage();
/**
@ -229,6 +215,7 @@ public:
std::list<FileLocation> _callStack;
Severity::SeverityType _severity;
std::string _id;
bool _inconclusive;
/** source file (not header) */
std::string file0;

View File

@ -53,7 +53,8 @@ void Preprocessor::writeError(const std::string &fileName, const unsigned int li
errorLogger->reportErr(ErrorLogger::ErrorMessage(locationList,
Severity::error,
errorText,
errorType));
errorType,
false));
}
static unsigned char readChar(std::istream &istr)
@ -1370,7 +1371,7 @@ std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const
if (_errorLogger && _settings && _settings->debugwarnings)
{
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
const ErrorLogger::ErrorMessage errmsg(locationList, Severity::debug, "unhandled configuration: " + *it, "debug");
const ErrorLogger::ErrorMessage errmsg(locationList, Severity::debug, "unhandled configuration: " + *it, "debug", false);
_errorLogger->reportErr(errmsg);
}
@ -1765,7 +1766,8 @@ void Preprocessor::error(const std::string &filename, unsigned int linenr, const
_errorLogger->reportErr(ErrorLogger::ErrorMessage(locationList,
Severity::error,
msg,
"preprocessorErrorDirective"));
"preprocessorErrorDirective",
false));
}
Preprocessor::HeaderTypes Preprocessor::getHeaderFileName(std::string &str)
@ -1963,7 +1965,7 @@ void Preprocessor::missingInclude(const std::string &filename, unsigned int line
// currently a debug-message.
const Severity::SeverityType severity = userheader ? Severity::information : Severity::debug;
const std::string id = userheader ? "missingInclude" : "debug";
ErrorLogger::ErrorMessage errmsg(locationList, severity, "Include file: \"" + header + "\" not found.", id);
ErrorLogger::ErrorMessage errmsg(locationList, severity, "Include file: \"" + header + "\" not found.", id, false);
errmsg.file0 = file0;
_errorLogger->reportErr(errmsg);
}

View File

@ -1209,7 +1209,8 @@ void SymbolDatabase::debugMessage(const Token *tok, const std::string &msg) cons
const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::debug,
msg,
"debug");
"debug",
false);
if (_errorLogger)
_errorLogger->reportErr(errmsg);
else

View File

@ -482,7 +482,8 @@ bool Token::Match(const Token *tok, const char pattern[], unsigned int varid)
const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::error,
"Internal error. Token::Match called with varid 0.",
"cppcheckError");
"cppcheckError",
false);
Check::reportError(errmsg);
}

View File

@ -489,7 +489,8 @@ void Tokenizer::duplicateTypedefError(const Token *tok1, const Token *tok2, cons
Severity::style,
std::string(type + " '" + tok2->str() +
"' hides typedef with same name"),
"variableHidingTypedef");
"variableHidingTypedef",
false);
if (_errorLogger)
_errorLogger->reportErr(errmsg);
@ -515,7 +516,8 @@ void Tokenizer::duplicateDeclarationError(const Token *tok1, const Token *tok2,
Severity::style,
std::string(type + " '" + tok2->str() +
"' forward declaration unnecessary, already declared"),
"unnecessaryForwardDeclaration");
"unnecessaryForwardDeclaration",
false);
if (_errorLogger)
_errorLogger->reportErr(errmsg);
@ -751,7 +753,8 @@ void Tokenizer::unsupportedTypedef(const Token *tok) const
const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::debug,
"Failed to parse \'" + str.str() + "\'. The checking continues anyway.",
"debug");
"debug",
false);
if (_errorLogger)
_errorLogger->reportErr(errmsg);
@ -2950,7 +2953,8 @@ void Tokenizer::simplifyTemplatesInstantiate(const Token *tok,
const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::debug,
"simplifyTemplates: bailing out",
"debug");
"debug",
false);
if (_errorLogger)
_errorLogger->reportErr(errmsg);
@ -3059,7 +3063,8 @@ void Tokenizer::simplifyTemplatesInstantiate(const Token *tok,
const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::debug,
"Failed to instantiate template. The checking continues anyway.",
"debug");
"debug",
false);
_errorLogger->reportErr(errmsg);
}
@ -6807,7 +6812,8 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::debug,
"simplifyKnownVariables: bailing out (variable="+tok3->str()+", value="+value+")",
"debug");
"debug",
false);
if (_errorLogger)
_errorLogger->reportErr(errmsg);
@ -7698,7 +7704,8 @@ void Tokenizer::duplicateEnumError(const Token * tok1, const Token * tok2, const
Severity::style,
std::string(type + " '" + tok2->str() +
"' hides enumerator with same name"),
"variableHidingEnum");
"variableHidingEnum",
false);
if (_errorLogger)
_errorLogger->reportErr(errmsg);
@ -8337,7 +8344,8 @@ void Tokenizer::syntaxError(const Token *tok)
const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::error,
"syntax error",
"syntaxError");
"syntaxError",
false);
if (_errorLogger)
_errorLogger->reportErr(errmsg);
@ -8364,7 +8372,8 @@ void Tokenizer::syntaxError(const Token *tok, char c)
"when these macros are defined: '" +
_configuration +
"'.",
"syntaxError");
"syntaxError",
false);
if (_errorLogger)
_errorLogger->reportErr(errmsg);
@ -8386,7 +8395,8 @@ void Tokenizer::cppcheckError(const Token *tok) const
const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::error,
"Analysis failed. If the code is valid then please report this failure.",
"cppcheckError");
"cppcheckError",
false);
if (_errorLogger)
_errorLogger->reportErr(errmsg);
@ -9667,7 +9677,8 @@ void Tokenizer::removeUnnecessaryQualification()
const ErrorLogger::ErrorMessage errmsg(locationList,
Severity::portability,
"Extra qualification \'" + tok->str() + "::\' unnecessary and considered an error by many compilers.",
"portability");
"portability",
false);
if (_errorLogger)
_errorLogger->reportErr(errmsg);

View File

@ -67,7 +67,7 @@ private:
loc.line = 5;
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
locs.push_back(loc);
ErrorMessage msg(locs, Severity::error, "Programming error.", "errorId");
ErrorMessage msg(locs, Severity::error, "Programming error.", "errorId", false);
ASSERT_EQUALS(1, (int)msg._callStack.size());
ASSERT_EQUALS("Programming error.", msg.shortMessage());
ASSERT_EQUALS("Programming error.", msg.verboseMessage());
@ -82,7 +82,7 @@ private:
loc.line = 5;
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
locs.push_back(loc);
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId");
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
ASSERT_EQUALS(1, (int)msg._callStack.size());
ASSERT_EQUALS("Programming error.", msg.shortMessage());
ASSERT_EQUALS("Verbose error", msg.verboseMessage());
@ -97,7 +97,7 @@ private:
loc.line = 5;
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
locs.push_back(loc);
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId");
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
ASSERT_EQUALS(1, (int)msg._callStack.size());
ASSERT_EQUALS("Programming error.", msg.shortMessage());
ASSERT_EQUALS("Verbose error", msg.verboseMessage());
@ -112,7 +112,7 @@ private:
loc.line = 5;
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
locs.push_back(loc);
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId");
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
ASSERT_EQUALS(1, (int)msg._callStack.size());
ASSERT_EQUALS("Programming error.", msg.shortMessage());
ASSERT_EQUALS("Verbose error", msg.verboseMessage());
@ -127,7 +127,7 @@ private:
loc.line = 5;
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
locs.push_back(loc);
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId");
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
ASSERT_EQUALS("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1));
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1));
ASSERT_EQUALS("<error file=\"foo.cpp\" line=\"5\" id=\"errorId\" severity=\"error\" msg=\"Programming error.\"/>", msg.toXML(false,1));
@ -140,7 +140,7 @@ private:
loc.line = 5;
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
locs.push_back(loc);
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId");
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
ASSERT_EQUALS("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1));
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1));
ASSERT_EQUALS("<error file=\"foo.cpp\" line=\"5\" id=\"errorId\" severity=\"error\" msg=\"Verbose error\"/>", msg.toXML(true,1));
@ -153,7 +153,7 @@ private:
loc.line = 5;
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
locs.push_back(loc);
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId");
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
std::string header("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results version=\"2\">\n");
header += " <cppcheck version=\"";
header += CppCheck::version();
@ -175,8 +175,8 @@ private:
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
locs.push_back(loc);
// Error message
ErrorMessage msg(locs, Severity::inconclusive_error, "Programming error", "errorId");
// Inconclusive error message
ErrorMessage msg(locs, Severity::error, "Programming error", "errorId", true);
// Don't save inconclusive messages if the xml version is 1
ASSERT_EQUALS("", msg.toXML(false, 1));