diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 195cc5b71..b0dd6cb32 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -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; } } diff --git a/test/testclass.cpp b/test/testclass.cpp index b0fa1063b..089fd5927 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -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()); }