From patchwork Thu Oct 19 14:00:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 828098 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-464544-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="wk3Cbxii"; 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 3yHrDm6CQVz9t2Z for ; Fri, 20 Oct 2017 01:00:56 +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:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=wpecD8U/wJvwHCHOspNOw73ogiQjPEznBXbhxZgQ1/sVGz9Pp7XTv VsBoA62jm+zi74nQSG4lnr/KfW4S9ucSxX4b5TP9pYx5QhwcU7I6APwQJzWfCF/B PDpAyQRlYUzai1WfEwvAm7xXbOliCW2PYJyhbasCw0SmVUkIOHUCyI= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=lues0t0nk4fKohG+AFrMfNNLMcI=; b=wk3CbxiiiV7nPhQ8+p3y Z5nlMAyiYy2TmE4fzcVp/lcwlOqvQKVULVs9NvJHqIHNdmQQ+1A0CtjeEfkgiDAG VQPA51bj0IDzoPmaWblBMxvzfsJ2LAtFAAbLrZxmBEtNG6A900ekKCHFszK4swyV tB06Xm2d6CBndbaLIO+Uie8= Received: (qmail 95305 invoked by alias); 19 Oct 2017 14:00:44 -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 95197 invoked by uid 89); 19 Oct 2017 14:00:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=friend X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 19 Oct 2017 14:00:39 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B591FFED4; Thu, 19 Oct 2017 14:00:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B591FFED4 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jwakely@redhat.com Received: from localhost (unknown [10.33.36.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5DFB7DF993; Thu, 19 Oct 2017 14:00:37 +0000 (UTC) Date: Thu, 19 Oct 2017 15:00:36 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] Fix path::iterator post-increment and post-decrement Message-ID: <20171019140036.GA15986@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.9.1 (2017-09-22) I made a dumb mistake in the post-inc and post-dec operators for the path::iterator type, forgetting that _M_cur is sometimes null (for a single-element path). * include/experimental/bits/fs_path.h (path::iterator++(int)) (path::iterator--(int)): Fix for paths with only one component. * testsuite/experimental/filesystem/path/itr/traversal.cc: Test post-increment and post-decrement. Tested powerpc64le-linux, committed to trunk. It's too late to fix this on the gcc-5 branch but I'll backport it to gcc-6 and gcc-7 soon. commit 1c773ea81a8781dfbb4381a496aa5bab5bd623de Author: Jonathan Wakely Date: Wed Oct 18 02:47:24 2017 +0100 Fix path::iterator post-increment and post-decrement * include/experimental/bits/fs_path.h (path::iterator++(int)) (path::iterator--(int)): Fix for paths with only one component. * testsuite/experimental/filesystem/path/itr/traversal.cc: Test post-increment and post-decrement. diff --git a/libstdc++-v3/include/experimental/bits/fs_path.h b/libstdc++-v3/include/experimental/bits/fs_path.h index cde3897b8e5..9121439b7f2 100644 --- a/libstdc++-v3/include/experimental/bits/fs_path.h +++ b/libstdc++-v3/include/experimental/bits/fs_path.h @@ -725,10 +725,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 pointer operator->() const { return std::__addressof(**this); } iterator& operator++(); - iterator operator++(int) { auto __tmp = *this; ++_M_cur; return __tmp; } + iterator operator++(int) { auto __tmp = *this; ++*this; return __tmp; } iterator& operator--(); - iterator operator--(int) { auto __tmp = *this; --_M_cur; return __tmp; } + iterator operator--(int) { auto __tmp = *this; --*this; return __tmp; } friend bool operator==(const iterator& __lhs, const iterator& __rhs) { return __lhs._M_equals(__rhs); } diff --git a/libstdc++-v3/testsuite/experimental/filesystem/path/itr/traversal.cc b/libstdc++-v3/testsuite/experimental/filesystem/path/itr/traversal.cc index bc1091476b5..dbb4d46796d 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/path/itr/traversal.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/path/itr/traversal.cc @@ -79,9 +79,28 @@ test02() } } +void +test03() +{ + path paths[] = { "single", "multiple/elements" }; + for (const path& p : paths) + for (auto iter = p.begin(); iter != p.end(); ++iter) + { + auto iter2 = iter; + ++iter; + iter2++; + VERIFY( iter2 == iter ); + auto iter3 = iter; + --iter3; + iter2--; + VERIFY( iter2 == iter3 ); + } +} + int main() { test01(); test02(); + test03(); }