[committed] libstdc++: Fix brainwrong in path::_S_convert(T) [PR102743]

Jonathan Wakely jwakely@redhat.com
Thu Oct 14 14:18:10 GMT 2021


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<C,T>&)): Use
>	std::char_traits<C> for returned string view.
>	(__detail::__effective_range(const basic_string_view<C,T>&)):
>	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<typename _Tp>
>       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<value_type>>)
>-	  return __str;
>-	else if constexpr (is_same_v<typename _Tp::value_type, value_type>)
>-	  return basic_string_view<value_type>(__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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 1566 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20211014/0f3aed20/attachment.bin>


More information about the Libstdc++ mailing list