From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 65FA23949089; Fri, 27 May 2022 10:13:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 65FA23949089 From: "hi+gccbugs at yamlcoder dot me" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/105749] New: Bogus maybe-unitialized when using std::optional, regex and sstream Date: Fri, 27 May 2022 10:13:05 +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.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: hi+gccbugs at yamlcoder dot me 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 attachments.created 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 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: Fri, 27 May 2022 10:13:05 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105749 Bug ID: 105749 Summary: Bogus maybe-unitialized when using std::optional, regex and sstream Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: hi+gccbugs at yamlcoder dot me Target Milestone: --- Created attachment 53044 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D53044&action=3Dedit t.ii reproducer Compiling following with -Wall -Werror -Os produces bogus=20 maybe-unitialized warning /tmp/t.cpp: In function =E2=80=98void t(const string&)=E2=80=99: /tmp/t.cpp:12:51: error: =E2=80=98*(int*)((char*)&port + offsetof(std::optional,std::optional::.std::_Optional_ba= se::))=E2=80=99 may be used uninitialized in this function [-Werror=3Dmaybe-uninitialized] 12 | reqb << "Host: " << port.value_or(443) << "\r\n"; Attaching .ii (tar.gz due to attachment limit) file from 11.2.0, but it is = also reproducible on trunk in godbolt: https://godbolt.org/z/ha3vn61n9 Interesting that commenting unrelated parts or changing them slightly makes warning go away. #include #include #include void t(const std::string& i) { const std::regex re("^$"); //removing this works std::optional port(i.length() > 0 ? std::make_optional(std::strtol("99", nullptr, 10)) : std::nullopt); std::ostringstream reqb; reqb << "GET /" << i << " HTTP/1.1" << "\r\n"; //removing this works reqb << "Host: " << port.value_or(443) << "\r\n"; }=