Deactived bad message. Ticket #4154
This commit is contained in:
parent
25befccb26
commit
3ff792560f
|
@ -217,13 +217,16 @@ void CheckClass::copyconstructors()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// throw error if count mismatch
|
// throw error if count mismatch
|
||||||
|
/* FIXME: This doesn't work. See #4154
|
||||||
for (std::map<unsigned int, const Token*>::const_iterator i = allocatedVars.begin(); i != allocatedVars.end(); ++i) {
|
for (std::map<unsigned int, const Token*>::const_iterator i = allocatedVars.begin(); i != allocatedVars.end(); ++i) {
|
||||||
copyConstructorMallocError(copyCtor, i->second, i->second->str());
|
copyConstructorMallocError(copyCtor, i->second, i->second->str());
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This doesn't work. See #4154
|
||||||
void CheckClass::copyConstructorMallocError(const Token *cctor, const Token *alloc, const std::string& varname)
|
void CheckClass::copyConstructorMallocError(const Token *cctor, const Token *alloc, const std::string& varname)
|
||||||
{
|
{
|
||||||
std::list<const Token*> callstack;
|
std::list<const Token*> callstack;
|
||||||
|
@ -231,6 +234,7 @@ void CheckClass::copyConstructorMallocError(const Token *cctor, const Token *all
|
||||||
callstack.push_back(alloc);
|
callstack.push_back(alloc);
|
||||||
reportError(callstack, Severity::warning, "copyCtorNoAllocation", "Copy constructor does not allocate memory for member '" + varname + "' although memory has been allocated in other constructors.");
|
reportError(callstack, Severity::warning, "copyCtorNoAllocation", "Copy constructor does not allocate memory for member '" + varname + "' although memory has been allocated in other constructors.");
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
void CheckClass::copyConstructorShallowCopyError(const Token *tok, const std::string& varname)
|
void CheckClass::copyConstructorShallowCopyError(const Token *tok, const std::string& varname)
|
||||||
{
|
{
|
||||||
|
|
|
@ -123,7 +123,7 @@ private:
|
||||||
|
|
||||||
// Reporting errors..
|
// Reporting errors..
|
||||||
void noConstructorError(const Token *tok, const std::string &classname, bool isStruct);
|
void noConstructorError(const Token *tok, const std::string &classname, bool isStruct);
|
||||||
void copyConstructorMallocError(const Token *cctor, const Token *alloc, const std::string& var_name);
|
//void copyConstructorMallocError(const Token *cctor, const Token *alloc, const std::string& var_name);
|
||||||
void copyConstructorShallowCopyError(const Token *tok, const std::string& varname);
|
void copyConstructorShallowCopyError(const Token *tok, const std::string& varname);
|
||||||
void noCopyConstructorError(const Token *tok, const std::string &classname, bool isStruct);
|
void noCopyConstructorError(const Token *tok, const std::string &classname, bool isStruct);
|
||||||
void uninitVarError(const Token *tok, const std::string &classname, const std::string &varname);
|
void uninitVarError(const Token *tok, const std::string &classname, const std::string &varname);
|
||||||
|
@ -143,7 +143,7 @@ private:
|
||||||
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
|
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
|
||||||
CheckClass c(0, settings, errorLogger);
|
CheckClass c(0, settings, errorLogger);
|
||||||
c.noConstructorError(0, "classname", false);
|
c.noConstructorError(0, "classname", false);
|
||||||
c.copyConstructorMallocError(0, 0, "var");
|
//c.copyConstructorMallocError(0, 0, "var");
|
||||||
c.copyConstructorShallowCopyError(0, "var");
|
c.copyConstructorShallowCopyError(0, "var");
|
||||||
c.noCopyConstructorError(0, "class", false);
|
c.noCopyConstructorError(0, "class", false);
|
||||||
c.uninitVarError(0, "classname", "varname");
|
c.uninitVarError(0, "classname", "varname");
|
||||||
|
@ -168,7 +168,7 @@ private:
|
||||||
std::string classInfo() const {
|
std::string classInfo() const {
|
||||||
return "Check the code for each class.\n"
|
return "Check the code for each class.\n"
|
||||||
"* Missing constructors and copy constructors\n"
|
"* Missing constructors and copy constructors\n"
|
||||||
"* Missing allocation of memory in copy constructor\n"
|
//"* Missing allocation of memory in copy constructor\n"
|
||||||
"* Are all variables initialized by the constructors?\n"
|
"* Are all variables initialized by the constructors?\n"
|
||||||
"* Are all variables assigned by 'operator='?\n"
|
"* Are all variables assigned by 'operator='?\n"
|
||||||
"* Warn if memset, memcpy etc are used on a class\n"
|
"* Warn if memset, memcpy etc are used on a class\n"
|
||||||
|
|
|
@ -207,8 +207,10 @@ private:
|
||||||
" p = malloc(strlen(str)+1);\n"
|
" p = malloc(strlen(str)+1);\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\n"
|
TODO_ASSERT_EQUALS("[test.cpp:4]: (style) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\n"
|
||||||
"[test.cpp:3] -> [test.cpp:7]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\n", errout.str());
|
"[test.cpp:3] -> [test.cpp:7]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\n",
|
||||||
|
"[test.cpp:4]: (style) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\n"
|
||||||
|
, errout.str());
|
||||||
|
|
||||||
checkCopyConstructor("class F\n"
|
checkCopyConstructor("class F\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -223,8 +225,10 @@ private:
|
||||||
" strcpy(p,str);\n"
|
" strcpy(p,str);\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (style) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\n"
|
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\n"
|
||||||
"[test.cpp:5] -> [test.cpp:10]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\n", errout.str());
|
"[test.cpp:5] -> [test.cpp:10]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\n",
|
||||||
|
"[test.cpp:5]: (style) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\n"
|
||||||
|
, errout.str());
|
||||||
|
|
||||||
checkCopyConstructor("class kalci\n"
|
checkCopyConstructor("class kalci\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -272,7 +276,7 @@ private:
|
||||||
" strcpy(p,f.p);\n"
|
" strcpy(p,f.p);\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:14] -> [test.cpp:11]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\n", errout.str());
|
TODO_ASSERT_EQUALS("[test.cpp:14] -> [test.cpp:11]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\n", "", errout.str());
|
||||||
|
|
||||||
checkCopyConstructor("class F {\n"
|
checkCopyConstructor("class F {\n"
|
||||||
" char *c;\n"
|
" char *c;\n"
|
||||||
|
|
Loading…
Reference in New Issue