Fixed false positive 'noCopyConstructor' for static member variable (#7198)
This commit is contained in:
parent
20b695d62d
commit
308fd1ba50
|
@ -289,7 +289,7 @@ void CheckClass::copyconstructors()
|
|||
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)
|
||||
if (var && var->isPointer() && var->scope() == scope && !var->isStatic())
|
||||
allocatedVars[tok->varId()] = tok;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -595,6 +595,15 @@ private:
|
|||
" 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());
|
||||
|
||||
// #7198
|
||||
checkCopyConstructor("struct F {\n"
|
||||
" static char* c;\n"
|
||||
" F() {\n"
|
||||
" p = malloc(100);\n"
|
||||
" }\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue