Fixed false negative mentioned in #4354.
This commit is contained in:
parent
641ac5c02a
commit
ed477ceb74
|
@ -200,7 +200,15 @@ void CheckClass::copyconstructors()
|
|||
|
||||
for (std::list<Function>::const_iterator func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
|
||||
if (func->type == Function::eConstructor && func->functionScope) {
|
||||
for (const Token* tok = func->functionScope->classStart; tok!=func->functionScope->classEnd; tok=tok->next()) {
|
||||
const Token* tok = func->functionScope->classDef->linkAt(1);
|
||||
for (const Token* const end = func->functionScope->classStart; tok != end; tok = tok->next()) {
|
||||
if (Token::Match(tok, "%var% ( new|malloc|g_malloc|g_try_malloc|realloc|g_realloc|g_try_realloc")) {
|
||||
const Variable* var = tok->variable();
|
||||
if (var && var->isPointer() && var->scope() == &*scope)
|
||||
allocatedVars[tok->varId()] = tok;
|
||||
}
|
||||
}
|
||||
for (const Token* const end = func->functionScope->classEnd; tok != end; tok = tok->next()) {
|
||||
if (Token::Match(tok, "%var% = new|malloc|g_malloc|g_try_malloc|realloc|g_realloc|g_try_realloc")) {
|
||||
const Variable* var = tok->variable();
|
||||
if (var && var->isPointer() && var->scope() == &*scope)
|
||||
|
|
|
@ -374,7 +374,7 @@ private:
|
|||
" p = malloc(100);\n"
|
||||
" }\n"
|
||||
"};");
|
||||
TODO_ASSERT_EQUALS("[test.cpp:2]: (style) 'class F' does not have a copy constructor which is required since the class contains a pointer to allocated memory.\n", "", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:2]: (style) 'class F' does not have a copy constructor which is recommended since the class contains a pointer to allocated memory.\n", "", errout.str());
|
||||
|
||||
checkCopyConstructor("class F {\n"
|
||||
" char *p;\n"
|
||||
|
@ -384,6 +384,12 @@ private:
|
|||
" F(F& f);\n" // non-copyable
|
||||
"};");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkCopyConstructor("class F {\n"
|
||||
" char *p;\n"
|
||||
" F() : p(malloc(100)) {}\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("[test.cpp:1]: (style) 'class F' does not have a copy constructor which is recommended since the class contains a pointer to allocated memory.\n", errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue