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

GCC 12 emits -Wuninitialized warnings #42

Closed
jngrad opened this issue May 30, 2022 · 2 comments
Closed

GCC 12 emits -Wuninitialized warnings #42

jngrad opened this issue May 30, 2022 · 2 comments

Comments

@jngrad
Copy link
Contributor

jngrad commented May 30, 2022

The GCC -Wmaybe-uninitialized warning reported in #27 was silenced by a diagnostic pragma in #38, however in GCC 12 the warning has become -Wuninitialized. Reproducible on Fedora with gcc-c++-12.0.1-0.16.fc36 and gcc-c++-12.1.1-1.fc37. Probably relevant part of the GCC 12 changelog: Eliminating uninitialized variables.

MWE:

#include <boost/test/unit_test.hpp>

struct my_precondition {
  boost::test_tools::assertion_result operator()(boost::unit_test::test_unit_id) {
    return false;
  }
};

BOOST_TEST_DECORATOR(*boost::unit_test::precondition(my_precondition()))
BOOST_AUTO_TEST_CASE(my_test) {
}

Output (live example):

$ g++ -Wall -O3 -c mwe.cpp
In file included from /usr/include/boost/function/detail/maybe_include.hpp:22,
                 from /usr/include/boost/function/function1.hpp:11,
                 from /usr/include/boost/test/tree/decorator.hpp:30,
                 from /usr/include/boost/test/tools/fpc_tolerance.hpp:19,
                 from /usr/include/boost/test/tools/fpc_op.hpp:19,
                 from /usr/include/boost/test/test_tools.hpp:54,
                 from /usr/include/boost/test/unit_test.hpp:18,
                 from mwe.cpp:1:
In member function ‘void boost::function1<R, T1>::assign_to_own(const boost::function1<R, T1>&) [with R = boost::test_tools::assertion_result; T0 = long unsigned int]’,
    inlined from ‘boost::function1<R, T1>::function1(const boost::function1<R, T1>&) [with R = boost::test_tools::assertion_result; T0 = long unsigned int]’ at /usr/include/boost/function/function_template.hpp:746:26,
    inlined from ‘boost::function<R(T0)>::function(const self_type&) [with R = boost::test_tools::assertion_result; T0 = long unsigned int]’ at /usr/include/boost/function/function_template.hpp:1105:76,
    inlined from ‘boost::unit_test::decorator::precondition::precondition(predicate_t)’ at /usr/include/boost/test/tree/decorator.hpp:280:61,
    inlined from ‘void __static_initialization_and_destruction_0(int, int)’ at mwe.cpp:9:1,
    inlined from ‘(static initializers for mwe.cpp)’ at mwe.cpp:11:1:
/usr/include/boost/function/function_template.hpp:910:22: warning: ‘*(unsigned char (*)[24])((char*)&<unnamed> + offsetof(boost::predicate_t, boost::function<boost::test_tools::assertion_result(long unsigned int)>::<unnamed>.boost::function1<boost::test_tools::assertion_result, long unsigned int>::<unnamed>.boost::function_base::functor))’ is used uninitialized [-Wuninitialized]
  910 |           std::memcpy(this->functor.data, f.functor.data, sizeof(boost::detail::function::function_buffer));
      |           ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/boost/test/unit_test.hpp:19:
mwe.cpp: In function ‘(static initializers for mwe.cpp)’:
mwe.cpp:9:71: note: ‘<anonymous>’ declared here
    9 | BOOST_TEST_DECORATOR(*boost::unit_test::precondition(my_precondition()))
      |                                                                       ^
@pdimov
Copy link
Member

pdimov commented May 30, 2022

Fixed by a variation of #43.

@pdimov pdimov closed this as completed May 30, 2022
@jngrad
Copy link
Contributor Author

jngrad commented May 30, 2022

Fixed by 5b4e279.

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

Successfully merging a pull request may close this issue.

2 participants