errmsg: Added errormessage for 'the class 'classname' doesn't have a constructor'

This commit is contained in:
Daniel Marjamäki 2009-01-10 13:08:44 +00:00
parent 41a73e3b1e
commit 0c3c00daec
6 changed files with 20 additions and 8 deletions

View File

@ -89,7 +89,7 @@ install: cppcheck
src/checkbufferoverrun.o: src/checkbufferoverrun.cpp src/checkbufferoverrun.h src/tokenize.h src/settings.h src/errorlogger.h src/token.h
g++ $(CXXFLAGS) -c -o src/checkbufferoverrun.o src/checkbufferoverrun.cpp
src/checkclass.o: src/checkclass.cpp src/checkclass.h src/tokenize.h src/settings.h src/errorlogger.h src/token.h
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

View File

@ -19,6 +19,8 @@
//---------------------------------------------------------------------------
#include "checkclass.h"
#include "errormessage.h"
#include <locale>
#include <string>
@ -69,7 +71,7 @@ struct CheckClass::VAR *CheckClass::ClassChecking_GetVarList(const Token *tok1)
if (indentlevel != 1)
continue;
// "private:" "public:" "protected:" etc
// "private:" "public:" "protected:" etc
bool b = bool((*tok->strAt(0) != ':') && strchr(tok->strAt(0), ':') != 0);
// Search for start of statement..
@ -385,10 +387,7 @@ void CheckClass::constructors()
struct VAR *varlist = ClassChecking_GetVarList(tok1);
if (varlist)
{
std::ostringstream ostr;
ostr << _tokenizer->fileLine(tok1);
ostr << " The class '" << classNameToken->str() << "' has no constructor";
_errorLogger->reportErr(ostr.str());
_errorLogger->reportErr(ErrorMessage::noConstructor(_tokenizer, tok1, classNameToken->str()));
}
// Delete the varlist..
while (varlist)

View File

@ -271,7 +271,8 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
checkMemoryLeak.CheckMemoryLeak();
// Check that all class constructors are ok.
checkClass.constructors();
if (ErrorMessage::noConstructor(_settings))
checkClass.constructors();
// Check that all base classes have virtual destructors
checkClass.virtualDestructor();

View File

@ -30,6 +30,15 @@ private:
ErrorMessage() { }
static std::string msg1(const Tokenizer *tokenizer, const Token *Location);
public:
static std::string noConstructor(const Tokenizer *tokenizer, const Token *Location, const std::string &classname)
{
return msg1(tokenizer, Location) + "The class '" + classname + "' has no constructor";
}
static bool noConstructor(const Settings &s)
{
return s._checkCodingStyle;
}
static std::string memleak(const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
{
return msg1(tokenizer, Location) + "Memory leak: " + varname + "";

View File

@ -83,7 +83,7 @@ private:
" int i;\n"
"};\n");
std::string actual(errout.str());
std::string expected("[test.cpp:1] The class 'Fred' has no constructor\n");
std::string expected("[test.cpp:1]: The class 'Fred' has no constructor\n");
ASSERT_EQUALS(expected, actual);
}

View File

@ -50,6 +50,9 @@ int main()
// Error messages..
std::list<Message> err;
// checkclass.cpp..
err.push_back(Message("noConstructor", Message::STYLE, "The class '%1' has no constructor", "classname"));
// checkmemoryleak.cpp..
err.push_back(Message("memleak", 0, "Memory leak: %1", "varname"));
err.push_back(Message("resourceLeak", 0, "Resource leak: %1", "varname"));