errmsg: added "unused function"
This commit is contained in:
parent
631e202027
commit
3d8791eebd
2
Makefile
2
Makefile
|
@ -93,7 +93,7 @@ src/checkbufferoverrun.o: src/checkbufferoverrun.cpp src/checkbufferoverrun.h sr
|
|||
src/checkclass.o: src/checkclass.cpp src/checkclass.h src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/errormessage.h
|
||||
g++ $(CXXFLAGS) -c -o src/checkclass.o src/checkclass.cpp
|
||||
|
||||
src/checkfunctionusage.o: src/checkfunctionusage.cpp src/checkfunctionusage.h src/tokenize.h src/settings.h src/errorlogger.h src/token.h
|
||||
src/checkfunctionusage.o: src/checkfunctionusage.cpp src/checkfunctionusage.h src/tokenize.h src/settings.h src/errorlogger.h src/token.h src/errormessage.h
|
||||
g++ $(CXXFLAGS) -c -o src/checkfunctionusage.o src/checkfunctionusage.cpp
|
||||
|
||||
src/checkheaders.o: src/checkheaders.cpp src/checkheaders.h src/tokenize.h src/settings.h src/errorlogger.h src/token.h
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
//---------------------------------------------------------------------------
|
||||
#include "checkfunctionusage.h"
|
||||
#include "errormessage.h"
|
||||
#include "tokenize.h"
|
||||
#include <sstream>
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -150,11 +151,12 @@ void CheckFunctionUsage::check()
|
|||
continue;
|
||||
if (! func.usedSameFile)
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
if (func.filename != "+")
|
||||
errmsg << "[" << func.filename << "] ";
|
||||
errmsg << "The function '" << it->first << "' is never used.";
|
||||
_errorLogger->reportErr(errmsg.str());
|
||||
std::string filename;
|
||||
if (func.filename=="+")
|
||||
filename = "";
|
||||
else
|
||||
filename = func.filename;
|
||||
_errorLogger->reportErr(ErrorMessage::unusedFunction(0, 0, filename, it->first));
|
||||
}
|
||||
else if (! func.usedOtherFile)
|
||||
{
|
||||
|
|
|
@ -136,11 +136,6 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[])
|
|||
return oss.str();
|
||||
}
|
||||
|
||||
// Check function usage if "--style" and "--all" was given.
|
||||
// There will be false positives for exported library functions
|
||||
if (_settings._showAll && _settings._checkCodingStyle)
|
||||
_settings._checkFunctionUsage = true;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
@ -200,7 +195,7 @@ unsigned int CppCheck::check()
|
|||
|
||||
// This generates false positives - especially for libraries
|
||||
_settings._verbose = false;
|
||||
if (_settings._checkFunctionUsage)
|
||||
if (ErrorMessage::unusedFunction(_settings))
|
||||
{
|
||||
_errout.str("");
|
||||
if (_settings._errorsOnly == false)
|
||||
|
@ -260,7 +255,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
|||
_tokenizer.simplifyTokenList();
|
||||
|
||||
|
||||
if (_settings._checkFunctionUsage)
|
||||
if (ErrorMessage::unusedFunction(_settings))
|
||||
_checkFunctionUsage.parseTokens(_tokenizer);
|
||||
|
||||
// Class for detecting buffer overruns and related problems
|
||||
|
|
|
@ -111,6 +111,15 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
static std::string unusedFunction(const Tokenizer *tokenizer, const Token *Location, const std::string &filename, const std::string &funcname)
|
||||
{
|
||||
return msg1(tokenizer, Location) + "[" + filename + "]: The function '" + funcname + "' is never used";
|
||||
}
|
||||
static bool unusedFunction(const Settings &s)
|
||||
{
|
||||
return s._showAll & s._checkCodingStyle;
|
||||
}
|
||||
|
||||
static std::string mismatchAllocDealloc(const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
|
||||
{
|
||||
return msg1(tokenizer, Location) + "Mismatching allocation and deallocation: " + varname + "";
|
||||
|
|
|
@ -24,7 +24,6 @@ Settings::Settings()
|
|||
_showAll = false;
|
||||
_checkCodingStyle = false;
|
||||
_errorsOnly = false;
|
||||
_checkFunctionUsage = false;
|
||||
_verbose = false;
|
||||
_force = false;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ public:
|
|||
bool _showAll;
|
||||
bool _checkCodingStyle;
|
||||
bool _errorsOnly;
|
||||
bool _checkFunctionUsage;
|
||||
bool _verbose;
|
||||
|
||||
/** Force checking t he files with "too many" configurations. */
|
||||
|
|
|
@ -66,6 +66,9 @@ int main()
|
|||
err.push_back(Message("operatorEq", Message::STYLE, "'operator=' should return something"));
|
||||
err.push_back(Message("virtualDestructor", 0, "Class %1 which is inherited by class %2 does not have a virtual destructor", "Base", "Derived"));
|
||||
|
||||
// checkfunctionusage.cpp..
|
||||
err.push_back(Message("unusedFunction", Message::STYLE | Message::ALL, "[%1]: The function '%2' is never used", "filename", "funcname"));
|
||||
|
||||
// checkmemoryleak.cpp..
|
||||
err.push_back(Message("mismatchAllocDealloc", 0, "Mismatching allocation and deallocation: %1", "varname"));
|
||||
err.push_back(Message("memleak", 0, "Memory leak: %1", "varname"));
|
||||
|
|
Loading…
Reference in New Issue