Tootsie
Tootsie

Reputation: 909

Compiling std::regex with libasan produces 'uninitialized' warnings

Compiling the following code:

#include <regex>

int main()
{
    static const std::regex rgx{"some string"};
}

Produces lots of 'uninitialized' compiler warnings if compiled with the following flags:

g++ -O3 -fsanitize=address -Wall test.cpp

Without any of these optional flags, compilation is silent (-fsanitize=address requires libasan)

In file included from /usr/include/c++/14/regex:50,
                 from test.cpp:1:
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 /usr/include/c++/14/bits/regex_automaton.h:149:4,
    inlined from ‘std::__detail::_State<_Char_type>::_State(std::__detail::_State<_Char_type>&&) [with _Char_type = char]’ at /usr/include/c++/14/bits/regex_automaton.h:146:7,
    inlined from ‘std::__detail::_StateIdT std::__detail::_NFA<_TraitsT>::_M_insert_subexpr_end() [with _TraitsT = std::__cxx11::regex_traits<char>]’ at /usr/include/c++/14/bits/regex_automaton.h:290:24:
/usr/include/c++/14/bits/std_function.h:405: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]
  405 |       : _Function_base(), _M_invoker(__x._M_invoker)
      |                                      ~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/regex:65:
/usr/include/c++/14/bits/regex_automaton.h: In member function ‘std::__detail::_StateIdT std::__detail::_NFA<_TraitsT>::_M_insert_subexpr_end() [with _TraitsT = std::__cxx11::regex_traits<char>]’:
/usr/include/c++/14/bits/regex_automaton.h:287:17: note: ‘__tmp’ declared here
  287 |         _StateT __tmp(_S_opcode_subexpr_end);
      |                 ^~~~~

These are only the first 10 of >200 lines giving this warning: '*(const std::_Function_base*)((char*)&__tmp + offsetof(std::__detail::_StateT, std::__detail::_State<char>::<unnamed>.std::__detail::_State_base::<unnamed>)).std::_Function_base::_M_manager' may be used uninitialized warning.

Platform is Fedora 41

$ g++ --version
g++ (GCC) 14.2.1 20240912 (Red Hat 14.2.1-3)

At the end, compilation succeeds and a binary is produced.
What could cause these compiler warnings ?

Upvotes: 1

Views: 90

Answers (0)

Related Questions