gcc/libstdc++-v3/testsuite/experimental
Jonathan Wakely 26b1320ee5 PR libstdc++/90281 Fix string conversions for filesystem::path
Fix several bugs in the encoding conversions for filesystem::path that
prevent conversion of Unicode characters outside the Basic Multilingual
Plane, and prevent returning basic_string specializations with
alternative allocator types.

The std::codecvt_utf8 class template is not suitable for UTF-16
conversions because it uses UCS-2 instead. For conversions between UTF-8
and UTF-16 either std::codecvt<C, char, mbstate> or
codecvt_utf8_utf16<C> must be used.

The __str_codecvt_in and __str_codecvt_out utilities do not
return false on a partial conversion (e.g. for invalid or incomplete
Unicode input). Add new helpers that treat partial conversions as
errors, and use them for all filesystem::path conversions.

	PR libstdc++/90281 Fix string conversions for filesystem::path
	* include/bits/fs_path.h (u8path) [_GLIBCXX_FILESYSTEM_IS_WINDOWS]:
	Use codecvt_utf8_utf16 instead of codecvt_utf8. Use
	__str_codecvt_in_all to fail for partial conversions and throw on
	error.
	[!_GLIBCXX_FILESYSTEM_IS_WINDOWS && _GLIBCXX_USE_CHAR8_T]
	(path::_Cvt<char8_t>): Add explicit specialization.
	[_GLIBCXX_FILESYSTEM_IS_WINDOWS] (path::_Cvt::_S_wconvert): Remove
	overloads.
	[_GLIBCXX_FILESYSTEM_IS_WINDOWS] (path::_Cvt::_S_convert): Use
	if-constexpr instead of dispatching to _S_wconvert. Use codecvt
	instead of codecvt_utf8. Use __str_codecvt_in_all and
	__str_codecvt_out_all.
	[!_GLIBCXX_FILESYSTEM_IS_WINDOWS] (path::_Cvt::_S_convert): Use
	codecvt instead of codecvt_utf8. Use __str_codecvt_out_all.
	(path::_S_str_convert) [_GLIBCXX_FILESYSTEM_IS_WINDOWS]: Use
	codecvt_utf8_utf16 instead of codecvt_utf8. Construct return values
	with allocator. Use __str_codecvt_out_all. Fallthrough to POSIX code
	after converting to UTF-8.
	(path::_S_str_convert): Use codecvt instead of codecvt_utf8. Use
	__str_codecvt_in_all.
	(path::string): Fix initialization of string types with different
	allocators.
	(path::u8string) [_GLIBCXX_FILESYSTEM_IS_WINDOWS]: Use
	codecvt_utf8_utf16 instead of codecvt_utf8. Use __str_codecvt_out_all.
	* include/bits/locale_conv.h (__do_str_codecvt): Reorder static and
	runtime conditions.
	(__str_codecvt_out_all, __str_codecvt_in_all): New functions that
	return false for partial conversions.
	* include/experimental/bits/fs_path.h (u8path):
	[_GLIBCXX_FILESYSTEM_IS_WINDOWS]: Implement correctly for mingw.
	[_GLIBCXX_FILESYSTEM_IS_WINDOWS] (path::_Cvt::_S_wconvert): Add
	missing handling for char8_t. Use codecvt and codecvt_utf8_utf16
	instead of codecvt_utf8. Use __str_codecvt_in_all and
	__str_codecvt_out_all.
	[!_GLIBCXX_FILESYSTEM_IS_WINDOWS] (path::_Cvt::_S_convert): Use
	codecvt instead of codecvt_utf8. Use __str_codecvt_out_all.
	(path::string) [_GLIBCXX_FILESYSTEM_IS_WINDOWS]: Use
	codecvt_utf8_utf16 instead of codecvt_utf8. Construct return values
	with allocator. Use __str_codecvt_out_all and __str_codecvt_in_all.
	(path::string) [!_GLIBCXX_FILESYSTEM_IS_WINDOWS]: Use
	__str_codecvt_in_all.
	(path::u8string) [_GLIBCXX_FILESYSTEM_IS_WINDOWS]: Use
	codecvt_utf8_utf16 instead of codecvt_utf8. Use __str_codecvt_out_all.
	* src/c++17/fs_path.cc (path::_S_convert_loc): Use
	__str_codecvt_in_all.
	* src/filesystem/path.cc (path::_S_convert_loc): Likewise.
	* testsuite/27_io/filesystem/path/construct/90281.cc: New test.
	* testsuite/27_io/filesystem/path/factory/u8path.cc: New test.
	* testsuite/27_io/filesystem/path/native/string.cc: Test with empty
	strings and with Unicode characters outside the basic multilingual
	plane.
	* testsuite/27_io/filesystem/path/native/alloc.cc: New test.
	* testsuite/experimental/filesystem/path/construct/90281.cc: New test.
	* testsuite/experimental/filesystem/path/factory/u8path.cc: New test.
	* testsuite/experimental/filesystem/path/native/alloc.cc: New test.
	* testsuite/experimental/filesystem/path/native/string.cc: Test with
	empty strings and with Unicode characters outside the basic
	multilingual plane.

From-SVN: r272385
2019-06-17 15:19:04 +01:00
..
algorithm Update copyright years. 2019-01-01 13:31:55 +01:00
any PR libstdc++/90220 fix experimental::any_cast for non-object types 2019-05-23 14:39:06 +01:00
array Improve docs for Library Fundamentals TS 2019-05-02 16:46:29 +01:00
chrono Update copyright years. 2019-01-01 13:31:55 +01:00
deque Update copyright years. 2019-01-01 13:31:55 +01:00
filesystem PR libstdc++/90281 Fix string conversions for filesystem::path 2019-06-17 15:19:04 +01:00
forward_list Update copyright years. 2019-01-01 13:31:55 +01:00
functional Update copyright years. 2019-01-01 13:31:55 +01:00
iterator Update copyright years. 2019-01-01 13:31:55 +01:00
list Update copyright years. 2019-01-01 13:31:55 +01:00
map Fix tests that fail without PCH 2019-06-17 09:18:17 +01:00
memory PR c++/90047 - ICE with enable_if alias template. 2019-04-17 23:32:24 -04:00
memory_resource PR libstdc++/77691 fix resource_adaptor failures due to max_align_t bugs 2019-05-22 21:29:39 +01:00
net re PR libstdc++/89461 (FAIL: experimental/net/timer/waitable/cons.cc) 2019-03-12 23:13:36 +00:00
numeric Update copyright years. 2019-01-01 13:31:55 +01:00
optional Remove redundant __constexpr_addressof function 2019-05-02 22:23:35 +01:00
polymorphic_allocator P0482R5 char8_t: Updates to existing standard library tests 2019-02-22 01:16:08 +00:00
propagate_const Improve docs for Library Fundamentals TS 2019-05-02 16:46:29 +01:00
random Update copyright years. 2019-01-01 13:31:55 +01:00
ratio Update copyright years. 2019-01-01 13:31:55 +01:00
set Update copyright years. 2019-01-01 13:31:55 +01:00
source_location Update copyright years. 2019-01-01 13:31:55 +01:00
string Update copyright years. 2019-01-01 13:31:55 +01:00
string_view Fix basic_string_view typedefs and enforce preconditions 2019-04-24 16:17:53 +01:00
system_error Update copyright years. 2019-01-01 13:31:55 +01:00
tuple Update copyright years. 2019-01-01 13:31:55 +01:00
type_erased_allocator Update copyright years. 2019-01-01 13:31:55 +01:00
type_traits nonesuch is insufficiently useless (lwg2996) 2019-05-14 16:48:27 +01:00
unordered_map Fix tests that fail without PCH 2019-06-17 09:18:17 +01:00
unordered_set Update copyright years. 2019-01-01 13:31:55 +01:00
vector Update copyright years. 2019-01-01 13:31:55 +01:00
feat-char8_t.cc Add L suffix to __cpp_lib_char8_t value 2019-03-06 12:13:19 +00:00
feat-cxx14.cc
feat-lib-fund.cc
names.cc Fix tests that fail with -std=gnu++98 or -std=gnu++11 2019-06-06 13:13:42 +01:00