From patchwork Tue Dec 10 17:41:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Smith-Rowland, Edward M" X-Patchwork-Id: 1207185 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-515626-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=alionscience.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="bb6FBrRf"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47XS7336WJz9sRM for ; Wed, 11 Dec 2019 04:42:04 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:content-type:mime-version; q=dns; s=default; b=xJ84C7MVqRAstzb9iqij0mqs+DvOpCfZ8SSm6ey1iIDGKV3OqP e5lDNLrOerBitfZ2MDfX4Gtlolwm5YV6L0x7TG3jvUXE+qQ7IfJHOLuD/W3rv13t ZXLS4T/QF+vNwFjWtWx+Zx21rxAQHVApXYxD56NsjmMEJIyHoHvPYhe6s= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:content-type:mime-version; s= default; bh=OgIFn7rgB6QvRKhBXiDroL39Vmo=; b=bb6FBrRfc2kgn6J0e6kU 2IjIhoR08jWLvWv2FFC0D2bpe6DAF0J3D9f+nq4yv3TP/5cCUry7UifVSgmXdow2 50zUO4kn3r72CkXI1HoDMauqM4f/TiuB93LdFh45cVj0NIv1z84O1t5mTmN6feEL CVXeW3UZWO+mTf15vvkuL74= Received: (qmail 90052 invoked by alias); 10 Dec 2019 17:41:55 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 90036 invoked by uid 89); 10 Dec 2019 17:41:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=ello, Simply X-HELO: mfilt1.alionscience.com Received: from mfilt1.alionscience.com (HELO mfilt1.alionscience.com) (192.104.146.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 10 Dec 2019 17:41:49 +0000 Received: from mfilt1.alionscience.com (127.0.0.1) id htvcdq0171sj; Tue, 10 Dec 2019 12:41:47 -0500 (envelope-from ) Received: from noc-cas1.alionscience.com ([205.167.170.4]) by mfilt1.alionscience.com ([192.104.146.193]) (SonicWall 10.0.1.1213) with ESMTP id o201912101741470198537-74; Tue, 10 Dec 2019 12:41:47 -0500 Received: from NOC-MBX07.alionscience.com (172.20.3.236) by NOC-MBX07.alionscience.com (172.20.3.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1847.3; Tue, 10 Dec 2019 12:41:46 -0500 Received: from NOC-MBX07.alionscience.com ([fe80::5d9f:3f61:efe7:3b0e]) by NOC-MBX07.alionscience.com ([fe80::5d9f:3f61:efe7:3b0e%6]) with mapi id 15.01.1847.005; Tue, 10 Dec 2019 12:41:46 -0500 From: "Smith-Rowland, Edward M" To: "gcc-patches@gcc.gnu.org" , "libstdc++@gcc.gnu.org" , "jwakely@redhat.com" , "frs.dumont@gmail.com" CC: "Ed Smith-Rowland (3dw4rd@verizon.net)" <3dw4rd@verizon.net> Subject: [PATCH, libstdc++] Two parts of C++20 p1032... Date: Tue, 10 Dec 2019 17:41:46 +0000 Message-ID: <8074f1f285804d078727db1c89a6977c@alionscience.com> MIME-Version: 1.0 X-Mlf-DSE-Version: 5849 X-Mlf-Rules-Version: s20191206015617; ds20171117204456; di20191113190116; ri20160318003319; fs20191204192710 X-Mlf-Smartnet-Version: 20191105220248 X-Mlf-Version: 10.0.1.1213 X-Mlf-License: BSVKCAP____ X-Mlf-UniqueId: o201912101741470198537 These patches are modest reworkings of previous patches. The patch for char_traits was pretty much approved already.  But in response to a comment from François I at least added __copy_backwards, and used ptrdiff_t instead of size_t parameters and I put all the mem* wrappers in a __detail namespace. I didn't change some names. I know Jonathan wanted a bikeshed discussion. For the constexpr iterators I was asked to simplify the testsuite. Done. These would finish p1032 except for std::string::copy which I think should wait behind the rest of constexpr string. Another thing I need to do is respond to the SG-10 changes for the p1032 macros. There's one thing that bothers me still in light of the policy that these macros are names __cpp_lib_constexpr_HEADER: We sill have __cpp_lib_constexpr_algorithmS in . OK if these pass final retesting? Index: include/bits/stl_iterator.h =================================================================== --- include/bits/stl_iterator.h (revision 279174) +++ include/bits/stl_iterator.h (working copy) @@ -502,8 +502,12 @@ /// A nested typedef for the type of whatever container you used. typedef _Container container_type; +#if __cplusplus > 201703L + constexpr back_insert_iterator() noexcept = default; +#endif + /// The only way to create this %iterator is with a container. - explicit + explicit _GLIBCXX20_CONSTEXPR back_insert_iterator(_Container& __x) : container(std::__addressof(__x)) { } @@ -526,7 +530,7 @@ return *this; } #else - back_insert_iterator& + _GLIBCXX20_CONSTEXPR back_insert_iterator& operator=(const typename _Container::value_type& __value) { container->push_back(__value); @@ -533,7 +537,7 @@ return *this; } - back_insert_iterator& + _GLIBCXX20_CONSTEXPR back_insert_iterator& operator=(typename _Container::value_type&& __value) { container->push_back(std::move(__value)); @@ -542,17 +546,17 @@ #endif /// Simply returns *this. - back_insert_iterator& + _GLIBCXX20_CONSTEXPR back_insert_iterator& operator*() { return *this; } /// Simply returns *this. (This %iterator does not @a move.) - back_insert_iterator& + _GLIBCXX20_CONSTEXPR back_insert_iterator& operator++() { return *this; } /// Simply returns *this. (This %iterator does not @a move.) - back_insert_iterator + _GLIBCXX20_CONSTEXPR back_insert_iterator operator++(int) { return *this; } }; @@ -569,7 +573,7 @@ * types for you. */ template - inline back_insert_iterator<_Container> + inline _GLIBCXX20_CONSTEXPR back_insert_iterator<_Container> back_inserter(_Container& __x) { return back_insert_iterator<_Container>(__x); } @@ -594,8 +598,13 @@ /// A nested typedef for the type of whatever container you used. typedef _Container container_type; +#if __cplusplus > 201703L + constexpr front_insert_iterator() noexcept = default; +#endif + /// The only way to create this %iterator is with a container. - explicit front_insert_iterator(_Container& __x) + explicit _GLIBCXX20_CONSTEXPR + front_insert_iterator(_Container& __x) : container(std::__addressof(__x)) { } /** @@ -617,14 +626,13 @@ return *this; } #else - front_insert_iterator& + _GLIBCXX20_CONSTEXPR front_insert_iterator& operator=(const typename _Container::value_type& __value) { container->push_front(__value); return *this; } - - front_insert_iterator& + _GLIBCXX20_CONSTEXPR front_insert_iterator& operator=(typename _Container::value_type&& __value) { container->push_front(std::move(__value)); @@ -633,17 +641,17 @@ #endif /// Simply returns *this. - front_insert_iterator& + _GLIBCXX20_CONSTEXPR front_insert_iterator& operator*() { return *this; } /// Simply returns *this. (This %iterator does not @a move.) - front_insert_iterator& + _GLIBCXX20_CONSTEXPR front_insert_iterator& operator++() { return *this; } /// Simply returns *this. (This %iterator does not @a move.) - front_insert_iterator + _GLIBCXX20_CONSTEXPR front_insert_iterator operator++(int) { return *this; } }; @@ -660,7 +668,7 @@ * types for you. */ template - inline front_insert_iterator<_Container> + inline _GLIBCXX20_CONSTEXPR front_insert_iterator<_Container> front_inserter(_Container& __x) { return front_insert_iterator<_Container>(__x); } @@ -690,10 +698,15 @@ /// A nested typedef for the type of whatever container you used. typedef _Container container_type; +#if __cplusplus > 201703L + constexpr insert_iterator() = default; +#endif + /** * The only way to create this %iterator is with a container and an * initial position (a normal %iterator into the container). */ + _GLIBCXX20_CONSTEXPR insert_iterator(_Container& __x, typename _Container::iterator __i) : container(std::__addressof(__x)), iter(__i) {} @@ -729,7 +742,7 @@ return *this; } #else - insert_iterator& + _GLIBCXX20_CONSTEXPR insert_iterator& operator=(const typename _Container::value_type& __value) { iter = container->insert(iter, __value); @@ -737,7 +750,7 @@ return *this; } - insert_iterator& + _GLIBCXX20_CONSTEXPR insert_iterator& operator=(typename _Container::value_type&& __value) { iter = container->insert(iter, std::move(__value)); @@ -747,17 +760,17 @@ #endif /// Simply returns *this. - insert_iterator& + _GLIBCXX20_CONSTEXPR insert_iterator& operator*() { return *this; } /// Simply returns *this. (This %iterator does not @a move.) - insert_iterator& + _GLIBCXX20_CONSTEXPR insert_iterator& operator++() { return *this; } /// Simply returns *this. (This %iterator does not @a move.) - insert_iterator& + _GLIBCXX20_CONSTEXPR insert_iterator& operator++(int) { return *this; } }; @@ -775,7 +788,7 @@ * types for you. */ template - inline insert_iterator<_Container> + inline _GLIBCXX20_CONSTEXPR insert_iterator<_Container> inserter(_Container& __x, _Iterator __i) { return insert_iterator<_Container>(__x, Index: testsuite/24_iterators/back_insert_iterator/requirements/constexpr.cc =================================================================== --- testsuite/24_iterators/back_insert_iterator/requirements/constexpr.cc (nonexistent) +++ testsuite/24_iterators/back_insert_iterator/requirements/constexpr.cc (working copy) @@ -0,0 +1,67 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } +// +// Copyright (C) 2019 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 +// . + +#include +#include + +template + struct listoid + { + using value_type = Tp; + using iterator = size_t; + + constexpr listoid() = default; + + constexpr void push_back(const value_type& value) { return; } + constexpr void push_back(value_type&& value) { return; } + constexpr void push_front(const value_type& value) { return; } + constexpr void push_front(value_type&& value) { return; } + constexpr iterator insert(iterator pos, const value_type& value) { return pos; } + constexpr iterator begin() noexcept { return _M_begin; } + constexpr iterator end() noexcept { return _M_end; } + + private: + size_t _M_begin = 0; + size_t _M_end = 0; + }; + +constexpr bool +test() +{ + listoid l; + + auto ok = true; + const int route = 66; + + constexpr std::array b{89, 99}; + const std::back_insert_iterator> bi(l); + std::copy(b.begin(), b.end(), bi); + auto nbi = std::back_inserter(l); + nbi = route; + nbi = 77; + + return ok; +} + +int +main() +{ + static_assert(test()); +} Index: testsuite/24_iterators/insert_iterator/requirements/constexpr.cc =================================================================== --- testsuite/24_iterators/insert_iterator/requirements/constexpr.cc (nonexistent) +++ testsuite/24_iterators/insert_iterator/requirements/constexpr.cc (working copy) @@ -0,0 +1,68 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } +// +// Copyright (C) 2019 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 +// . + +#include +#include + +template + struct listoid + { + using value_type = Tp; + using iterator = size_t; + + constexpr listoid() = default; + + constexpr void push_back(const value_type& value) { return; } + constexpr void push_back(value_type&& value) { return; } + constexpr void push_front(const value_type& value) { return; } + constexpr void push_front(value_type&& value) { return; } + constexpr iterator insert(iterator pos, const value_type& value) { return pos; } + constexpr iterator begin() noexcept { return _M_begin; } + constexpr iterator end() noexcept { return _M_end; } + + private: + size_t _M_begin = 0; + size_t _M_end = 0; + }; + +constexpr bool +test() +{ + listoid l; + + auto ok = true; + const int route = 66; + + constexpr std::array a{1, 2, 3, 4, 5}; + const auto liter = l.begin() + 1; + const std::insert_iterator> ii(l, liter); + std::copy(a.begin(), a.end(), ii); + auto nii = std::inserter(l, liter); + nii = route; + nii = 77; + + return ok; +} + +int +main() +{ + static_assert(test()); +} Index: testsuite/24_iterators/front_insert_iterator/requirements/constexpr.cc =================================================================== --- testsuite/24_iterators/front_insert_iterator/requirements/constexpr.cc (nonexistent) +++ testsuite/24_iterators/front_insert_iterator/requirements/constexpr.cc (working copy) @@ -0,0 +1,67 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } +// +// Copyright (C) 2019 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 +// . + +#include +#include + +template + struct listoid + { + using value_type = Tp; + using iterator = size_t; + + constexpr listoid() = default; + + constexpr void push_back(const value_type& value) { return; } + constexpr void push_back(value_type&& value) { return; } + constexpr void push_front(const value_type& value) { return; } + constexpr void push_front(value_type&& value) { return; } + constexpr iterator insert(iterator pos, const value_type& value) { return pos; } + constexpr iterator begin() noexcept { return _M_begin; } + constexpr iterator end() noexcept { return _M_end; } + + private: + size_t _M_begin = 0; + size_t _M_end = 0; + }; + +constexpr bool +test() +{ + listoid l; + + auto ok = true; + const int route = 66; + + constexpr std::array f{-1, 0}; + const std::front_insert_iterator> fi(l); + std::copy(f.begin(), f.end(), fi); + auto nfi = std::front_inserter(l); + nfi = route; + nfi = 77; + + return ok; +} + +int +main() +{ + static_assert(test()); +} Index: testsuite/24_iterators/headers/iterator/synopsis_c++17.cc =================================================================== --- testsuite/24_iterators/headers/iterator/synopsis_c++17.cc (revision 279174) +++ testsuite/24_iterators/headers/iterator/synopsis_c++17.cc (working copy) @@ -1,5 +1,5 @@ // { dg-options "-std=gnu++17" } -// { dg-do compile } +// { dg-do compile { target c++17_only } } // { dg-require-normal-namespace "" } // Copyright (C) 2016-2019 Free Software Foundation, Inc. @@ -88,7 +88,7 @@ template constexpr reverse_iterator make_reverse_iterator(const Iterator&); - +#if __cplusplus == 201703L template class back_insert_iterator; template @@ -103,7 +103,7 @@ template insert_iterator inserter(Container& x, Iterator i); - +#endif template class move_iterator; template Index: testsuite/24_iterators/headers/iterator/synopsis_c++20.cc =================================================================== --- testsuite/24_iterators/headers/iterator/synopsis_c++20.cc (revision 279174) +++ testsuite/24_iterators/headers/iterator/synopsis_c++20.cc (working copy) @@ -76,6 +76,21 @@ struct iterator_traits>; struct unreachable_sentinel_t; + + template class back_insert_iterator; + + template + constexpr back_insert_iterator back_inserter(Container& x); + + template class front_insert_iterator; + + template + constexpr front_insert_iterator front_inserter(Container& x); + + template class insert_iterator; + + template + constexpr insert_iterator inserter(Container& x, Iterator i); } struct I { };