From patchwork Sat Mar 21 22:40:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 1259558 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=MpI7hCxz; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48lFwV6ryzz9sPJ for ; Sun, 22 Mar 2020 09:40:41 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E78783944411; Sat, 21 Mar 2020 22:40:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E78783944411 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1584830438; bh=TfvsZT8hgzIW3MOUqd7CAdT0YRABcr/zjCH4XP7L97E=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=MpI7hCxzsTCQtDd9Tm52I5jv8KcCAe5TyUHHPVv2Omwys5IlkJ0ow2qLWEOePu9Il w8hHPi2ft7wXqmPdRp9hYYHzn3RlbS328fVMdf9AaajNPd9u2sobWGGFqvEhq03b9G sazT7vPGViqkZLw4jvmlji2Nx5TT9L/dPnvmNSG8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by sourceware.org (Postfix) with ESMTP id 6EEC73877007 for ; Sat, 21 Mar 2020 22:40:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6EEC73877007 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-421-EGVbKZpsM_GPEhxFxRXz-w-1; Sat, 21 Mar 2020 18:40:32 -0400 X-MC-Unique: EGVbKZpsM_GPEhxFxRXz-w-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 806468017CC; Sat, 21 Mar 2020 22:40:31 +0000 (UTC) Received: from localhost (unknown [10.33.36.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A41B5C1B8; Sat, 21 Mar 2020 22:40:31 +0000 (UTC) Date: Sat, 21 Mar 2020 22:40:30 +0000 To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix experimental::path::generic_string (PR 93245) Message-ID: <20200321224030.GA42772@redhat.com> MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-38.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This function was unimplemented, simply returning the native format string instead. PR libstdc++/93245 * include/experimental/bits/fs_path.h (path::generic_string()): * testsuite/experimental/filesystem/path/generic/generic_string.cc: Improve test coverage. Tested powerpc64le-linux and x86_64-w64-mingw32, committed to master. I think this could be safely backported too. commit a577c0c26931090e7c25e56ef5ffc807627961ec Author: Jonathan Wakely Date: Sat Mar 21 22:11:44 2020 +0000 libstdc++: Fix experimental::path::generic_string (PR 93245) This function was unimplemented, simply returning the native format string instead. PR libstdc++/93245 * include/experimental/bits/fs_path.h (path::generic_string()): * testsuite/experimental/filesystem/path/generic/generic_string.cc: Improve test coverage. diff --git a/libstdc++-v3/include/experimental/bits/fs_path.h b/libstdc++-v3/include/experimental/bits/fs_path.h index 7b3d9926e60..d7234c08a00 100644 --- a/libstdc++-v3/include/experimental/bits/fs_path.h +++ b/libstdc++-v3/include/experimental/bits/fs_path.h @@ -1086,34 +1086,56 @@ namespace __detail inline std::u32string path::u32string() const { return string(); } -#ifndef _GLIBCXX_FILESYSTEM_IS_WINDOWS template inline std::basic_string<_CharT, _Traits, _Allocator> path::generic_string(const _Allocator& __a) const - { return string<_CharT, _Traits, _Allocator>(__a); } + { +#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS + const _CharT __slash = is_same<_CharT, wchar_t>::value + ? _CharT(L'/') + : _CharT('/'); // Assume value is correct for the encoding. +#else + const _CharT __slash = _CharT('/'); +#endif + basic_string<_CharT, _Traits, _Allocator> __str(__a); + __str.reserve(_M_pathname.size()); + bool __add_slash = false; + for (auto& __elem : *this) + { + if (__elem._M_type == _Type::_Root_dir) + { + __str += __slash; + continue; + } + if (__add_slash) + __str += __slash; + __str += __elem.string<_CharT, _Traits, _Allocator>(__a); + __add_slash = __elem._M_type == _Type::_Filename; + } + return __str; + } inline std::string - path::generic_string() const { return string(); } + path::generic_string() const { return generic_string(); } #if _GLIBCXX_USE_WCHAR_T inline std::wstring - path::generic_wstring() const { return wstring(); } + path::generic_wstring() const { return generic_string(); } #endif #ifdef _GLIBCXX_USE_CHAR8_T inline std::u8string - path::generic_u8string() const { return u8string(); } + path::generic_u8string() const { return generic_string(); } #else inline std::string - path::generic_u8string() const { return u8string(); } + path::generic_u8string() const { return generic_string(); } #endif inline std::u16string - path::generic_u16string() const { return u16string(); } + path::generic_u16string() const { return generic_string(); } inline std::u32string - path::generic_u32string() const { return u32string(); } -#endif + path::generic_u32string() const { return generic_string(); } inline int path::compare(const string_type& __s) const { return compare(path(__s)); } diff --git a/libstdc++-v3/testsuite/experimental/filesystem/path/generic/generic_string.cc b/libstdc++-v3/testsuite/experimental/filesystem/path/generic/generic_string.cc index 40b39d22023..aa977847436 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/path/generic/generic_string.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/path/generic/generic_string.cc @@ -23,27 +23,55 @@ #include #include -#include +#include using std::experimental::filesystem::path; void test01() { - for (const path& p : __gnu_test::test_paths) + __gnu_test::compare_paths( path("///a//b///").generic_string(), "/a/b/." ); + __gnu_test::compare_paths( path("///a//b").generic_u16string(), "/a/b" ); + __gnu_test::compare_paths( path("//a//b").generic_u16string(), "//a/b" ); +} + +using __gnu_test::SimpleAllocator; + +void +test02() +{ + path p = "//foo//bar//."; + using C = char16_t; + auto g = p.generic_string, SimpleAllocator>(); + VERIFY( g == u"//foo/bar/." ); +} + + +void +test03() +{ + for (path p : { "/a///b//c", "///a//b//c", "a:b//c", "a://b///c" }) { - path p2(p), p3; - p2.swap(p3); - VERIFY( p2 == path() ); - VERIFY( p3 == p ); - p2.swap(p3); - VERIFY( p2 == p ); - VERIFY( p3 == path() ); + // A path constructed from the generic format string should compare equal + // to the original, because they represent the same path. + VERIFY( path(p.generic_string()) == p ); + VERIFY( path(p.generic_wstring()) == p ); + VERIFY( path(p.generic_u8string()) == p ); + VERIFY( path(p.generic_u16string()) == p ); + VERIFY( path(p.generic_u32string()) == p ); } + + // Except when the original consists entirely of a root-directory with + // multiple slashes, because path("///").native() is "///" but the + // generic format string is "/". In the Filesystem TS path::compare just + // compares native strings, so path("///") != path("/"). + VERIFY( path("///").generic_string() == "/" ); } int main() { test01(); + test02(); + test03(); }