From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B3A093858D33; Wed, 3 May 2023 20:40:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B3A093858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683146412; bh=DCLBgbEAeOVO/s1gvpFoqUGFt/Nd26x7L9bnfPLJPoI=; h=From:To:Subject:Date:From; b=ZwTTO2erCU6euQqZBHqy9mQ2FKu/IyUcS0BAV2J1mO7oKqlitA4S1E6+noFLTPP87 kQSoXclVp/64YwQLE+zN/MEpglZoeJUK0NiA4n539JHRJiy/1rez4jx5ApS5a4VaNr LkKYxEHJTW0w9UAe4WuLpD0bFzQFY4n1cc1oiKOw= From: "psmith at gnu dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109720] New: -Wmaybe-uninitialized triggering when I can see no path that would allow it Date: Wed, 03 May 2023 20:40:12 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: psmith at gnu dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109720 Bug ID: 109720 Summary: -Wmaybe-uninitialized triggering when I can see no path that would allow it Product: gcc Version: 13.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: psmith at gnu dot org Target Milestone: --- I recently upgraded to GCC 13.1 and when building some code that uses boost::dynamic_bitset I'm seeing the -Wmaybe-ininitialized warning triggeri= ng when it's impossible for any object of the class to be created without the m_num_bits field being initialized. I've tried to reduce this without luck. Also if I do other, seemingly irrelevant things then the warning goes away. I wonder if it's somehow rel= ated to the placement new that we use for the union...? I'll attach the postprocessed output. Code: DynamicBitSet set(200); size_t setup(size_t ln) { size_t count =3D 0; DynamicBitSet nbits(set); for (auto bit: nbits) { count +=3D bit; } return count; } I checked and this also failed in GCC 11.3; maybe -Wall didn't used to incl= ude this warning and now it does which is why I didn't notice it before? Results: $ /data/src/build/x86_64-linux/bin/x86_64-rl84-linux-gnu-g++ -I/data/src/build/common/boost/include -std=3Dgnu++20 -Wmaybe-uninitialized= -O2 -c -o /tmp/bitset.o /tmp/bitset.i In member function 'boost::dynamic_bitset::size_type boost::dynamic_bitset::size() const [with Block =3D long unsigned int; Allocator =3D std::allocator]', inlined from 'boost::dynamic_bitset::size_type boost::dynamic_bitset::find_next(size_type) const [with B= lock =3D long unsigned int; Allocator =3D std::allocator]' at /tmp/bitset.i:70473:30, inlined from 'DynamicBitSet::size_type DynamicBitSet::find_next(size_ty= pe) const' at /tmp/bitset.i:77301:44, inlined from 'DynamicBitSet::Iterator& DynamicBitSet::Iterator::operator++()' at /tmp/bitset.i:77325:38, inlined from 'size_t setup(size_t)' at /tmp/bitset.i:77340:20: /tmp/bitset.i:70355:12: warning: '*(const boost::dynamic_bitset >*)((char*)&nbits + offsetof(DynamicBitSet, DynamicBitSet::)).boost::dynamic_bitset<>::m_num_bits' may be used uninitialized [-Wmaybe-uninitialized] 70355 | return m_num_bits; | ^~~~~~~~~~ /tmp/bitset.i: In function 'size_t setup(size_t)': /tmp/bitset.i:77339:19: note: 'nbits' declared here 77339 | DynamicBitSet nbits(set); | ^~~~~=