From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5866F3951C36; Thu, 15 Oct 2020 18:02:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5866F3951C36 From: "cuzdav at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/80635] [8/9/10/11 regression] std::optional and bogus -Wmaybe-uninitialized warning Date: Thu, 15 Oct 2020 18:02:31 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 8.2.0 X-Bugzilla-Keywords: diagnostic, patch X-Bugzilla-Severity: normal X-Bugzilla-Who: cuzdav at gmail dot com X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: law at redhat dot com X-Bugzilla-Target-Milestone: 8.5 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Oct 2020 18:02:32 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D80635 Chris Uzdavinis changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |cuzdav at gmail dot com --- Comment #54 from Chris Uzdavinis --- I'm not sure if this is the same bug or a different one, but it's in the sa= me family (I think). Visible in current trunk, 10.2 release, and as far back = as 8.1. I found optimize level -Os is necessary=20 https://godbolt.org/z/Ta55jM #include using Opt =3D std::optional; Opt f(int x) {=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 Opt ret;=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 Opt val =3D (x =3D=3D 1) ? 999 : (x =3D=3D 2) ? Opt(2) : std::nullopt; if (val.has_value()) ret =3D val.value(); return ret; } : In function 'Opt f(int)': :9:12: error: 'val.std::_Optional_payload_base::_Storage::_M_value' may be used uninitialized in this function [-Werror=3Dmaybe-uninitialized] 9 | return ret; | ^~~=