public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105749] New: Bogus maybe-unitialized when using std::optional, regex and sstream
@ 2022-05-27 10:13 hi+gccbugs at yamlcoder dot me
  2022-06-22 20:20 ` [Bug tree-optimization/105749] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: hi+gccbugs at yamlcoder dot me @ 2022-05-27 10:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105749

            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=53044&action=edit
t.ii reproducer

Compiling following with -Wall -Werror -Os produces bogus 
maybe-unitialized warning


/tmp/t.cpp: In function ‘void t(const string&)’:
/tmp/t.cpp:12:51: error: ‘*(int*)((char*)&port +
offsetof(std::optional<int>,std::optional<int>::<unnamed>.std::_Optional_base<int,
true, true>::<unnamed>))’ may be used uninitialized in this function
[-Werror=maybe-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 <regex>
#include <optional>
#include <sstream>

void t(const std::string& i) {
        const std::regex re("^$"); //removing this works

        std::optional<int> 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";
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-09-22 13:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-27 10:13 [Bug c++/105749] New: Bogus maybe-unitialized when using std::optional, regex and sstream hi+gccbugs at yamlcoder dot me
2022-06-22 20:20 ` [Bug tree-optimization/105749] " pinskia at gcc dot gnu.org
2022-06-22 20:23 ` pinskia at gcc dot gnu.org
2022-06-22 20:24 ` pinskia at gcc dot gnu.org
2022-09-22 13:25 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).