Fixed #9043 (false positive & regression: Variable '*s' is reassigned a value before the old one has been used.)
This commit is contained in:
parent
5579ea3338
commit
253f2c9e9d
|
@ -1424,6 +1424,9 @@ FwdAnalysis::Result FwdAnalysis::check(const Token *expr, const Token *startToke
|
||||||
if (unknownVarId)
|
if (unknownVarId)
|
||||||
return Result(FwdAnalysis::Result::Type::BAILOUT);
|
return Result(FwdAnalysis::Result::Type::BAILOUT);
|
||||||
|
|
||||||
|
if (mWhat == What::Reassign && isGlobalData(expr))
|
||||||
|
local = false;
|
||||||
|
|
||||||
// In unused values checking we do not want to check assignments to
|
// In unused values checking we do not want to check assignments to
|
||||||
// global data.
|
// global data.
|
||||||
if (mWhat == What::UnusedValue && isGlobalData(expr))
|
if (mWhat == What::UnusedValue && isGlobalData(expr))
|
||||||
|
|
|
@ -167,6 +167,7 @@ private:
|
||||||
TEST_CASE(redundantVarAssignment_lambda);
|
TEST_CASE(redundantVarAssignment_lambda);
|
||||||
TEST_CASE(redundantVarAssignment_for);
|
TEST_CASE(redundantVarAssignment_for);
|
||||||
TEST_CASE(redundantVarAssignment_after_switch);
|
TEST_CASE(redundantVarAssignment_after_switch);
|
||||||
|
TEST_CASE(redundantVarAssignment_pointer);
|
||||||
TEST_CASE(redundantVarAssignment_pointer_parameter);
|
TEST_CASE(redundantVarAssignment_pointer_parameter);
|
||||||
TEST_CASE(redundantMemWrite);
|
TEST_CASE(redundantMemWrite);
|
||||||
|
|
||||||
|
@ -6130,6 +6131,16 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:8]: (style) Variable 'ret' is reassigned a value before the old one has been used.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:8]: (style) Variable 'ret' is reassigned a value before the old one has been used.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void redundantVarAssignment_pointer() {
|
||||||
|
check("void f(int *ptr) {\n"
|
||||||
|
" int *x = ptr + 1;\n"
|
||||||
|
" *x = 23;\n"
|
||||||
|
" foo(ptr);\n"
|
||||||
|
" *x = 32;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void redundantVarAssignment_pointer_parameter() {
|
void redundantVarAssignment_pointer_parameter() {
|
||||||
check("void f(int *p) {\n"
|
check("void f(int *p) {\n"
|
||||||
" *p = 1;\n"
|
" *p = 1;\n"
|
||||||
|
|
Loading…
Reference in New Issue