From patchwork Tue Feb 11 15:54:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1236358 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-519349-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=YGUQDn4H; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bR3wKte6; 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 48H6lr5Dhkz9s29 for ; Wed, 12 Feb 2020 02:54:31 +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:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=Bxz3d76GRsq3BssG AV+/yyT46ZgU18YsOYSx6DHOaM4izUb2FA8k3raPnE6Cd44IUNLXoVs0T946Hvb7 mVFVXaYd+LdMNcdSoQBoaoIdH/0DL9dzw8C9Ne+OCIR65YquYfgeAxZsZLBUj72G gKfh+jCtTQ948WkHUYycnoOEQww= 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:mime-version:content-type :content-transfer-encoding; s=default; bh=+GKQVL+dkj9gR1uMNZQkbi VPoTU=; b=YGUQDn4H5vD89ZcokcGru/le6L7SZRSQI2kYAfPor1J2s6MGV75W2N paN4D0/IoESeWTIiX/JHGqIZSVIqaKUf9n/+g2VEgfcoK3H4TwQd5fSjVZ50aqVc BbrSIFFUayQ8wGCfRz5ozysDvBrOf8i5BZ7gBLTeuUQ82qU+9QhzY= Received: (qmail 10847 invoked by alias); 11 Feb 2020 15:54:22 -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 10824 invoked by uid 89); 11 Feb 2020 15:54:21 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 spammy=H*Ad:U*ppalka X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (207.211.31.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 11 Feb 2020 15:54:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581436458; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=K8o20bsnviWaEgeDEetBmYqe8wNBFHU+HcQ5keNZP8I=; b=bR3wKte6Mi3D06fUXKKcDbm8iaXcVs7w9931siF8PXzV3HC6xxltakcBJeQjq/9Z6o3D+i RoloS9bUbfuTLurpKh8tWWoRcH5zsxMwQuB2C9qjdJX2FgEGbt7wlkNQVBiSJe588brWxL lJ4n2HuPEAOf7PhcxL3EZCR980HpBRQ= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-383-0TDOFzIyMC6c5cStCdoufw-1; Tue, 11 Feb 2020 10:54:12 -0500 Received: by mail-qk1-f197.google.com with SMTP id q2so7350484qkq.19 for ; Tue, 11 Feb 2020 07:54:12 -0800 (PST) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id b26sm2169815qkk.5.2020.02.11.07.54.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Feb 2020 07:54:11 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jwakely@redhat.com, Patrick Palka Subject: [PATCH] libstdc++: Fix LWG issues 3389 and 3390 Date: Tue, 11 Feb 2020 10:54:09 -0500 Message-Id: <20200211155409.3119627-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-IsSubscribed: yes libstdc++-v3/ChangeLog: DR 3389 and DR 3390 * include/bits/stl_iterator.h (move_move_iterator): Use std::move when constructing the move_iterator with __i. (counted_iterator::counted_iterator): Use std::move when initializing M_current with __i. * testsuite/24_iterators/counted_iterator/dr3389.cc: New test. * testsuite/24_iterators/move_iterator/dr3390.cc: New test. --- libstdc++-v3/include/bits/stl_iterator.h | 4 +- .../24_iterators/counted_iterator/dr3389.cc | 66 +++++++++++++++++++ .../24_iterators/move_iterator/dr3390.cc | 66 +++++++++++++++++++ 3 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 libstdc++-v3/testsuite/24_iterators/counted_iterator/dr3389.cc create mode 100644 libstdc++-v3/testsuite/24_iterators/move_iterator/dr3390.cc diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index 4e70672924b..fc9d442b475 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -1375,7 +1375,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template inline _GLIBCXX17_CONSTEXPR move_iterator<_Iterator> make_move_iterator(_Iterator __i) - { return move_iterator<_Iterator>(__i); } + { return move_iterator<_Iterator>(std::move(__i)); } template __n) - : _M_current(__i), _M_length(__n) + : _M_current(std::move(__i)), _M_length(__n) { __glibcxx_assert(__n >= 0); } template diff --git a/libstdc++-v3/testsuite/24_iterators/counted_iterator/dr3389.cc b/libstdc++-v3/testsuite/24_iterators/counted_iterator/dr3389.cc new file mode 100644 index 00000000000..c72317407cd --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/counted_iterator/dr3389.cc @@ -0,0 +1,66 @@ +// 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 + +#include + +using __gnu_test::test_range; +using __gnu_test::input_iterator_wrapper; + +template +struct move_only_wrapper : input_iterator_wrapper +{ + using input_iterator_wrapper::input_iterator_wrapper; + + move_only_wrapper() + : input_iterator_wrapper(nullptr, nullptr) + { } + + move_only_wrapper(const move_only_wrapper&) = delete; + move_only_wrapper& + operator=(const move_only_wrapper&) = delete; + + move_only_wrapper(move_only_wrapper&&) = default; + move_only_wrapper& + operator=(move_only_wrapper&&) = default; + + using input_iterator_wrapper::operator++; + + move_only_wrapper& + operator++() + { + input_iterator_wrapper::operator++(); + return *this; + } +}; + +static_assert(std::input_iterator>); +static_assert(!std::forward_iterator>); +static_assert(!std::copyable>); + +// DR 3390 +void +test01() +{ + int x[] = {1,2,3,4}; + test_range rx(x); + auto it = std::counted_iterator(rx.begin(), 2); +} diff --git a/libstdc++-v3/testsuite/24_iterators/move_iterator/dr3390.cc b/libstdc++-v3/testsuite/24_iterators/move_iterator/dr3390.cc new file mode 100644 index 00000000000..100d68c1d5e --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/move_iterator/dr3390.cc @@ -0,0 +1,66 @@ +// 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 + +#include + +using __gnu_test::test_range; +using __gnu_test::input_iterator_wrapper; + +template +struct move_only_wrapper : input_iterator_wrapper +{ + using input_iterator_wrapper::input_iterator_wrapper; + + move_only_wrapper() + : input_iterator_wrapper(nullptr, nullptr) + { } + + move_only_wrapper(const move_only_wrapper&) = delete; + move_only_wrapper& + operator=(const move_only_wrapper&) = delete; + + move_only_wrapper(move_only_wrapper&&) = default; + move_only_wrapper& + operator=(move_only_wrapper&&) = default; + + using input_iterator_wrapper::operator++; + + move_only_wrapper& + operator++() + { + input_iterator_wrapper::operator++(); + return *this; + } +}; + +static_assert(std::input_iterator>); +static_assert(!std::forward_iterator>); +static_assert(!std::copyable>); + +// DR 3390 +void +test01() +{ + int x[] = {1,2,3,4}; + test_range rx(x); + auto it = std::make_move_iterator(rx.begin()); +}