From patchwork Tue May 15 13:50:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 913628 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-477708-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.b="uVnLEpBi"; 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 40lf9K3fVkz9s02 for ; Tue, 15 May 2018 23:51:00 +1000 (AEST) 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=pkzvElkVOGYDefveTnG6oBu/c5OtvyeO2fVkMjrGB798oL79aTgRY pYmbnWRSSkf4oqNehFWrcvzP2uy3m6xV2ClDyUHGZa9/4ce21Yz1x9XRSRWs56z/ SEMICbz74JLjUKor371V7jv2gn4W1U3iizekztdefgpkU8Khi0X7CM= 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=q31QMU4o2khcf1eS9fB8dIZU78I=; b=uVnLEpBidGzxFSjpRMxM HzXUStd561pBB/5zWHAnUoKcxk5cvM9+evPu1MCsXGLpYR3E2a1XRU/7xQsp4MxU 8e8io7i91ezTUO9m62745PLZ3PGBujorc82NaBTTfHhWi5Fs05HaY/gNGmOMzDNh IrjZe0MIacU1XWeAIn4F2Bs= Received: (qmail 66705 invoked by alias); 15 May 2018 13:50:45 -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 66685 invoked by uid 89); 15 May 2018 13:50:44 -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, KAM_SHORT, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= 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; Tue, 15 May 2018 13:50:38 +0000 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EDB95C08C32F; Tue, 15 May 2018 13:50:36 +0000 (UTC) Received: from localhost (unknown [10.33.36.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EC491001948; Tue, 15 May 2018 13:50:36 +0000 (UTC) Date: Tue, 15 May 2018 14:50:35 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] PR libstdc++/83891 fix path::is_absolute() for non-POSIX targets Message-ID: <20180515135035.GA3868@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.9.2 (2017-12-15) The correct definition seems to be has_root_directory() for all systems we care about. PR libstdc++/83891 * include/bits/fs_path.h (path::is_absolute()): Use same definition for all operating systems. * include/experimental/bits/fs_path.h (path::is_absolute()): Likewise. * testsuite/27_io/filesystem/path/query/is_absolute.cc: New. * testsuite/27_io/filesystem/path/query/is_relative.cc: Fix comment. * testsuite/experimental/filesystem/path/query/is_absolute.cc: New. Tested powerpc64le-linux and x86_64-linux, committed to trunk and gcc-8-branch. commit 82eb5d9bd748708bd0069e2045c2665f56c0e268 Author: Jonathan Wakely Date: Tue May 15 14:32:43 2018 +0100 PR libstdc++/83891 fix path::is_absolute() for non-POSIX targets The correct definition seems to be has_root_directory() for all systems we care about. PR libstdc++/83891 * include/bits/fs_path.h (path::is_absolute()): Use same definition for all operating systems. * include/experimental/bits/fs_path.h (path::is_absolute()): Likewise. * testsuite/27_io/filesystem/path/query/is_absolute.cc: New. * testsuite/27_io/filesystem/path/query/is_relative.cc: Fix comment. * testsuite/experimental/filesystem/path/query/is_absolute.cc: New. diff --git a/libstdc++-v3/include/bits/fs_path.h b/libstdc++-v3/include/bits/fs_path.h index 53bf237b547..51af2891647 100644 --- a/libstdc++-v3/include/bits/fs_path.h +++ b/libstdc++-v3/include/bits/fs_path.h @@ -376,7 +376,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 bool has_filename() const; bool has_stem() const; bool has_extension() const; - bool is_absolute() const; + bool is_absolute() const { return has_root_directory(); } bool is_relative() const { return !is_absolute(); } // generation @@ -1071,16 +1071,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 return ext.first && ext.second != string_type::npos; } - inline bool - path::is_absolute() const - { -#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS - return has_root_name(); -#else - return has_root_directory(); -#endif - } - inline path::iterator path::begin() const { diff --git a/libstdc++-v3/include/experimental/bits/fs_path.h b/libstdc++-v3/include/experimental/bits/fs_path.h index 3b4011e6414..ada7c1791aa 100644 --- a/libstdc++-v3/include/experimental/bits/fs_path.h +++ b/libstdc++-v3/include/experimental/bits/fs_path.h @@ -368,7 +368,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 bool has_filename() const; bool has_stem() const; bool has_extension() const; - bool is_absolute() const; + bool is_absolute() const { return has_root_directory(); } bool is_relative() const { return !is_absolute(); } // iterators @@ -999,16 +999,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 return ext.first && ext.second != string_type::npos; } - inline bool - path::is_absolute() const - { -#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS - return has_root_name(); -#else - return has_root_directory(); -#endif - } - inline path::iterator path::begin() const { diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/query/is_absolute.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/query/is_absolute.cc new file mode 100644 index 00000000000..6b5c098489a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/query/is_absolute.cc @@ -0,0 +1,62 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2018 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 +// . + +// 30.11.7.4.9 path decomposition [fs.path.decompose] + +#include +#include + +using std::filesystem::path; + +void +test01() +{ + VERIFY( path("/").is_absolute() ); + VERIFY( path("/foo").is_absolute() ); + VERIFY( path("/foo/").is_absolute() ); + VERIFY( path("/foo/bar").is_absolute() ); + VERIFY( path("/foo/bar/").is_absolute() ); + VERIFY( ! path("foo").is_absolute() ); + VERIFY( ! path("foo/").is_absolute() ); + VERIFY( ! path("foo/bar").is_absolute() ); + VERIFY( ! path("foo/bar/").is_absolute() ); + VERIFY( ! path("c:").is_absolute() ); + VERIFY( ! path("c:foo").is_absolute() ); + VERIFY( ! path("c:foo/").is_absolute() ); + VERIFY( ! path("c:foo/bar").is_absolute() ); + VERIFY( ! path("c:foo/bar/").is_absolute() ); +#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS + const bool drive_letter_is_root_name = true; +#else + const bool drive_letter_is_root_name = false; +#endif + VERIFY( path("c:/").is_absolute() == drive_letter_is_root_name ); + VERIFY( path("c:/foo").is_absolute() == drive_letter_is_root_name ); + VERIFY( path("c:/foo/").is_absolute() == drive_letter_is_root_name ); + VERIFY( path("c:/foo/bar").is_absolute() == drive_letter_is_root_name ); + VERIFY( path("c:/foo/bar/").is_absolute() == drive_letter_is_root_name ); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/query/is_relative.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/query/is_relative.cc index a647e8e831f..d8c09414965 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/path/query/is_relative.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/query/is_relative.cc @@ -19,7 +19,7 @@ // with this library; see the file COPYING3. If not see // . -// 8.4.9 path decomposition [path.decompose] +// 30.11.7.4.9 path decomposition [fs.path.decompose] #include #include diff --git a/libstdc++-v3/testsuite/experimental/filesystem/path/query/is_absolute.cc b/libstdc++-v3/testsuite/experimental/filesystem/path/query/is_absolute.cc new file mode 100644 index 00000000000..1b99eaceef4 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/filesystem/path/query/is_absolute.cc @@ -0,0 +1,62 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2018 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 +// . + +// 8.4.9 path decomposition [path.decompose] + +#include +#include + +using std::filesystem::path; + +void +test01() +{ + VERIFY( path("/").is_absolute() ); + VERIFY( path("/foo").is_absolute() ); + VERIFY( path("/foo/").is_absolute() ); + VERIFY( path("/foo/bar").is_absolute() ); + VERIFY( path("/foo/bar/").is_absolute() ); + VERIFY( ! path("foo").is_absolute() ); + VERIFY( ! path("foo/").is_absolute() ); + VERIFY( ! path("foo/bar").is_absolute() ); + VERIFY( ! path("foo/bar/").is_absolute() ); + VERIFY( ! path("c:").is_absolute() ); + VERIFY( ! path("c:foo").is_absolute() ); + VERIFY( ! path("c:foo/").is_absolute() ); + VERIFY( ! path("c:foo/bar").is_absolute() ); + VERIFY( ! path("c:foo/bar/").is_absolute() ); +#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS + const bool drive_letter_is_root_name = true; +#else + const bool drive_letter_is_root_name = false; +#endif + VERIFY( path("c:/").is_absolute() == drive_letter_is_root_name ); + VERIFY( path("c:/foo").is_absolute() == drive_letter_is_root_name ); + VERIFY( path("c:/foo/").is_absolute() == drive_letter_is_root_name ); + VERIFY( path("c:/foo/bar").is_absolute() == drive_letter_is_root_name ); + VERIFY( path("c:/foo/bar/").is_absolute() == drive_letter_is_root_name ); +} + +int +main() +{ + test01(); +}