Added --debug-warnings that we can use to enable various debug warnings
This commit is contained in:
parent
8eee4cf2e8
commit
d45186d645
|
@ -76,7 +76,7 @@ void CheckClass::createSymbolDatabase()
|
||||||
// only create variable list and base list if not namespace
|
// only create variable list and base list if not namespace
|
||||||
if (!new_info->isNamespace)
|
if (!new_info->isNamespace)
|
||||||
{
|
{
|
||||||
new_info->getVarList();
|
new_info->getVarList(_settings->debugwarnings);
|
||||||
|
|
||||||
// goto initial '{'
|
// goto initial '{'
|
||||||
tok2 = initBaseInfo(new_info, tok);
|
tok2 = initBaseInfo(new_info, tok);
|
||||||
|
@ -417,7 +417,7 @@ const Token *CheckClass::initBaseInfo(SpaceInfo *info, const Token *tok)
|
||||||
return tok2;
|
return tok2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckClass::SpaceInfo::getVarList()
|
void CheckClass::SpaceInfo::getVarList(bool debugwarnings)
|
||||||
{
|
{
|
||||||
// Get variable list..
|
// Get variable list..
|
||||||
const Token *tok1 = classDef;
|
const Token *tok1 = classDef;
|
||||||
|
@ -629,9 +629,9 @@ void CheckClass::SpaceInfo::getVarList()
|
||||||
// If the vartok was set in the if-blocks above, create a entry for this variable..
|
// If the vartok was set in the if-blocks above, create a entry for this variable..
|
||||||
if (vartok && vartok->str() != "operator")
|
if (vartok && vartok->str() != "operator")
|
||||||
{
|
{
|
||||||
if (vartok->varId() == 0)
|
if (vartok->varId() == 0 && debugwarnings)
|
||||||
{
|
{
|
||||||
check->reportError(vartok, Severity::error, "cppcheckError", "Internal error. CheckClass::SpaceInfo::getVarList found variable \'" + vartok->str() + "\' with varid 0.");
|
check->reportError(vartok, Severity::debug, "debug", "CheckClass::SpaceInfo::getVarList found variable \'" + vartok->str() + "\' with varid 0.");
|
||||||
}
|
}
|
||||||
|
|
||||||
varlist.push_back(Var(vartok, false, varaccess, isMutable, isStatic, isClass));
|
varlist.push_back(Var(vartok, false, varaccess, isMutable, isStatic, isClass));
|
||||||
|
|
|
@ -241,7 +241,7 @@ private:
|
||||||
void markAllVar(bool value);
|
void markAllVar(bool value);
|
||||||
|
|
||||||
/** @brief initialize varlist */
|
/** @brief initialize varlist */
|
||||||
void getVarList();
|
void getVarList(bool debugwarnings);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief parse a scope for a constructor or member function and set the "init" flags in the provided varlist
|
* @brief parse a scope for a constructor or member function and set the "init" flags in the provided varlist
|
||||||
|
|
|
@ -2153,7 +2153,7 @@ void CheckMemoryLeakInFunction::checkScope(const Token *Tok1, const std::string
|
||||||
|
|
||||||
simplifycode(tok);
|
simplifycode(tok);
|
||||||
|
|
||||||
if (_settings->_debug && _settings->_verbose)
|
if (_settings->debug && _settings->_verbose)
|
||||||
{
|
{
|
||||||
tok->printOut(("Checkmemoryleak: simplifycode result for: " + varname).c_str());
|
tok->printOut(("Checkmemoryleak: simplifycode result for: " + varname).c_str());
|
||||||
}
|
}
|
||||||
|
@ -2183,7 +2183,7 @@ void CheckMemoryLeakInFunction::checkScope(const Token *Tok1, const std::string
|
||||||
}
|
}
|
||||||
|
|
||||||
// detect cases that "simplifycode" don't handle well..
|
// detect cases that "simplifycode" don't handle well..
|
||||||
else if (_settings->_debug)
|
else if (_settings->debugwarnings)
|
||||||
{
|
{
|
||||||
Token *first = tok;
|
Token *first = tok;
|
||||||
while (first && first->str() == ";")
|
while (first && first->str() == ";")
|
||||||
|
@ -2204,10 +2204,11 @@ void CheckMemoryLeakInFunction::checkScope(const Token *Tok1, const std::string
|
||||||
// Unhandled case..
|
// Unhandled case..
|
||||||
if (! noerr)
|
if (! noerr)
|
||||||
{
|
{
|
||||||
std::cout << "Token listing..\n ";
|
std::ostringstream errmsg;
|
||||||
|
errmsg << "inconclusive leak: ";
|
||||||
for (const Token *tok2 = tok; tok2; tok2 = tok2->next())
|
for (const Token *tok2 = tok; tok2; tok2 = tok2->next())
|
||||||
std::cout << " " << tok2->str();
|
errmsg << " " << tok2->str();
|
||||||
std::cout << "\n";
|
reportError(_tokenizer->tokens(), Severity::debug, "debug", errmsg.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -246,7 +246,11 @@ bool CppCheck::parseFromArgs(int argc, const char* const argv[])
|
||||||
|
|
||||||
// Flag used for various purposes during debugging
|
// Flag used for various purposes during debugging
|
||||||
else if (strcmp(argv[i], "--debug") == 0)
|
else if (strcmp(argv[i], "--debug") == 0)
|
||||||
_settings._debug = true;
|
_settings.debug = _settings.debugwarnings = true;
|
||||||
|
|
||||||
|
// Show debug warnings
|
||||||
|
else if (strcmp(argv[i], "--debug-warnings") == 0)
|
||||||
|
_settings.debugwarnings = true;
|
||||||
|
|
||||||
// Inconclusive checking - keep this for compatibility but don't
|
// Inconclusive checking - keep this for compatibility but don't
|
||||||
// handle it
|
// handle it
|
||||||
|
|
|
@ -1030,8 +1030,12 @@ std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const
|
||||||
if (unhandled)
|
if (unhandled)
|
||||||
{
|
{
|
||||||
// unhandled ifdef configuration..
|
// unhandled ifdef configuration..
|
||||||
if (_errorLogger && _settings && _settings->_debug)
|
if (_errorLogger && _settings && _settings->debugwarnings)
|
||||||
_errorLogger->reportOut("unhandled configuration: " + *it);
|
{
|
||||||
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
||||||
|
const ErrorLogger::ErrorMessage errmsg(locationList, Severity::debug, "unhandled configuration: " + *it, "debug");
|
||||||
|
_errorLogger->reportErr(errmsg);
|
||||||
|
}
|
||||||
|
|
||||||
ret.erase(it++);
|
ret.erase(it++);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
Settings::Settings()
|
Settings::Settings()
|
||||||
{
|
{
|
||||||
_debug = false;
|
debug = debugwarnings = false;
|
||||||
_checkCodingStyle = false;
|
_checkCodingStyle = false;
|
||||||
_errorsOnly = false;
|
_errorsOnly = false;
|
||||||
_inlineSuppressions = false;
|
_inlineSuppressions = false;
|
||||||
|
|
|
@ -49,7 +49,10 @@ public:
|
||||||
Settings();
|
Settings();
|
||||||
|
|
||||||
/** @brief Is --debug given? */
|
/** @brief Is --debug given? */
|
||||||
bool _debug;
|
bool debug;
|
||||||
|
|
||||||
|
/** @brief Is --debug-warnings given? */
|
||||||
|
bool debugwarnings;
|
||||||
|
|
||||||
/** @brief Inconclusive checks - for debugging of Cppcheck */
|
/** @brief Inconclusive checks - for debugging of Cppcheck */
|
||||||
bool inconclusive;
|
bool inconclusive;
|
||||||
|
|
|
@ -637,7 +637,15 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name)
|
||||||
|
|
||||||
void Tokenizer::unsupportedTypedef(const Token *tok) const
|
void Tokenizer::unsupportedTypedef(const Token *tok) const
|
||||||
{
|
{
|
||||||
#ifndef NDEBUG
|
// ###### The ifdef will be removed soon - the message will only be shown if --debug-warnings are given. #######
|
||||||
|
#ifdef NDEBUG
|
||||||
|
if (!_settings)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!_settings->debugwarnings)
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
std::ostringstream str;
|
std::ostringstream str;
|
||||||
const Token *tok1 = tok;
|
const Token *tok1 = tok;
|
||||||
while (tok && tok->str() != ";")
|
while (tok && tok->str() != ";")
|
||||||
|
@ -656,15 +664,14 @@ void Tokenizer::unsupportedTypedef(const Token *tok) const
|
||||||
locationList.push_back(loc);
|
locationList.push_back(loc);
|
||||||
|
|
||||||
const ErrorLogger::ErrorMessage errmsg(locationList,
|
const ErrorLogger::ErrorMessage errmsg(locationList,
|
||||||
Severity::error,
|
Severity::debug,
|
||||||
"Failed to parse \'" + str.str() + "\'. The checking continues anyway.",
|
"Failed to parse \'" + str.str() + "\'. The checking continues anyway.",
|
||||||
"cppcheckError");
|
"debug");
|
||||||
|
|
||||||
if (_errorLogger)
|
if (_errorLogger)
|
||||||
_errorLogger->reportErr(errmsg);
|
_errorLogger->reportErr(errmsg);
|
||||||
else
|
else
|
||||||
Check::reportError(errmsg);
|
Check::reportError(errmsg);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SpaceInfo
|
struct SpaceInfo
|
||||||
|
@ -2405,19 +2412,25 @@ void Tokenizer::simplifyTemplates()
|
||||||
namepos = 3;
|
namepos = 3;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifndef NDEBUG
|
|
||||||
// debug message that we bail out..
|
// debug message that we bail out..
|
||||||
if (_settings && _settings->_debug)
|
if (_settings && _settings->debugwarnings)
|
||||||
{
|
{
|
||||||
std::cout << "simplifyTemplates debug-information: bailing out: "
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
||||||
<< file(tok->tokAt(namepos))
|
ErrorLogger::ErrorMessage::FileLocation loc;
|
||||||
<< ": "
|
loc.line = tok->linenr();
|
||||||
<< tok->tokAt(namepos)->linenr()
|
loc.setfile(file(tok));
|
||||||
<< ": "
|
locationList.push_back(loc);
|
||||||
<< tok->tokAt(namepos)->str()
|
|
||||||
<< std::endl;
|
const ErrorLogger::ErrorMessage errmsg(locationList,
|
||||||
|
Severity::debug,
|
||||||
|
"simplifyTemplates: bailing out",
|
||||||
|
"debug");
|
||||||
|
|
||||||
|
if (_errorLogger)
|
||||||
|
_errorLogger->reportErr(errmsg);
|
||||||
|
else
|
||||||
|
Check::reportError(errmsg);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((tok->tokAt(namepos)->str() == "*" || tok->tokAt(namepos)->str() == "&"))
|
if ((tok->tokAt(namepos)->str() == "*" || tok->tokAt(namepos)->str() == "&"))
|
||||||
|
@ -3910,7 +3923,7 @@ bool Tokenizer::simplifyTokenList()
|
||||||
removeRedundantAssignment();
|
removeRedundantAssignment();
|
||||||
|
|
||||||
simplifyComma();
|
simplifyComma();
|
||||||
if (_settings && _settings->_debug)
|
if (_settings && _settings->debug)
|
||||||
{
|
{
|
||||||
_tokens->printOut(0, _files);
|
_tokens->printOut(0, _files);
|
||||||
}
|
}
|
||||||
|
|
|
@ -741,7 +741,7 @@ private:
|
||||||
{
|
{
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings._debug = true;
|
settings.debug = settings.debugwarnings = true;
|
||||||
Tokenizer tokenizer(&settings, NULL);
|
Tokenizer tokenizer(&settings, NULL);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
tokenizer.tokenize(istr, "test.cpp");
|
||||||
|
|
|
@ -1082,7 +1082,7 @@ private:
|
||||||
std::istringstream istr(filedata);
|
std::istringstream istr(filedata);
|
||||||
std::map<std::string, std::string> actual;
|
std::map<std::string, std::string> actual;
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings._debug = true;
|
settings.debug = settings.debugwarnings = true;
|
||||||
settings._verbose = true;
|
settings._verbose = true;
|
||||||
Preprocessor preprocessor(&settings, this);
|
Preprocessor preprocessor(&settings, this);
|
||||||
preprocessor.preprocess(istr, actual, "file.c");
|
preprocessor.preprocess(istr, actual, "file.c");
|
||||||
|
@ -1092,7 +1092,7 @@ private:
|
||||||
ASSERT_EQUALS("\n\n\n", actual[""]);
|
ASSERT_EQUALS("\n\n\n", actual[""]);
|
||||||
|
|
||||||
// the "defined(DEF_10) || defined(DEF_11)" are not handled correctly..
|
// the "defined(DEF_10) || defined(DEF_11)" are not handled correctly..
|
||||||
ASSERT_EQUALS("unhandled configuration: defined(DEF_10)||defined(DEF_11)\n", output.str());
|
ASSERT_EQUALS("(debug) unhandled configuration: defined(DEF_10)||defined(DEF_11)\n", errout.str());
|
||||||
TODO_ASSERT_EQUALS(2, actual.size());
|
TODO_ASSERT_EQUALS(2, actual.size());
|
||||||
TODO_ASSERT_EQUALS("\na1;\n\n", actual["DEF_10"]);
|
TODO_ASSERT_EQUALS("\na1;\n\n", actual["DEF_10"]);
|
||||||
|
|
||||||
|
|
|
@ -3704,6 +3704,7 @@ private:
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.inconclusive = true;
|
settings.inconclusive = true;
|
||||||
settings._checkCodingStyle = true;
|
settings._checkCodingStyle = true;
|
||||||
|
settings.debugwarnings = true; // show warnings about unhandled typedef
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
@ -4236,11 +4237,7 @@ private:
|
||||||
|
|
||||||
// this is invalid C so just make sure it doesn't crash
|
// this is invalid C so just make sure it doesn't crash
|
||||||
checkSimplifyTypedef(code);
|
checkSimplifyTypedef(code);
|
||||||
#ifndef NDEBUG
|
ASSERT_EQUALS("[test.cpp:1]: (debug) Failed to parse 'typedef int ( * int ( * ) ( ) ) ( ) ;'. The checking continues anyway.\n", errout.str());
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (error) Failed to parse 'typedef int ( * int ( * ) ( ) ) ( ) ;'. The checking continues anyway.\n", errout.str());
|
|
||||||
#else
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue