CheckClass::copyconstructors: Use library to determine if function is a allocation function
This commit is contained in:
parent
eb922a140a
commit
1a9e8c158d
|
@ -288,14 +288,16 @@ void CheckClass::copyconstructors()
|
|||
continue;
|
||||
const Token* tok = func.token->linkAt(1);
|
||||
for (const Token* const end = func.functionScope->bodyStart; tok != end; tok = tok->next()) {
|
||||
if (Token::Match(tok, "%var% ( new|malloc|g_malloc|g_try_malloc|realloc|g_realloc|g_try_realloc")) {
|
||||
if (Token::Match(tok, "%var% ( new") ||
|
||||
(Token::Match(tok, "%var% ( %name% (") && _settings->library.alloc(tok->tokAt(2)))) {
|
||||
const Variable* var = tok->variable();
|
||||
if (var && var->isPointer() && var->scope() == scope)
|
||||
allocatedVars[tok->varId()] = tok;
|
||||
}
|
||||
}
|
||||
for (const Token* const end = func.functionScope->bodyEnd; tok != end; tok = tok->next()) {
|
||||
if (Token::Match(tok, "%var% = new|malloc|g_malloc|g_try_malloc|realloc|g_realloc|g_try_realloc")) {
|
||||
if (Token::Match(tok, "%var% = new") ||
|
||||
(Token::Match(tok, "%var% = %name% (") && _settings->library.alloc(tok->tokAt(2)))) {
|
||||
const Variable* var = tok->variable();
|
||||
if (var && var->isPointer() && var->scope() == scope && !var->isStatic())
|
||||
allocatedVars[tok->varId()] = tok;
|
||||
|
|
|
@ -38,6 +38,22 @@ private:
|
|||
settings0.addEnabled("style");
|
||||
settings1.addEnabled("warning");
|
||||
|
||||
// Load std.cfg configuration
|
||||
{
|
||||
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
|
||||
"<def>\n"
|
||||
" <memory>\n"
|
||||
" <alloc init=\"false\">malloc</alloc>\n"
|
||||
" <dealloc>free</dealloc>\n"
|
||||
" </memory>\n"
|
||||
"</def>";
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.Parse(xmldata, sizeof(xmldata));
|
||||
settings0.library.load(doc);
|
||||
settings1.library.load(doc);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE(virtualDestructor1); // Base class not found => no error
|
||||
TEST_CASE(virtualDestructor2); // Base class doesn't have a destructor
|
||||
TEST_CASE(virtualDestructor3); // Base class has a destructor, but it's not virtual
|
||||
|
|
Loading…
Reference in New Issue