File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1641,6 +1641,11 @@ void CheckUninitVar::valueFlowUninit()
16411641 const bool isarray = tok->variable ()->isArray ();
16421642 if (isarray && tok->variable ()->isMember ())
16431643 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+ }
16441649 const bool deref = CheckNullPointer::isPointerDeRef (tok, unknown, *mSettings );
16451650 uninitderef = deref && v->indirect == 0 ;
16461651 const bool isleaf = isLeafDot (tok) || uninitderef;
Original file line number Diff line number Diff line change @@ -6542,6 +6542,17 @@ class TestUninitVar : public TestFixture {
65426542 " [test.cpp:12]: (error) Uninitialized variable: b\n "
65436543 " [test.cpp:16]: (error) Uninitialized variable: a\n " ,
65446544 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 ());
65456556 }
65466557
65476558 void valueFlowUninitBreak () { // Do not show duplicate warnings about the same uninitialized value
You can’t perform that action at this time.
0 commit comments