From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id AB5BE3858C50; Mon, 17 Oct 2022 15:01:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AB5BE3858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666018918; bh=pbOuvzkpCwSd9KbqLUlIWmc+dHKvtDa0SZQokQrCaAo=; h=From:To:Subject:Date:From; b=tCzl/hGi2NzeGGTdjRWYRTkrk+uh6aCP0LFOcJNwjEvK3dO1zK2X8VGLaEgg93OlW 8cBY8iGK1yAnWf++k26QNngC6HHDmRqz77+yx421uWW+hw0H2HlB4mKD/dy9SXBKci euwRRQHELG+aZf08K5LIt1+zqJRb9h7rq+kBSV5I= From: "jzwinck at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug sanitizer/107298] New: Failure to compile code with std::optional and ASan/UBSan Date: Mon, 17 Oct 2022 15:01:54 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: sanitizer X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jzwinck 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 cc 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=3D107298 Bug ID: 107298 Summary: Failure to compile code with std::optional and ASan/UBSan Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: sanitizer Assignee: unassigned at gcc dot gnu.org Reporter: jzwinck at gmail dot com CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org, jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxi= n at gcc dot gnu.org Target Milestone: --- Test case which is expected to compile: #include std::optional f(bool cond) { if (cond) { return std::make_optional(true); } return {}; } bool g() { return *f(true); } GCC 10, 11 and 12 all fail to compile this with "-Wall -Wextra -Werror -O2 -fsanitize=3Dundefined": error: '*(unsigned char*)((char*)& + offsetof(std::optional,std::optional::.std::_Optional_= base::))' may be used uninitialized [-Werror=3Dmaybe-uninitialized] return {}; Removing std::make_optional or replacing it with std::optional makes = the error go away, though these changes should be irrelevant since they're not = on the code path the compiler complains about. Compiling without a sanitizer = also works fine. Demo: https://godbolt.org/z/TafE9cxWW=