From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 010EF3858C2C for ; Thu, 14 Oct 2021 14:18:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 010EF3858C2C 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-534-v0MxUZRoOWap20Jp0WRkZQ-1; Thu, 14 Oct 2021 10:18:12 -0400 X-MC-Unique: v0MxUZRoOWap20Jp0WRkZQ-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 57030120C841; Thu, 14 Oct 2021 14:18:11 +0000 (UTC) Received: from localhost (unknown [10.33.36.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 093221001B2C; Thu, 14 Oct 2021 14:18:10 +0000 (UTC) Date: Thu, 14 Oct 2021 15:18:10 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix brainwrong in path::_S_convert(T) [PR102743] Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="5AEC63Z/wUVVo0D3" Content-Disposition: inline X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Oct 2021 14:18:17 -0000 --5AEC63Z/wUVVo0D3 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline On 13/10/21 20:41 +0100, Jonathan Wakely wrote: >Adjust the __detail::__effective_range overloads so they always return a >string or string view using std::char_traits, because we don't care >about the traits of an incoming string. > >Use std::contiguous_iterator in the __effective_range(const Source&) >overload, to allow returning a basic_string_view in more cases. For the >non-contiguous cases in both __effective_range and __string_from_range, >return a std::string instead of std::u8string when the value type of the >range is char8_t. These changes avoid unnecessary basic_string >temporaries. > >Also simplify __string_from_range(Iter, Iter) to not need >std::__to_address for the contiguous case. > >Combine the _S_convert(string_type) and _S_convert(const T&) overloads >into a single _S_convert(T) function which also avoids the dangling >view problem of PR 102592 (should that recur somehow). > >libstdc++-v3/ChangeLog: > > * include/bits/fs_path.h (__detail::__is_contiguous): New > variable template to identify contiguous iterators. > (__detail::__unified_char8_t): New alias template to decide when > to treat char8_t as char without encoding conversion. > (__detail::__effective_range(const basic_string&)): Use > std::char_traits for returned string view. > (__detail::__effective_range(const basic_string_view&)): > Likewise. > (__detail::__effective_range(const Source&)): Use > __is_contiguous to detect mode cases of contiguous iterators. > Use __unified_char8_t to return a std::string instead of > std::u8string. > >Tested powerpc64le-linux. Committed to trunk. > template > static auto >- _S_convert(const _Tp& __str) >+ _S_convert(_Tp __str) > { >- if constexpr (is_same_v<_Tp, string_type>) >- return __str; >- else if constexpr (is_same_v<_Tp, basic_string_view>) >- return __str; >- else if constexpr (is_same_v) >- return basic_string_view(__str.data(), __str.size()); >+ if constexpr (is_same_v<_Tp, typename _Tp::value_type>) >+ return __str; // No conversion needed. Yikes, this condition is wrong! Causing PR 102743 on Windows. Fixed by the attached patch, tested x86_64-linux and x86_64-mingw32, pushed to trunk. --5AEC63Z/wUVVo0D3 Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" commit 5e3f88838994b67580594c4679c839fff7cdeba0 Author: Jonathan Wakely Date: Thu Oct 14 13:20:57 2021 libstdc++: Fix brainwrong in path::_S_convert(T) [PR102743] This function was supposed to check whether the parameter's value type is the same as path::value_type, and therefore needs no conversion. Instead it checks whether the parameter is the same as its own value type, which is never true. This means we incorrectly return a string view for the case where T is path::string_type, instead of just returning the string itself. The only place that happens is path::_S_convert_loc for Windows, where we call _S_convert with a std::wstring rvalue. This fixes the condition in _S_convert(T). libstdc++-v3/ChangeLog: PR libstdc++/102743 * include/bits/fs_path.h (path::_S_convert(T)): Fix condition for returning the same string unchanged. diff --git a/libstdc++-v3/include/bits/fs_path.h b/libstdc++-v3/include/bits/fs_path.h index c51bfa3095a..a63e4b9ab07 100644 --- a/libstdc++-v3/include/bits/fs_path.h +++ b/libstdc++-v3/include/bits/fs_path.h @@ -625,7 +625,7 @@ namespace __detail static auto _S_convert(_Tp __str) { - if constexpr (is_same_v<_Tp, typename _Tp::value_type>) + if constexpr (is_same_v) return __str; // No conversion needed. #if !defined _GLIBCXX_FILESYSTEM_IS_WINDOWS && defined _GLIBCXX_USE_CHAR8_T else if constexpr (is_same_v<_Tp, std::u8string>) --5AEC63Z/wUVVo0D3--