From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 05BCC3858D32; Mon, 26 Dec 2022 19:02:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 05BCC3858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1672081353; bh=xSkQhnezZ/O8lY9K2hFmgfqNVCjjC2CeTw2ShJceOe0=; h=From:To:Subject:Date:From; b=tVt9AzT75y9v2fWle/OlirkuwOEIAXYzm6Phb0Q11CpgE/r8vShfhZbVxCaqcroQy ZcBk+tczvGKn1ULTyZWtIBp1d2C66Y1oYSR1ixIYd43rNogYYgepbYPCEJ7ExKpvfC 9k+vetP5ihMUs27MPl6p+Y5pjDmwglTXKxuU8KAw= From: "shin.david at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/108230] New: assert() spuriously activates maybe-initialized warning Date: Mon, 26 Dec 2022 19:02:32 +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: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: shin.david at gmail dot com 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=3D108230 Bug ID: 108230 Summary: assert() spuriously activates maybe-initialized warning Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: shin.david at gmail dot com Target Milestone: --- gcc-12.2 reports a maybe-uninitialized warning for the last line of the bel= ow code if-and-only-if the macro ADD_ASSERT is defined: #include #include using Array =3D Eigen::Array; struct Tree { Array array; std::bitset<8> bitset; }; auto func(Tree* tree) { int c =3D tree->array.rows(); int d =3D tree->bitset.count(); #ifdef ADD_ASSERT assert(c=3D=3Dd); #endif // ADD_ASSERT Array e(c); for (int k =3D 0; k < d; ++k) e(k) =3D k; return e.sum() / (e + 1); } int main() { Tree tree; func(&tree); } This is a bug because adding this assert() should have no bearing on whethe= r or not the return statement might entail uninitialized memory usage. gcc cmd1, generates warning: -Wmaybe-uninitialized -O3 -DADD_ASSERT gcc cmd2, no warning: -Wmaybe-uninitialized -O3 Godbolt link, which includes full gcc warning output: https://godbolt.org/z/nv11aaKb6 This example, convoluted as it seems, appears to be a minimal reproducible example. For example: - Removing the for-loop makes the warning appear with both gcc cmds - Replacing the return expression with something simpler like (e + 1) makes= the warning disappear with both gcc cmds - Replacing std::bitset with something else also makes the warning disappear with both gcc cmds Eigen library version is 3.4.0.=