public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Stephan Bergmann <sbergman@redhat.com>
To: gcc@gcc.gnu.org, libstdc++@gcc.gnu.org
Subject: More aggressive GCC 12 -Wmaybe-uninitialized when using <functional>
Date: Thu, 22 Jul 2021 11:19:26 +0200	[thread overview]
Message-ID: <2a9e7039-b23b-b0d6-c34f-56a1957df591@redhat.com> (raw)

Compared to GCC 11 (at least gcc-c++-11.1.1-3.fc34.x86_64), recent GCC 
12 trunk emits two "unhelpful" -Wmaybe-uninitialized for

> $ cat test.cc
> #include <functional>
> using fn = std::function<void()>;
> fn f(fn x) {
>     fn a;
>     a = x;
>     return x;
> }

> $ ~/gcc/trunk/inst/bin/g++ -c -Wmaybe-uninitialized -O2 test.cc
> In file included from ~/gcc/trunk/inst/include/c++/12.0.0/bits/stl_function.h:60,
>                  from ~/gcc/trunk/inst/include/c++/12.0.0/functional:49,
>                  from test.cc:1:
> In function ‘std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&) [with _Tp = void (*)(const std::_Any_data&)]’,
>     inlined from ‘void std::function<_Res(_ArgTypes ...)>::swap(std::function<_Res(_ArgTypes ...)>&) [with _Res = void; _ArgTypes = {}]’ at ~/gcc/trunk/inst/include/c++/12.0.0/bits/std_function.h:529:11,
>     inlined from ‘std::function<_Res(_ArgTypes ...)>& std::function<_Res(_ArgTypes ...)>::operator=(const std::function<_Res(_ArgTypes ...)>&) [with _Res = void; _ArgTypes = {}]’ at ~/gcc/trunk/inst/include/c++/12.0.0/bits/std_function.h:442:20,
>     inlined from ‘fn f(fn)’ at test.cc:5:9:
> ~/gcc/trunk/inst/include/c++/12.0.0/bits/move.h:204:11: warning: ‘<unnamed>.std::function<void()>::_M_invoker’ may be used uninitialized [-Wmaybe-uninitialized]
>   204 |       _Tp __tmp = _GLIBCXX_MOVE(__a);
>       |           ^~~~~
> In file included from ~/gcc/trunk/inst/include/c++/12.0.0/functional:59,
>                  from test.cc:1:
> ~/gcc/trunk/inst/include/c++/12.0.0/bits/std_function.h: In function ‘fn f(fn)’:
> ~/gcc/trunk/inst/include/c++/12.0.0/bits/std_function.h:442:9: note: ‘<anonymous>’ declared here
>   442 |         function(__x).swap(*this);
>       |         ^~~~~~~~~~~~~
> In file included from ~/gcc/trunk/inst/include/c++/12.0.0/bits/stl_function.h:60,
>                  from ~/gcc/trunk/inst/include/c++/12.0.0/functional:49,
>                  from test.cc:1:
> In function ‘std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&) [with _Tp = std::_Any_data]’,
>     inlined from ‘void std::function<_Res(_ArgTypes ...)>::swap(std::function<_Res(_ArgTypes ...)>&) [with _Res = void; _ArgTypes = {}]’ at ~/gcc/trunk/inst/include/c++/12.0.0/bits/std_function.h:527:11,
>     inlined from ‘std::function<_Res(_ArgTypes ...)>& std::function<_Res(_ArgTypes ...)>::operator=(const std::function<_Res(_ArgTypes ...)>&) [with _Res = void; _ArgTypes = {}]’ at ~/gcc/trunk/inst/include/c++/12.0.0/bits/std_function.h:442:20,
>     inlined from ‘fn f(fn)’ at test.cc:5:9:
> ~/gcc/trunk/inst/include/c++/12.0.0/bits/move.h:204:11: warning: ‘*(std::_Any_data*)((char*)&<unnamed> + offsetof(std::function, std::function<void()>::<unnamed>))’ may be used uninitialized [-Wmaybe-uninitialized]
>   204 |       _Tp __tmp = _GLIBCXX_MOVE(__a);
>       |           ^~~~~
> In file included from ~/gcc/trunk/inst/include/c++/12.0.0/functional:59,
>                  from test.cc:1:
> ~/gcc/trunk/inst/include/c++/12.0.0/bits/std_function.h: In function ‘fn f(fn)’:
> ~/gcc/trunk/inst/include/c++/12.0.0/bits/std_function.h:442:9: note: ‘<anonymous>’ declared here
>   442 |         function(__x).swap(*this);
>       |         ^~~~~~~~~~~~~

This appears to be an issue with more aggressive -Wmaybe-uninitialized 
in GCC 12 vs. 11, rather than an issue with changes to <functional> in 
libstdc++ 12 vs. 11, as effectively the same warnings are emitted when I 
use GCC 12 with libstdc++ 11 with

> $ ~/gcc/trunk/inst/bin/g++ -c -Wmaybe-uninitialized -O2 -nostdinc++ -isystem /usr/include/c++/11 -isystem /usr/include/c++/11/x86_64-redhat-linux test.cc

The warnings may technically be correct, and I'm not sure whether this 
is something that should be addressed in the GCC code emitting the 
warnings or in the libstdc++ <functional> implementation.

(I found this when building LibreOffice with recent GCC 12 trunk.)


             reply	other threads:[~2021-07-22  9:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-22  9:19 Stephan Bergmann [this message]
2021-07-22 10:03 ` Jonathan Wakely
2021-07-22 13:36   ` Jonathan Wakely
2021-07-23  9:58   ` Stephan Bergmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2a9e7039-b23b-b0d6-c34f-56a1957df591@redhat.com \
    --to=sbergman@redhat.com \
    --cc=gcc@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).