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 3D8F73857816 for ; Thu, 29 Oct 2020 23:11:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3D8F73857816 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-358-zh_WoJQCOjGccMwRfi5PTg-1; Thu, 29 Oct 2020 19:11:50 -0400 X-MC-Unique: zh_WoJQCOjGccMwRfi5PTg-1 Received: by mail-il1-f197.google.com with SMTP id g14so3209450ilr.7 for ; Thu, 29 Oct 2020 16:11:50 -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:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5HFeg1XRAjE1aNuWNofOJZI3VbYajd4D2SC3NhLNGBs=; b=GGqsWJCue/UtK5kCsLv8Jjs4nYQgBJ70pDSPiT1OBhSF3+wDe3JamQekvMXy1iWkjs uWAuMWmudQjJrnxqSW+DFegtHcgviPKFWmu5DXvApgwtlMwtuGSlMbI2qX+NReBSrb9E 4/iGzb+hvhoXTZ/w/QblI+hzu5VOt0b9JPpn5PGM1C0eza/DnwQ0G64aTXtr/+Rdc+5B /T8h4nGZEOdpmASB1uMNL+j/yg/qt0sQftkZMYqOgeuafKUa/IUFEXCMfZeHcyKgY51t d37L6OaI6pzkyNRPNDxpygVUlExT8CxxJB1DhCPli5L4g2C3htPWU+Fh3YqgmmAdQaXg JW7A== X-Gm-Message-State: AOAM531ZLE75ONc0lmBxmB60bYp9fOQFo8xVqCaclSFmRDRhvtMyVih+ L9fezYLRJ2YPzIAWYKYF7Nf4ieBGwc0a9QJ3lG0tOYb6Op5pCSTsi61KQsQusOOQgl6DUfhR50p skpGgS33laIAUh7E= X-Received: by 2002:a6b:e40f:: with SMTP id u15mr5254869iog.88.1604013109806; Thu, 29 Oct 2020 16:11:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+Gw8dtX8dEOgg8hj4gUF7K0ztEohEDQNoxhb+vdLBUOJT7yDDVRgK23HmggUAAIE+gaVzNQ== X-Received: by 2002:a6b:e40f:: with SMTP id u15mr5254860iog.88.1604013109608; Thu, 29 Oct 2020 16:11:49 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id h13sm3319690ile.79.2020.10.29.16.11.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 16:11:48 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH] libstdc++: Fix the default constructor of ranges::__detail::__box Date: Thu, 29 Oct 2020 19:11:46 -0400 Message-Id: <20201029231146.2538093-1-ppalka@redhat.com> X-Mailer: git-send-email 2.29.0.rc0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-16.3 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:11:54 -0000 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 = {}; 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