Fixed false positive 'noCopyConstructor' for static member variable (#7198)

This commit is contained in:
PKEuS 2015-12-04 18:26:49 +01:00
parent 20b695d62d
commit 308fd1ba50
2 changed files with 10 additions and 1 deletions

View File

@ -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;
}
}

View File

@ -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());
}