public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: gdb-patches@sourceware.org
Subject: Re: Oh dear. I regret to inform you that commit 'RAII-fy make_cleanup_restore_current_thread & friends' might be unfortunate
Date: Thu, 04 May 2017 21:49:00 -0000	[thread overview]
Message-ID: <dd8a708a-69ce-2126-331b-e7af8ca90d46@redhat.com> (raw)
In-Reply-To: <1fd4bf31-b0cd-3746-36d0-5f9f9e9dce4c@redhat.com>

On 05/04/2017 07:28 PM, Pedro Alves wrote:
> On 05/04/2017 07:22 PM, Pedro Alves wrote:
> 
>> AFAICS so far, this is a false positive.
>>
>> Not sure what to do.  I wouldn't want to force-memset
>> the optional's storage to work around it, which would be
>> a pessimization to quiet a warning.  From above, we see that
>> that wouldn't work when we later start using std::optional.
>>
>> There's a bug open about this (for boost::optional, but most
>> probably the exact same):
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78044
> 
> I've tried the reproducer there with the obvious change to use
> std::optional and that does not warn.  So this is a different,
> though related issue.
> 
> Or maybe there's really something wrong with the gdb code
> that is escaping me.

OK, here's smallest, self-contained reproducer I managed to
come up with:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//#include <optional>
#include <new>

template<typename T>
struct optional
{
  optional () : m_dummy () {}
  ~optional () { m_item.~T (); }
  void emplace () { new (&m_item) T (); }

  union
  {
    int m_dummy;
    T m_item;
  };
};

template <typename T>
using Optional = optional<T>; // warns
//using Optional = std::optional<T>; // warns too

extern int get ();
extern void set (int);

struct A
{
  A () : m (get ()) {}
  ~A () { set (m); }

  int m;
};

struct B
{
  B ();
  ~B ();
};

void func ()
{
  Optional<A> maybe_a;
  Optional<B> maybe_b;

  maybe_a.emplace ();
  maybe_b.emplace ();
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


$ /opt/gcc/bin/g++ optional.cc -g3 -O2 -Wmaybe-uninitialized -std=gnu++17 -c
optional.cc: In function ‘void func()’:
optional.cc:28:15: warning:
‘maybe_a.optional<A>::<anonymous>.optional<A>::<unnamed union>::m_dummy’
may be used uninitialized in this function [-Wmaybe-uninitialized]
   ~A () { set (m); }
           ~~~~^~~
optional.cc:41:15: note:
‘maybe_a.optional<A>::<anonymous>.optional<A>::<unnamed union>::m_dummy’
was declared here
   Optional<A> maybe_a;
               ^~~~~~~

Looks like a compiler bug to me.

Thanks,
Pedro Alves

  reply	other threads:[~2017-05-04 21:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <E1d6JGc-0000zB-OE@kwanyin.sergiodj.net>
2017-05-04 16:42 ` Pedro Alves
2017-05-04 18:15   ` Simon Marchi
2017-05-04 18:23     ` Pedro Alves
2017-05-04 18:29       ` Pedro Alves
2017-05-04 21:49         ` Pedro Alves [this message]
2017-05-04 22:36           ` Pedro Alves
2017-05-05  0:10       ` [pushed] gdb: Disable -Werror for -Wmaybe-uninitialized (Re: Oh dear. I regret to inform you that commit 'RAII-fy make_cleanup_restore_current_thread & friends' might be unfortunate) Pedro Alves

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=dd8a708a-69ce-2126-331b-e7af8ca90d46@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    /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).