Fixed false positive in fityk: operator new calling constructor
This commit is contained in:
parent
dd241501f3
commit
7364cc8040
|
@ -1495,9 +1495,12 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
|
||||||
*alloc = true;
|
*alloc = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (var.isPointer() && (_tokenizer->isC() || var.typeStartToken()->isStandardType() || (var.type() && var.type()->needInitialization == Type::True)) && Token::Match(tok->next(), "= new")) {
|
if (var.isPointer() && (var.typeStartToken()->isStandardType() || (var.type() && var.type()->needInitialization == Type::True)) && Token::Match(tok->next(), "= new")) {
|
||||||
if (alloc)
|
if (alloc) {
|
||||||
*alloc = true;
|
*alloc = true;
|
||||||
|
if (var.typeScope()->numConstructors > 0)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1455,21 +1455,28 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" Fred *fred = new Fred;\n"
|
" Fred *fred = new Fred;\n"
|
||||||
" fred->foo();\n"
|
" fred->foo();\n"
|
||||||
"};");
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkUninitVarB("struct Fred { int i; Fred(int, float); };\n"
|
||||||
|
"void f() {\n"
|
||||||
|
" Fred *fred = new Fred(1, 2);\n"
|
||||||
|
" fred->foo();\n"
|
||||||
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkUninitVarB("void f()\n"
|
checkUninitVarB("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" Fred *fred = malloc(sizeof(Fred));\n"
|
" Fred *fred = malloc(sizeof(Fred));\n"
|
||||||
" x(&fred->f);\n"
|
" x(&fred->f);\n"
|
||||||
"};");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkUninitVarB("void f()\n"
|
checkUninitVarB("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" Fred *fred = malloc(sizeof(Fred));\n"
|
" Fred *fred = malloc(sizeof(Fred));\n"
|
||||||
" x(fred->f);\n"
|
" x(fred->f);\n"
|
||||||
"};");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkUninitVarB("void foo(char *s)\n"
|
checkUninitVarB("void foo(char *s)\n"
|
||||||
|
|
Loading…
Reference in New Issue