File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -1641,6 +1641,11 @@ void CheckUninitVar::valueFlowUninit()
1641
1641
const bool isarray = tok->variable ()->isArray ();
1642
1642
if (isarray && tok->variable ()->isMember ())
1643
1643
continue ; // Todo: this is a bailout
1644
+ if (isarray && tok->variable ()->isStlType () && Token::simpleMatch (tok->astParent (), " ." )) {
1645
+ const auto yield = astContainerYield (tok);
1646
+ if (yield != Library::Container::Yield::AT_INDEX && yield != Library::Container::Yield::ITEM)
1647
+ continue ;
1648
+ }
1644
1649
const bool deref = CheckNullPointer::isPointerDeRef (tok, unknown, *mSettings );
1645
1650
uninitderef = deref && v->indirect == 0 ;
1646
1651
const bool isleaf = isLeafDot (tok) || uninitderef;
Original file line number Diff line number Diff line change @@ -6542,6 +6542,17 @@ class TestUninitVar : public TestFixture {
6542
6542
" [test.cpp:12]: (error) Uninitialized variable: b\n "
6543
6543
" [test.cpp:16]: (error) Uninitialized variable: a\n " ,
6544
6544
errout_str ());
6545
+
6546
+ valueFlowUninit (" void f() {\n " // # 12932
6547
+ " std::array<int, 0> a;\n "
6548
+ " if (a.begin() == a.end()) {}\n "
6549
+ " std::array<int, 1> b;\n "
6550
+ " auto it = b.begin();\n "
6551
+ " *it = 0;\n "
6552
+ " std::array<int, 1> c;\n "
6553
+ " return c.front();\n "
6554
+ " }\n " );
6555
+ ASSERT_EQUALS (" [test.cpp:8]: (error) Uninitialized variable: c\n " , errout_str ());
6545
6556
}
6546
6557
6547
6558
void valueFlowUninitBreak () { // Do not show duplicate warnings about the same uninitialized value
You can’t perform that action at this time.
0 commit comments