public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: "François Dumont" <frs.dumont@gmail.com>
Cc: "libstdc++@gcc.gnu.org" <libstdc++@gcc.gnu.org>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: Default std::vector<bool> default and move constructor
Date: Thu, 01 Jun 2017 13:34:00 -0000	[thread overview]
Message-ID: <20170601133402.GU12306@redhat.com> (raw)
In-Reply-To: <164fb25b-dedc-21f4-9305-f68c47fa58df@gmail.com>

On 31/05/17 22:28 +0200, François Dumont wrote:
>Unless I made a mistake it revealed that restoring explicit call to 
>_Bit_alloc_type() in default constructor was not enough. G++ doesn't 
>transform it into a value-init if needed. I don't know if it is a 
>compiler bug but I had to do just like presented in the Standard to 
>achieve the expected behavior.

That really shouldn't be necessary (see blow).

>This value-init is specific to post-C++11 right ? Maybe I could remove 
>the useless explicit call to _Bit_alloc_type() in pre-C++11 mode ?

No, because C++03 also requires the allocator to be value-initialized.

>Now I wonder if I really introduced a regression in rb_tree...

Yes, I think you did. Could you try to verify that using the new
default_init_allocator?


>+      struct _Bvector_impl
>+	: public _Bit_alloc_type, public _Bvector_impl_data
>+	{
>+	public:
>+#if __cplusplus >= 201103L
>+	  _Bvector_impl()
>+	    noexcept( noexcept(_Bit_alloc_type())
>+		      && noexcept(_Bvector_impl(declval<const _Bit_alloc_type&>())) )

This second condition is not needed, because that constructor should
be noexcept (see below).

>+	  : _Bvector_impl(_Bit_alloc_type())

This should not be necessary...

>+	  { }
>+#else
> 	  _Bvector_impl()
>-	: _Bit_alloc_type(), _M_start(), _M_finish(), _M_end_of_storage()
>+	  : _Bit_alloc_type()
> 	  { }
>+#endif

I would expect the constructor to look like this:

	  _Bvector_impl()
	  _GLIBCXX_NOEXCEPT_IF( noexcept(_Bit_alloc_type()) )
          : _Bit_alloc_type()
          { }

What happens when you do that?


> 	  _Bvector_impl(const _Bit_alloc_type& __a)
>-	: _Bit_alloc_type(__a), _M_start(), _M_finish(), _M_end_of_storage()
>+	     _GLIBCXX_NOEXCEPT_IF( noexcept(_Bit_alloc_type(__a)) )

Copying the allocator is not allowed to throw. You can use simply
_GLIBCXX_NOEXCEPT here.


>+void test01()
>+{
>+  typedef default_init_allocator<T> alloc_type;
>+  typedef std::vector<T, alloc_type> test_type;
>+
>+  test_type v1;
>+  v1.push_back(T());
>+
>+  VERIFY( !v1.empty() );
>+  VERIFY( !v1.get_allocator().state );

This is unlikely to ever fail, because the stack is probably full of
zeros anyway. Did you confirm whether the test fails without your
fixes to value-initialize the allocator?

One possible way to make it fail would be to construct the
vector<bool> using placement new, into a buffer filled with non-zero
values. (Valgrind or a sanitizer should also tell us, but we can't
rely on them in the testsuite).

  reply	other threads:[~2017-06-01 13:34 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-15 18:38 François Dumont
2017-05-15 19:36 ` Marc Glisse
2017-05-16 20:38   ` François Dumont
2017-05-16 21:39     ` Marc Glisse
2017-05-19 19:42   ` François Dumont
2017-05-23 20:14     ` François Dumont
2017-05-25 16:33 ` Jonathan Wakely
2017-05-26 21:34   ` François Dumont
2017-05-27 11:16     ` Jonathan Wakely
2017-05-28 20:29       ` François Dumont
2017-05-29 20:57         ` François Dumont
2017-05-31 10:37           ` Jonathan Wakely
2017-05-31 20:34             ` François Dumont
2017-06-01 13:34               ` Jonathan Wakely [this message]
2017-06-01 20:49                 ` François Dumont
2017-06-02 10:27                   ` Jonathan Wakely
2017-06-13 20:36                 ` François Dumont
2017-06-15 11:07                   ` Jonathan Wakely
2017-05-31 11:13         ` Jonathan Wakely

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=20170601133402.GU12306@redhat.com \
    --to=jwakely@redhat.com \
    --cc=frs.dumont@gmail.com \
    --cc=gcc-patches@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).