Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler warning with -Wmaybe-uninitialized when using Fedora 36 and gcc 12.1.1 #2423

Closed
bryancall opened this issue May 13, 2022 · 3 comments

Comments

@bryancall
Copy link

Describe the bug
Compiler warning with maybe-uninitialized when using Fedora 36 and gcc 12.1.1. Fedora 35 and an older version of gcc works. I am curious if anyone else has run into this issue before.

Expected behavior
I expect it to build without warnings.

Reproduction steps
Build ATS on Fedora 36 and turn on -Werror and build the unit tests with make test

Platform information:

  • OS: Fedora 36
  • Compiler+version: gcc 12.1.1
  • Catch version: 2.13.8 and 2.13.9

Additional context
Here is a link to our issue of the problem: apache/trafficserver#8848

Compiler error

  CXX      unit_tests/freelist_benchmark-freelist_benchmark.o
In file included from /usr/include/c++/12/functional:59,
                 from /home/bcall/dev/apache/trafficserver/build-Linux_gcc/../tests/include/catch.hpp:3483,
                 from ../../../src/tscore/unit_tests/freelist_benchmark.cc:25:
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++/12/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++/12/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++/12/bits/regex_automaton.h:290:24:
/usr/include/c++/12/bits/std_function.h:405:42: error: ‘*(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 [-Werror=maybe-uninitialized]
  405 |       : _Function_base(), _M_invoker(__x._M_invoker)
      |                                      ~~~~^~~~~~~~~~
In file included from /usr/include/c++/12/regex:63,
                 from /home/bcall/dev/apache/trafficserver/build-Linux_gcc/../tests/include/catch.hpp:11706:
/usr/include/c++/12/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++/12/bits/regex_automaton.h:287:17: note: ‘__tmp’ declared here
  287 |         _StateT __tmp(_S_opcode_subexpr_end);
      |                 ^~~~~
In member function ‘bool std::_Function_base::_M_empty() const’,
    inlined from ‘std::function<_Res(_ArgTypes ...)>::operator bool() const [with _Res = bool; _ArgTypes = {char}]’ at /usr/include/c++/12/bits/std_function.h:574:25,
    inlined from ‘std::function<_Res(_ArgTypes ...)>::function(std::function<_Res(_ArgTypes ...)>&&) [with _Res = bool; _ArgTypes = {char}]’ at /usr/include/c++/12/bits/std_function.h:407:6,
    inlined from ‘std::__detail::_State<_Char_type>::_State(std::__detail::_State<_Char_type>&&) [with _Char_type = char]’ at /usr/include/c++/12/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++/12/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++/12/bits/regex_automaton.h:290:24:
/usr/include/c++/12/bits/std_function.h:247:37: error: ‘*(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 [-Werror=maybe-uninitialized]
  247 |     bool _M_empty() const { return !_M_manager; }
      |                                     ^~~~~~~~~~
/usr/include/c++/12/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++/12/bits/regex_automaton.h:287:17: note: ‘__tmp’ declared here
  287 |         _StateT __tmp(_S_opcode_subexpr_end);
      |                 ^~~~~
cc1plus: all warnings being treated as errors

Patch to get around this issue

+#pragma GCC diagnostic error "-Wmaybe-uninitialized"
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
 #include <functional>
+#pragma GCC diagnostic pop
+#pragma GCC diagnostic pop
@olbender
Copy link

Also got it in Arch Linux with gcc 12.1.0.

@complexoctonion
Copy link

This seems to be a bug in gcc 12.1.0, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105562

@horenmar
Copy link
Member

Yeah I am not suppressing warning in system header caused by overeager compiler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants