From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id E7E0A3857816 for ; Thu, 29 Oct 2020 23:48:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E7E0A3857816 Received: from mail-il1-f197.google.com (mail-il1-f197.google.com [209.85.166.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-296-e189JN7MPyakvkjUbfBpgQ-1; Thu, 29 Oct 2020 19:48:21 -0400 X-MC-Unique: e189JN7MPyakvkjUbfBpgQ-1 Received: by mail-il1-f197.google.com with SMTP id b6so3279192ilm.6 for ; Thu, 29 Oct 2020 16:48:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=Os0ugOHEH/xHswym970mno/KwfxR9jNVeSGQlNVPWFI=; b=WVQG6Mt5ms72NQ5NLEsdwm+sWx9mGNNS+TEOYoYncc4pPM16B9fQa7hfw6tRbPRJu+ xTkTHYE0rKxjXZceWiZrX44EJwDb+VPtpxSYF59tLTrKF8z/PhoxyiRZVzKvcuKimGYq 56ae3MCgyDqxh+HsCCES5RVYDvGKbaeBuA5aFrx0oBIR0rTb96CljJSh14a2LIjjv+rJ Et+NU4KdWvIGT00GOxK2IAHe3WqudEDfv4aP2aw+4bAZ+vEIDNgBq+Hcw0QxOxc48rhG XNs06BJAwSTiRZLyDZZnOLI1qxw0fkan1IU8Qqa2a9rhoZyKczo9wWbD0RyjnJx3y22V xI7w== X-Gm-Message-State: AOAM531k2Ns4HVO+nDB1cvQT9MUcTvlWLtjj9rUZKrrx9DSyh5cFH/k9 PJrloZxvgZ92/wf2LWE1W8CoUcB8g2zCd6K+ak9nsHT6jUcL/A3023SJBIf6A7BTdrTKiesw4Dt ZGlktyaO0aYA2kB0= X-Received: by 2002:a05:6602:228f:: with SMTP id d15mr5608161iod.10.1604015300659; Thu, 29 Oct 2020 16:48:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVB1P455f4JLTomPX22Qegc/uw9/MCY7+8rUtue34MbVNN2i+MIBd6aMYK3vve8z57wTTudg== X-Received: by 2002:a05:6602:228f:: with SMTP id d15mr5608151iod.10.1604015300430; Thu, 29 Oct 2020 16:48:20 -0700 (PDT) Received: from [192.168.1.130] (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id u1sm4346551ili.55.2020.10.29.16.48.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 16:48:19 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Thu, 29 Oct 2020 19:48:18 -0400 (EDT) To: Patrick Palka cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: Re: [PATCH] libstdc++: Fix the default constructor of ranges::__detail::__box In-Reply-To: <20201029231146.2538093-1-ppalka@redhat.com> Message-ID: <5b86a40-d458-26cc-4f5e-9191185eefab@idea> References: <20201029231146.2538093-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-14.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Oct 2020 23:48:25 -0000 On Thu, 29 Oct 2020, Patrick Palka wrote: > The class template semiregular-box 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 > which are already semiregular) does not. > > This patch fixes this issue, and additionally makes the in place > constructor explicit (as in the primary template). > > Tested on x86_64-pc-linux-gnu, does this look OK for trunk? > > libstdc++-v3/ChangeLog: > > * include/std/ranges (__detail::__box): For the partial > specialization for types that are already semiregular, > make the default constructor value-initialize the underlying > object instead of default-initializing it. Make the > corresponding in place constructor explicit. > * testsuite/std/ranges/detail/semiregular_box.cc: New test. > --- > libstdc++-v3/include/std/ranges | 4 +-- > .../std/ranges/detail/semiregular_box.cc | 33 +++++++++++++++++++ > 2 files changed, 35 insertions(+), 2 deletions(-) > create mode 100644 libstdc++-v3/testsuite/std/ranges/detail/semiregular_box.cc > > diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges > index df02b03cada..59aac326309 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 = {}; It would be more consistent with the rest of the header to do = _Tp() instead: Tested on x86_64-pc-linux-gnu. -- >8 -- --- libstdc++-v3/include/std/ranges | 4 +-- .../std/ranges/detail/semiregular_box.cc | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 libstdc++-v3/testsuite/std/ranges/detail/semiregular_box.cc diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index df02b03cada..579280d16fb 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 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/detail/semiregular_box.cc b/libstdc++-v3/testsuite/std/ranges/detail/semiregular_box.cc new file mode 100644 index 00000000000..2a909d6ae50 --- /dev/null +++ b/libstdc++-v3/testsuite/std/ranges/detail/semiregular_box.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +using std::ranges::__detail::__box; + +constexpr bool +test01() +{ + // Verify the default constructor value-initializes the underlying object. + __box x; + __glibcxx_assert(*x == 0); + return true; +} +static_assert(test01()); -- 2.29.0.rc0