parent
6ac804d209
commit
3bd5a034bd
|
@ -1356,7 +1356,8 @@ void CheckUnusedVar::checkFunctionVariableUsage()
|
|||
unassignedVariableError(usage._var->nameToken(), varname);
|
||||
}
|
||||
// variable has been read but not written
|
||||
else if (!usage._write && !usage._allocateMemory && var && !var->isStlType() && !isEmptyType(var->type()))
|
||||
else if (!usage._write && !usage._allocateMemory && var && !var->isStlType() && !isEmptyType(var->type()) &&
|
||||
!(var->type() && var->type()->needInitialization == Type::NeedInitialization::False))
|
||||
unassignedVariableError(usage._var->nameToken(), varname);
|
||||
else if (!usage._var->isMaybeUnused() && !usage._modified && !usage._read && var) {
|
||||
const Token* vnt = var->nameToken();
|
||||
|
|
|
@ -140,6 +140,7 @@ private:
|
|||
TEST_CASE(localvar67); // #9946
|
||||
TEST_CASE(localvar68);
|
||||
TEST_CASE(localvar69);
|
||||
TEST_CASE(localvar70);
|
||||
TEST_CASE(localvarloops); // loops
|
||||
TEST_CASE(localvaralias1);
|
||||
TEST_CASE(localvaralias2); // ticket #1637
|
||||
|
@ -3827,6 +3828,15 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localvar70() {
|
||||
functionVariableUsage("struct S { int i = 0; };\n" // #12176
|
||||
"void f(S s) {\n"
|
||||
" S s1;\n"
|
||||
" if (s == s1) {}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localvarloops() {
|
||||
// loops
|
||||
functionVariableUsage("void fun(int c) {\n"
|
||||
|
|
Loading…
Reference in New Issue