[Bug c++/105749] New: Bogus maybe-unitialized when using std::optional, regex and sstream

hi+gccbugs at yamlcoder dot me gcc-bugzilla@gcc.gnu.org
Fri May 27 10:13:05 GMT 2022


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";
}


More information about the Gcc-bugs mailing list