public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r11-4575] libstdc++: Fix the default constructor of ranges::__detail::__box
Date: Fri, 30 Oct 2020 16:33:55 +0000 (GMT)	[thread overview]
Message-ID: <20201030163355.5DC863857C7B@sourceware.org> (raw)

https://gcc.gnu.org/g:f3ced6772e2257bdef4e6f4dbdd0bdcf34b5bb3f

commit r11-4575-gf3ced6772e2257bdef4e6f4dbdd0bdcf34b5bb3f
Author: Patrick Palka <ppalka@redhat.com>
Date:   Fri Oct 30 12:33:13 2020 -0400

    libstdc++: Fix the default constructor of ranges::__detail::__box
    
    The class template semiregular-box<T> of [range.semi.wrap] is specified
    to value-initialize the underlying object whenever its type is default
    initializable.  Our primary template for __detail::__box respects this
    requirement, but the recently added partial specialization (for types
    that are already semiregular) does not.
    
    This patch fixes this issue, and additionally makes the corresponding in
    place constructor explicit (as in the primary template).
    
    libstdc++-v3/ChangeLog:
    
            * include/std/ranges (__detail::__box): For the partial
            specialization used by types that are already semiregular,
            make the default constructor value-initialize the underlying
            object instead of default-initializing it.  Make its in place
            constructor explicit.
            * testsuite/std/ranges/adaptors/detail/semiregular_box.cc:
            Augment test.

Diff:
---
 libstdc++-v3/include/std/ranges                                |  4 ++--
 .../testsuite/std/ranges/adaptors/detail/semiregular_box.cc    | 10 ++++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index a3e5354848a..610083167d8 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -141,7 +141,7 @@ namespace ranges
       struct __box<_Tp>
       {
       private:
-	[[no_unique_address]] _Tp _M_value;
+	[[no_unique_address]] _Tp _M_value = _Tp();
 
       public:
 	__box() = default;
@@ -160,7 +160,7 @@ namespace ranges
 
 	template<typename... _Args>
 	  requires constructible_from<_Tp, _Args...>
-	  constexpr
+	  constexpr explicit
 	  __box(in_place_t, _Args&&... __args)
 	  noexcept(is_nothrow_constructible_v<_Tp, _Args...>)
 	  : _M_value{std::forward<_Args>(__args)...}
diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/detail/semiregular_box.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/detail/semiregular_box.cc
index 392acff3eb6..748137f7e33 100644
--- a/libstdc++-v3/testsuite/std/ranges/adaptors/detail/semiregular_box.cc
+++ b/libstdc++-v3/testsuite/std/ranges/adaptors/detail/semiregular_box.cc
@@ -71,3 +71,13 @@ static_assert(requires (__box<U> a) {
   a.operator->();
   a.has_value();
 });
+
+constexpr bool
+test01()
+{
+  // Verify the default constructor value-initializes the underlying object.
+  __box<int> x;
+  __glibcxx_assert(*x == 0);
+  return true;
+}
+static_assert(test01());


                 reply	other threads:[~2020-10-30 16:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20201030163355.5DC863857C7B@sourceware.org \
    --to=ppalka@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@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).