Java: fixed false positives about uninitialized variable
This commit is contained in:
parent
5deb046ac5
commit
120073f000
|
@ -743,7 +743,7 @@ void CheckClass::SpaceInfo::getVarList()
|
|||
}
|
||||
|
||||
// If the vartok was set in the if-blocks above, create a entry for this variable..
|
||||
if (vartok && vartok->str() != "operator")
|
||||
if (vartok && vartok->str() != "operator" && !Token::Match(vartok->next(), "; %varid% =", vartok->varId()))
|
||||
{
|
||||
if (vartok->varId() == 0 && check->_settings->debugwarnings)
|
||||
{
|
||||
|
|
|
@ -81,6 +81,7 @@ private:
|
|||
TEST_CASE(uninitFunction3); // No FP when initialized in function
|
||||
TEST_CASE(uninitSameClassName); // No FP when two classes have the same name
|
||||
TEST_CASE(uninitFunctionOverload); // No FP when there are overloaded functions
|
||||
TEST_CASE(uninitJava); // Java: no FP when variable is initialized in declaration
|
||||
|
||||
TEST_CASE(noConstructor1);
|
||||
TEST_CASE(noConstructor2);
|
||||
|
@ -2228,6 +2229,15 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void uninitJava()
|
||||
{
|
||||
checkUninitVar("class A {\n"
|
||||
" private: int i = 0;\n"
|
||||
" public: A() { }\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
void checkNoConstructor(const char code[])
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue