https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117873
Bug ID: 117873 Summary: Spurious -Wmaybe-uninitialized warnings with -O3 for static const std::regex Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: hewillk at gmail dot com Target Milestone: --- https://godbolt.org/z/Mh64vqGcs #include <regex> int main() { static const std::regex rgx{"hello"}; } compile with -O3 -fsanitize=address -Wall, GCC gives: In constructor 'std::function<_Res(_ArgTypes ...)>::function(std::function<_Res(_ArgTypes ...)>&&) [with _Res = bool; _ArgTypes = {char}]', inlined from 'std::__detail::_State<_Char_type>::_State(std::__detail::_State<_Char_type>&&) [with _Char_type = char]' at /opt/compiler-explorer/gcc-trunk-20241202/include/c++/15.0.0/bits/regex_automaton.h:152:4, inlined from 'std::__detail::_State<_Char_type>::_State(std::__detail::_State<_Char_type>&&) [with _Char_type = char]' at /opt/compiler-explorer/gcc-trunk-20241202/include/c++/15.0.0/bits/regex_automaton.h:149:7, inlined from 'std::__detail::_StateIdT std::__detail::_NFA<_TraitsT>::_M_insert_subexpr_end() [with _TraitsT = std::__cxx11::regex_traits<char>]' at /opt/compiler-explorer/gcc-trunk-20241202/include/c++/15.0.0/bits/regex_automaton.h:293:24: /opt/compiler-explorer/gcc-trunk-20241202/include/c++/15.0.0/bits/std_function.h:407:42: warning: '*(std::function<bool(char)>*)((char*)&__tmp + offsetof(std::__detail::_StateT, std::__detail::_State<char>::<unnamed>.std::__detail::_State_base::<unnamed>)).std::function<bool(char)>::_M_invoker' may be used uninitialized [-Wmaybe-uninitialized] 407 | : _Function_base(), _M_invoker(__x._M_invoker) | ~~~~^~~~~~~~~~