Uninitialized variables: warn about structs in C code
This commit is contained in:
parent
cf84c211ed
commit
dc6aa92f3b
|
@ -1055,7 +1055,7 @@ void CheckUninitVar::check()
|
||||||
void CheckUninitVar::checkScope(const Scope* scope)
|
void CheckUninitVar::checkScope(const Scope* scope)
|
||||||
{
|
{
|
||||||
for (std::list<Variable>::const_iterator i = scope->varlist.begin(); i != scope->varlist.end(); ++i) {
|
for (std::list<Variable>::const_iterator i = scope->varlist.begin(); i != scope->varlist.end(); ++i) {
|
||||||
if ((i->type() && !i->isPointer()) || i->isStatic() || i->isExtern() || i->isConst() || i->isArray() || i->isReference())
|
if ((_tokenizer->isCPP() && i->type() && !i->isPointer()) || i->isStatic() || i->isExtern() || i->isConst() || i->isArray() || i->isReference())
|
||||||
continue;
|
continue;
|
||||||
if (i->nameToken()->strAt(1) == "(")
|
if (i->nameToken()->strAt(1) == "(")
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -2373,6 +2373,16 @@ private:
|
||||||
// Assume dfs is a POD type if file is C
|
// Assume dfs is a POD type if file is C
|
||||||
checkUninitVar2(code, "test.c");
|
checkUninitVar2(code, "test.c");
|
||||||
ASSERT_EQUALS("[test.c:3]: (error) Uninitialized variable: a\n", errout.str());
|
ASSERT_EQUALS("[test.c:3]: (error) Uninitialized variable: a\n", errout.str());
|
||||||
|
|
||||||
|
const char code2[] = "struct AB { int a,b; };\n"
|
||||||
|
"void f() {\n"
|
||||||
|
" struct AB ab;\n"
|
||||||
|
" return ab;\n"
|
||||||
|
"}";
|
||||||
|
checkUninitVar2(code2, "test.cpp");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
checkUninitVar2(code2, "test.c");
|
||||||
|
ASSERT_EQUALS("[test.c:4]: (error) Uninitialized variable: ab\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handling of function calls
|
// Handling of function calls
|
||||||
|
|
Loading…
Reference in New Issue