Commit Graph

654 Commits

Author SHA1 Message Date
Jonathan Wakely
e06d3f5dd7 libstdc++: Fix filesystem::path construction from COW string [PR 99805]
Calling the non-const data() member on a COW string makes it "leaked",
possibly resulting in reallocating the string to ensure a unique owner.

The path::_M_split_cmpts() member parses its _M_pathname string using
string_view objects and then calls _M_pathname.data() to find the offset
of each string_view from the start of the string. However because
_M_pathname is non-const that will cause a COW string to reallocate if
it happens to be shared with another string object. This results in the
offsets calculated for each component being wrong (i.e. undefined)
because the string views no longer refer to substrings of the
_M_pathname member. The fix is to use the parse.offset(c) member which
gets the offset safely.

The bug only happens for the path(string_type&&) constructor and only
for COW strings. When constructed from an lvalue string the string's
contents are copied rather than just incrementing the refcount, so
there's no reallocation when calling the non-const data() member. The
testsuite changes check the lvalue case anyway, because we should
probably change the deep copying to just be a refcount increment (by
adding a path(const string_type&) constructor or an overload for
__effective_range(const string_type&), for COW strings only).

libstdc++-v3/ChangeLog:

	PR libstdc++/99805
	* src/c++17/fs_path.cc (path::_M_split_cmpts): Do not call
	non-const member on _M_pathname, to avoid copy-on-write.
	* testsuite/27_io/filesystem/path/decompose/parent_path.cc:
	Check construction from strings that might be shared.
2021-04-07 16:39:24 +01:00
Jonathan Wakely
31002af904 libstdc++: Do not assume std::FILE is complete [PR 99270]
libstdc++-v3/ChangeLog:

	PR libstdc++/99270
	* testsuite/27_io/headers/cstdio/types_std.cc: Use pointer to
	FILE instead of FILE.
2021-02-25 15:35:58 +00:00
Jonathan Wakely
1dfd95f0a0 libstdc++: Fix filesystem::rename on Windows [PR 98985]
The _wrename function won't overwrite an existing file, so use
MoveFileEx instead. That allows renaming directories over files, which
POSIX doesn't allow, so check for that case explicitly and report an
error.

Also document the deviation from the expected behaviour, and add a test
for filesystem::rename which was previously missing.

The Filesystem TS experimental::filesystem::rename doesn't have that
extra code to handle directories correctly, so the relevant parts of the
new test are not run on Windows.

libstdc++-v3/ChangeLog:

	* doc/xml/manual/status_cxx2014.xml: Document implementation
	specific properties of std::experimental::filesystem::rename.
	* doc/xml/manual/status_cxx2017.xml: Document implementation
	specific properties of std::filesystem::rename.
	* doc/html/*: Regenerate.
	* src/c++17/fs_ops.cc (fs::rename): Implement correct behaviour
	for directories on Windows.
	* src/filesystem/ops-common.h (__gnu_posix::rename): Use
	MoveFileExW on Windows.
	* testsuite/27_io/filesystem/operations/rename.cc: New test.
	* testsuite/experimental/filesystem/operations/rename.cc: New test.
2021-02-12 15:29:50 +00:00
Jonathan Wakely
c4ece1d96a libstdc++: XFAIL tests that depends on RTTI
The std::emit_on_flush manipulator depends on dynamic_cast, so fails
without RTTI.

The std::async code can't catch a forced_unwind exception when RTTI is
disabled, so it can't rethrow it either, and the test aborts.

libstdc++-v3/ChangeLog:

	* testsuite/27_io/basic_ostream/emit/1.cc: Expect test to fail
	if -fno-rtti is used.
	* testsuite/30_threads/async/forced_unwind.cc: Expect test
	to abort if -fno-rtti is used.
2021-02-12 14:30:13 +00:00
Jonathan Wakely
e9c3105211 libstdc++: Only use dynamic_cast in tests when RTTI is enabled
libstdc++-v3/ChangeLog:

	* testsuite/27_io/basic_istringstream/rdbuf/char/2832.cc: Use
	static_cast when RTTI is disabled.
	* testsuite/27_io/basic_istringstream/rdbuf/wchar_t/2832.cc:
	Likewise.
	* testsuite/27_io/basic_ostringstream/rdbuf/char/2832.cc:
	Likewise.
	* testsuite/27_io/basic_ostringstream/rdbuf/wchar_t/2832.cc:
	Likewise.
	* testsuite/27_io/basic_stringstream/str/char/2.cc:
	Likewise.
	* testsuite/27_io/basic_stringstream/str/wchar_t/2.cc:
	Likewise.
2021-02-12 14:30:13 +00:00
Jonathan Wakely
6a6f74be9d libstdc++: Fix spelling of __MINGW32__ macros
libstdc++-v3/ChangeLog:

	* testsuite/27_io/filesystem/operations/proximate.cc: Fix typo
	in __MINGW32__ macro name.
	* testsuite/27_io/filesystem/path/compare/lwg2936.cc: Likewise.
	* testsuite/27_io/filesystem/path/generation/proximate.cc:
	Likewise.
	* testsuite/27_io/filesystem/path/generation/relative.cc:
	Likewise.
	* testsuite/util/testsuite_fs.h: Likewise.
2021-02-10 16:40:29 +00:00
Jonathan Wakely
bfdb7b8c6f libstdc++: Clear up directories created by tests
libstdc++-v3/ChangeLog:

	* testsuite/27_io/filesystem/operations/remove_all.cc: Remove
	test directory after making it writable again.
	* testsuite/experimental/filesystem/operations/remove_all.cc:
	Likewise.
2021-02-09 16:54:41 +00:00
Jonathan Wakely
a81d2f1e41 libstdc++: Fix narrow char test to use stringbuf not wstringbuf
This seems to be a copy & paste error.

libstdc++-v3/ChangeLog:

	* testsuite/27_io/basic_stringstream/cons/char/1.cc: Use
	stringbuf not wstringbuf.
2021-01-18 12:45:10 +00:00
Jakub Jelinek
99dee82307 Update copyright years. 2021-01-04 10:26:59 +01:00
Ville Voutilainen
4e096e0ff8 libstdc++: Fix the test for rvalue stream extraction
libstdc++-v3/ChangeLog:

	* testsuite/27_io/rvalue_streams.cc: Run the extraction to a char*
	for C++17 and lower only.
2020-12-15 18:03:43 +02:00
Jonathan Wakely
8b2c3b5af3 libstdc++: Use longer timeout for istream::gcount() overflow tests
On targets with 32-bit poitners these tests do extra work, so give them
longer to run.

libstdc++-v3/ChangeLog:

	* testsuite/27_io/basic_istream/ignore/char/94749.cc: Add
	dg-timeout-factor for ilp32 targets.
	* testsuite/27_io/basic_istream/ignore/wchar_t/94749.cc:
	Likewise.
2020-12-02 12:34:20 +00:00
Jonathan Wakely
0fb378761f libstdc++: Use longer timeout for slow running tests
libstdc++-v3/ChangeLog:

	* testsuite/27_io/basic_istream/get/char/lwg3464.cc: Add
	dg-timeout-factor directive.
	* testsuite/27_io/basic_istream/get/wchar_t/lwg3464.cc:
	Likewise.
2020-12-01 10:51:25 +00:00
Jonathan Wakely
58f71a34c6 libstdc++: Link test with libatomic if needed [PR 98003]
libstdc++-v3/ChangeLog:

	PR libstdc++/98003
	* testsuite/27_io/basic_syncbuf/sync_ops/1.cc: Add options for
	libatomic.
2020-12-01 10:37:38 +00:00
Jonathan Wakely
4a7c799908 libstdc++: Fix -Wrange-loop-construct warnings in filesystem tests
Many tests do `for (const path& p : test_paths)` where test_paths is an
array of strings. To avoid -Wrange-loop-construct warnings the loop
variable should be an object, not a reference bound to a temporary.

libstdc++-v3/ChangeLog:

	* testsuite/27_io/filesystem/operations/absolute.cc: Avoid
	-Wrange-loop-construct warning.
	* testsuite/27_io/filesystem/path/append/source.cc: Likewise.
	* testsuite/27_io/filesystem/path/assign/copy.cc: Likewise.
	* testsuite/27_io/filesystem/path/compare/path.cc: Likewise.
	* testsuite/27_io/filesystem/path/construct/copy.cc: Likewise.
	* testsuite/27_io/filesystem/path/decompose/extension.cc:
	Likewise.
	* testsuite/27_io/filesystem/path/decompose/filename.cc:
	Likewise.
	* testsuite/27_io/filesystem/path/decompose/parent_path.cc:
	Likewise.
	* testsuite/27_io/filesystem/path/decompose/relative_path.cc:
	Likewise.
	* testsuite/27_io/filesystem/path/decompose/root_directory.cc:
	Likewise.
	* testsuite/27_io/filesystem/path/decompose/root_path.cc:
	Likewise.
	* testsuite/27_io/filesystem/path/itr/traversal.cc: Likewise.
	* testsuite/27_io/filesystem/path/modifiers/remove_filename.cc:
	Likewise.
	* testsuite/27_io/filesystem/path/modifiers/replace_extension.cc:
	Likewise.
	* testsuite/27_io/filesystem/path/modifiers/replace_filename.cc:
	Likewise.
	* testsuite/27_io/filesystem/path/nonmember/append.cc: Likewise.
	* testsuite/27_io/filesystem/path/nonmember/cmp.cc: Likewise.
	* testsuite/27_io/filesystem/path/nonmember/cmp_c++20.cc:
	Likewise.
	* testsuite/27_io/filesystem/path/nonmember/hash_value.cc:
	Likewise.
	* testsuite/27_io/filesystem/path/query/has_extension.cc:
	Likewise.
	* testsuite/27_io/filesystem/path/query/has_filename.cc:
	Likewise.
	* testsuite/27_io/filesystem/path/query/has_parent_path.cc:
	Likewise.
	* testsuite/27_io/filesystem/path/query/has_relative_path.cc:
	Likewise.
	* testsuite/27_io/filesystem/path/query/has_root_directory.cc:
	Likewise.
	* testsuite/27_io/filesystem/path/query/has_root_name.cc:
	Likewise.
	* testsuite/27_io/filesystem/path/query/has_root_path.cc:
	Likewise.
	* testsuite/27_io/filesystem/path/query/has_stem.cc: Likewise.
	* testsuite/27_io/filesystem/path/query/is_relative.cc: Likewise.
	* testsuite/experimental/filesystem/operations/absolute.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/assign/copy.cc: Likewise.
	* testsuite/experimental/filesystem/path/compare/path.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/construct/copy.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/decompose/extension.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/decompose/filename.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/decompose/parent_path.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/decompose/relative_path.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/decompose/root_directory.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/decompose/root_path.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/itr/traversal.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/modifiers/remove_filename.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/modifiers/replace_extension.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/modifiers/replace_filename.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/nonmember/hash_value.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/query/has_extension.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/query/has_filename.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/query/has_parent_path.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/query/has_relative_path.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/query/has_root_directory.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/query/has_root_name.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/query/has_root_path.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/query/has_stem.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/query/is_relative.cc:
	Likewise.
2020-11-27 13:34:22 +00:00
Jonathan Wakely
ecba8547dd libstdc++: Implement std::emit_on_flush etc.
This adds the manipulators for use with basic_osyncstream. In order to
detect when an arbitrary basic_ostream<C,T> is the base class of a
basic_syncbuf<C,T,A> object, introduce a new intermediate base class
that stores the data members. The new base class stores a pointer and
two bools, which wastes (sizeof(void*) - 2) bytes of padding. It would
be possible to use the two least significant bits of the pointer for the
two bools, at least for targets where alignof(basic_streambuf) > 2, but
that's left as a possible change for a future date.

Also define basic_syncbuf::overflow to override the virtual function in
the base class, so that single characters can be inserted into the
stream buffer. Previously the default basic_streambuf::overflow
implementation was used, which drops the character on the floor.

libstdc++-v3/ChangeLog:

	* include/std/ostream (__syncbuf_base): New class template.
	(emit_on_flush, noemit_on_flush, flush_emit): New manipulators.
	* include/std/syncstream (basic_syncbuf): Derive from
	__syncbuf_base instead of basic_streambuf.
	(basic_syncbuf::operator=): Remove self-assignment check.
	(basic_syncbuf::swap): Remove self-swap check.
	(basic_syncbuf::emit): Do not skip pubsync() call if sequence
	is empty.
	(basic_syncbuf::sync): Remove no-op pubsync on stringbuf.
	(basic_syncbuf::overflow): Define override.
	* testsuite/27_io/basic_syncstream/basic_ops/1.cc: Test
	basic_osyncstream::put(char_type).
	* testsuite/27_io/basic_ostream/emit/1.cc: New test.
2020-11-11 00:19:40 +00:00
Jonathan Wakely
95cb0fc8c5 libstdc++: Add remaining C++20 additions to <sstream> [P0408R7]
This adds the new overloads of basic_stringbuf::str, and the
corresponding overloads to basic_istringstream, basic_ostringstream and
basic_stringstream.

libstdc++-v3/ChangeLog:

	* config/abi/pre/gnu.ver (GLIBCXX_3.4.21): Tighten patterns.
	(GLIBCXX_3.4.29): Export new symbols.
	* include/bits/alloc_traits.h (__allocator_like): New concept.
	* include/std/sstream (basic_stringbuf::swap): Add exception
	specification.
	(basic_stringbuf::str() const): Add ref-qualifier. Use new
	_M_high_mark function.
	(basic_stringbuf::str(const SAlloc&) const): Define new function.
	(basic_stringbuf::str() &&): Likewise.
	(basic_stringbuf::str(const basic_string<C,T,SAlloc>&)):
	Likewise.
	(basic_stringbuf::str(basic_string<C,T,Alloc>&&)): Likewise.
	(basic_stringbuf::view() const): Use _M_high_mark.
	(basic_istringstream::str, basic_ostringstream::str)
	(basic_stringstream::str): Define new overloads.
	* src/c++20/sstream-inst.cc (basic_stringbuf::str)
	(basic_istringstream::str, basic_ostringstream::str)
	(basic_stringstream::str): Explicit instantiation definitions
	for new overloads.
	* testsuite/27_io/basic_istringstream/view/char/1.cc: Add more
	checks.
	* testsuite/27_io/basic_istringstream/view/wchar_t/1.cc:
	Likewise.
	* testsuite/27_io/basic_ostringstream/view/char/1.cc:
	Likewise.
	* testsuite/27_io/basic_ostringstream/view/wchar_t/1.cc:
	Likewise.
	* testsuite/27_io/basic_stringstream/view/char/1.cc:
	Likewise.
	* testsuite/27_io/basic_stringstream/view/wchar_t/1.cc:
	Likewise.
	* testsuite/27_io/basic_istringstream/str/char/2.cc: New test.
	* testsuite/27_io/basic_istringstream/str/wchar_t/2.cc: New test.
	* testsuite/27_io/basic_ostringstream/str/char/3.cc: New test.
	* testsuite/27_io/basic_ostringstream/str/wchar_t/3.cc: New test.
	* testsuite/27_io/basic_stringbuf/str/char/4.cc: New test.
	* testsuite/27_io/basic_stringbuf/str/wchar_t/4.cc: New test.
	* testsuite/27_io/basic_stringstream/str/char/5.cc: New test.
	* testsuite/27_io/basic_stringstream/str/wchar_t/5.cc.cc: New test.
2020-11-10 19:22:47 +00:00
Jonathan Wakely
432258be4f libstdc++: Fix new <sstream> constructors
- Add a missing 'explicit' to a basic_stringbuf constructor.
- Set up the get/put area pointers in the constructor from strings using
  different allocator types.
- Remove public basic_stringbuf::__sv_type alias.
- Do not construct temporary basic_string objects with a
  default-constructed allocator.

Also, change which basic_string constructor is used, as a minor
compile-time optimization. Constructing from a basic_string_view
requires more work from the compiler, so just use a pointer and length.

libstdc++-v3/ChangeLog:

	* include/std/sstream (basic_stringbuf(const allocator_type&):
	Add explicit.
	(basic_stringbuf(const basic_string<C,T,SA>&, openmode, const A&)):
	Call _M_stringbuf_init. Construct _M_string from pointer and length
	to avoid constraint checks for string view.
	(basic_stringbuf::view()): Make __sv_type alias local to the
	function.
	(basic_istringstream(const basic_string<C,T,SA>&, openmode, const A&)):
	Pass string to _M_streambuf instead of constructing a temporary
	with the wrong allocator.
	(basic_ostringstream(const basic_string<C,T,SA>&, openmode, const A&)):
	Likewise.
	(basic_stringstream(const basic_string<C,T,SA>&, openmode, const A&)):
	Likewise.
	* src/c++20/sstream-inst.cc: Use string_view and wstring_view
	typedefs in explicit instantiations.
	* testsuite/27_io/basic_istringstream/cons/char/1.cc: Add more
	tests for constructors.
	* testsuite/27_io/basic_ostringstream/cons/char/1.cc: Likewise.
	* testsuite/27_io/basic_stringbuf/cons/char/1.cc: Likewise.
	* testsuite/27_io/basic_stringbuf/cons/char/2.cc: Likewise.
	* testsuite/27_io/basic_stringbuf/cons/wchar_t/1.cc: Likewise.
	* testsuite/27_io/basic_stringbuf/cons/wchar_t/2.cc: Likewise.
	* testsuite/27_io/basic_stringstream/cons/char/1.cc: Likewise.
2020-11-05 13:31:32 +00:00
Jonathan Wakely
8f565d255a libstdc++: Fix default mode of new basic_stringstream constructor [PR 97719]
libstdc++-v3/ChangeLog:

	PR libstdc++/97719
	* include/std/sstream (basic_stringstream(string_type&&, openmode)):
	Fix default argument.
	* testsuite/27_io/basic_stringstream/cons/char/97719.cc: New test.
2020-11-04 23:41:02 +00:00
Thomas Rodgers
6bcbcea058 libstdc++: Add c++2a <syncstream>
libstdc++-v3/ChangeLog:
	* doc/doxygen/user.cfg.in (INPUT): Add new header.
	* include/Makefile.am (std_headers): Add new header.
	* include/Makefile.in: Regenerate.
	* include/precompiled/stdc++.h: Include new header.
	* include/std/syncstream: New header.
	* include/std/version: Add __cpp_lib_syncbuf.
	* testsuite/27_io/basic_syncbuf/1.cc: New test.
	* testsuite/27_io/basic_syncbuf/2.cc: Likewise.
	* testsuite/27_io/basic_syncbuf/basic_ops/1.cc:
	Likewise.
	* testsuite/27_io/basic_syncbuf/requirements/types.cc:
	Likewise.
	* testsuite/27_io/basic_syncbuf/sync_ops/1.cc:
	Likewise.
	* testsuite/27_io/basic_syncstream/1.cc: Likewise.
	* testsuite/27_io/basic_syncstream/2.cc: Likewise.
	* testsuite/27_io/basic_syncstream/basic_ops/1.cc:
	Likewise.
	* testsuite/27_io/basic_syncstream/requirements/types.cc:
	Likewise.
2020-11-02 10:41:32 -08:00
Jonathan Wakely
13feb0234b libstdc++: Avoid warnings in tests
This fixes some warnings emitted when testing with warning flags added.
Some of these are only necessary when testing with -Wsystem-headers, but
either way it cleans up the tests to be less noisy under non-default
flags.

libstdc++-v3/ChangeLog:

	* testsuite/18_support/96817.cc: Avoid -Wunused warnings.
	* testsuite/20_util/any/assign/2.cc: Likewise.
	* testsuite/20_util/any/cons/2.cc: Likewise.
	* testsuite/20_util/align/1.cc: Avoid -Wsign-compare warning.
	* testsuite/20_util/function/65760.cc: Avoid -Wunused warning.
	* testsuite/20_util/function/1.cc: Avoid -Wcatch-value warning.
	* testsuite/20_util/function/cons/move_target.cc: Avoid -Wunused
	warning.
	* testsuite/20_util/headers/memory/synopsis.cc: Add exception
	specification.
	* testsuite/20_util/monotonic_buffer_resource/allocate.cc: Avoid
	-Wsign-compare warning.
	* testsuite/20_util/tuple/cons/deduction.cc: Avoid -Wunused
	warning.
	* testsuite/20_util/specialized_algorithms/uninitialized_copy/808590-cxx11.cc:
	Avoid -Wdeprecated-copy warning.
	* testsuite/21_strings/basic_string/56166.cc: Avoid
	-Wcatch-value warning.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stod.cc:
	Avoid -Wcatch-value warnings.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stof.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stoi.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stol.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stold.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stoll.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stoul.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stoull.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stod.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stof.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoi.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stol.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stold.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoll.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoul.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoull.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/compare/char/nonnull.cc:
	Prune additional diagnostics.
	* testsuite/21_strings/basic_string_view/operations/find/char/nonnull.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/rfind/char/nonnull.cc:
	Likewise.
	* testsuite/21_strings/headers/string/synopsis.cc: Add exception
	specifications.
	* testsuite/22_locale/locale/cons/12352.cc: Define sized
	delete operators to avoid warnings.
	* testsuite/23_containers/deque/modifiers/swap/1.cc: Add
	exception specification.
	* testsuite/23_containers/forward_list/cons/11.cc: Avoid
	-Wdeprecated-copy warning.
	* testsuite/23_containers/headers/bitset/synopsis.cc: Add
	exception specification.
	* testsuite/23_containers/headers/deque/synopsis.cc: Likewise.
	* testsuite/23_containers/headers/forward_list/synopsis.cc:
	Likewise.
	* testsuite/23_containers/headers/list/synopsis.cc: Likewise.
	* testsuite/23_containers/headers/map/synopsis.cc: Likewise.
	* testsuite/23_containers/headers/queue/synopsis.cc: Likewise.
	* testsuite/23_containers/headers/set/synopsis.cc: Likewise.
	* testsuite/23_containers/headers/vector/synopsis.cc: Likewise.
	* testsuite/23_containers/list/modifiers/swap/1.cc: Likewise.
	* testsuite/23_containers/map/modifiers/swap/1.cc: Likewise.
	* testsuite/23_containers/multimap/modifiers/swap/1.cc:
	Likewise.
	* testsuite/23_containers/multiset/modifiers/swap/1.cc:
	Likewise.
	* testsuite/23_containers/set/modifiers/swap/1.cc: Likewise.
	* testsuite/23_containers/unordered_set/56267-2.cc: Avoid
	-Wdeprecated-copy warning.
	* testsuite/23_containers/vector/bool/23632.cc: Avoid
	-Wempty-body warning.
	* testsuite/23_containers/vector/modifiers/swap/1.cc: Add
	exception specification.
	* testsuite/25_algorithms/heap/moveable2.cc: Fix misplaced
	parentheses around arguments.
	* testsuite/25_algorithms/sample/1.cc: Use return value.
	* testsuite/25_algorithms/search/searcher.cc: Avoid -Wunused
	warnings.
	* testsuite/27_io/basic_ostream/exceptions/char/9561.cc:
	Likewise.
	* testsuite/27_io/basic_ostream/exceptions/wchar_t/9561.cc:
	Likewise.
	* testsuite/27_io/filesystem/operations/remove_all.cc: Avoid
	-Wsign-compare warning.
	* testsuite/experimental/any/assign/2.cc: Avoid -Wunused warnings.
	* testsuite/experimental/any/cons/2.cc: Likewise.
	* testsuite/experimental/filesystem/operations/remove_all.cc:
	Avoid -Wign-compare warning.
	* testsuite/experimental/memory/observer_ptr/cons/cons.cc:
	Likewise.
	* testsuite/experimental/memory_resource/null_memory_resource.cc:
	Likewise.
	* testsuite/experimental/source_location/1.cc: Avoid -Waddress
	warning.
	* testsuite/ext/pod_char_traits.cc: Avoid -Wunused warning.
	* testsuite/ext/vstring/modifiers/clear/56166.cc: Avoid
	-Wcatch-value.
	* testsuite/std/concepts/concepts.lang/concept.swappable/swap.cc:
	Avoid -Wunused warning.
	* testsuite/std/concepts/concepts.lang/concept.swappable/swappable.cc:
	Likewise.
	* testsuite/tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc:
	Prune additional warnings.
	* testsuite/tr1/3_function_objects/function/1.cc: Avoid
	-Wcatch-value warning.
	* testsuite/util/replacement_memory_operators.h: Define sized
	delete to avoid warnings.
	* testsuite/util/testsuite_api.h (_NonDefaultConstructible): Add
	user-declared assignment operator to stop -Wdeprecated-copy
	warnings.
	* testsuite/util/testsuite_containers.h: Avoid -Wunused warning.
	* testsuite/util/testsuite_iterators.h: Avoid -Wsign-compare
	warnings.
	* testsuite/util/testsuite_new_operators.h: Define sized deleted.
2020-10-29 22:47:21 +00:00
Thomas Rodgers
a0e4d7b44c libstdc++: Implement C++20 features for <sstream>
New ctors and ::view() accessor for -
  * basic_stingbuf
  * basic_istringstream
  * basic_ostringstream
  * basic_stringstreamm

New ::get_allocator() accessor for basic_stringbuf.

libstdc++-v3/ChangeLog:
	* acinclude.m4 (glibcxx_SUBDIRS): Add src/c++20.
	* config/abi/pre/gnu.ver (GLIBCXX_3.4.29): New symbols.
	* configure: Regenerate.
	* include/std/sstream:
	(basic_stringbuf::basic_stringbuf(allocator const&)): New constructor.
	(basic_stringbuf::basic_stringbuf(openmode, allocator const&)): Likewise.
	(basic_stringbuf::basic_stringbuf(basic_string&&, openmode)): Likewise.
	(basic_stringbuf::basic_stringbuf(basic_stringbuf&&, allocator const&)):
	Likewise.
	(basic_stringbuf::get_allocator()): New method.
	(basic_stringbuf::view()): Likewise.
	(basic_istringstream::basic_istringstream(basic_string&&, openmode)):
	New constructor.
	(basic_istringstream::basic_istringstream(openmode, allocator const&)):
	Likewise
	(basic_istringstream::view()): New method.
	(basic_ostringstream::basic_ostringstream(basic_string&&, openmode)):
	New constructor.
	(basic_ostringstream::basic_ostringstream(openmode, allocator const&)):
	Likewise
	(basic_ostringstream::view()): New method.
	(basic_stringstream::basic_stringstream(basic_string&&, openmode)):
	New constructor.
	(basic_stringstream::basic_stringstream(openmode, allocator const&)):
	Likewise
	(basic_stringstream::view()): New method.
	* src/Makefile.in: Add c++20 directory.
	* src/Makefile.am: Regenerate.
	* src/c++20/Makefile.am: Add makefile for new sub-directory.
	* src/c++20/Makefile.in: Generate.
	* src/c++20/sstream-inst.cc: New file defining explicit
	instantiations for basic_stringbuf, basic_istringstream,
	basic_ostringstream, and basic_stringstream member functions
	added in C++20.
	* testsuite/27_io/basic_stringbuf/cons/char/2.cc: New test.
	* testsuite/27_io/basic_stringbuf/cons/wchar_t/2.cc: Likewise.
	* testsuite/27_io/basic_stringbuf/view/char/1.cc: Likewise.
	* testsuite/27_io/basic_stringbuf/view/wchar_t/1.cc: Likewise.
	* testsuite/27_io/basic_istringstream/cons/char/1.cc: Likewise.
	* testsuite/27_io/basic_istringstream/cons/wchar_t/1.cc: Likewise.
	* testsuite/27_io/basic_istringstream/view/char/1.cc: Likewise.
	* testsuite/27_io/basic_istringstream/view/wchar_t/1.cc: Likewise.
	* testsuite/27_io/basic_ostringstream/cons/char/1.cc: Likewise.
	* testsuite/27_io/basic_ostringstream/cons/wchar_t/1.cc: Likewise.
	* testsuite/27_io/basic_ostringstream/view/char/1.cc: Likewise.
	* testsuite/27_io/basic_ostringstream/view/wchar_t/1.cc: Likewise.
	* testsuite/27_io/basic_stringstream/cons/char/1.cc: Likewise.
	* testsuite/27_io/basic_stringstream/cons/wchar_t/1.cc: Likewise.
	* testsuite/27_io/basic_stringstream/view/char/1.cc: Likewise.
	* testsuite/27_io/basic_stringstream/view/wchar_t/1.cc: Likewise.
2020-10-28 11:56:06 -07:00
Jonathan Wakely
5ae9ddd480 libstdc++: Enable tests that incorrectly require cxx11-abi
These tests were not being run when -D_GLIBCXX_USE_CXX11_ABI=0 was added
to the test flags, but they actually work OK with the old string.

libstdc++-v3/ChangeLog:

	* testsuite/21_strings/basic_string/allocator/char/minimal.cc:
	Do not require cxx11-abi effective target.
	* testsuite/21_strings/basic_string/allocator/wchar_t/minimal.cc:
	Likewise.
	* testsuite/27_io/basic_fstream/cons/base.cc: Likewise.
2020-10-14 12:52:46 +01:00
Jonathan Wakely
f997b67550 libstdc++: Add C++11 member functions for ios::failure in old ABI
The new constructors that C++11 added to std::ios_base::failure were
missing for the old ABI. This adds them, but just ignores the
std::error_code argument (because there's nowhere to store it).

This also adds a code() member, which should be provided by the
std::system_error base class, but that base class isn't present in the
old ABI.

This allows the old ios::failure to be used in code that expects the new
API, although with reduced functionality.

libstdc++-v3/ChangeLog:

	* include/bits/ios_base.h (ios_base::failure): Add constructors
	takeing error_code argument. Add code() member function.
	* testsuite/27_io/ios_base/failure/cxx11.cc: Allow test to
	run for the old ABI but do not check for derivation from
	std::system_error.
	* testsuite/27_io/ios_base/failure/error_code.cc: New test.
2020-10-08 14:45:37 +01:00
Jonathan Wakely
49ff88bd0d libstdc++: Fix out-of-bounds string_view access in filesystem::path [PR 97167]
libstdc++-v3/ChangeLog:

	PR libstdc++/97167
	* src/c++17/fs_path.cc (path::_Parser::root_path()): Check
	for empty string before inspecting the first character.
	* testsuite/27_io/filesystem/path/append/source.cc: Append
	empty string_view to path.
2020-09-22 20:02:58 +01:00
Jonathan Wakely
eef9bf4ca8 libstdc++: Add deprecated attributes to old iostream members
Back in 2017 I removed these prehistoric members (which were deprecated
since C++98) for C++17 mode. But I didn't add deprecated attributes to
most of them, so users didn't get any warning they would be going away.
Apparently some poor souls do actually use some of these names, and so
now that GCC 11 defaults to -std=gnu++17 some code has stopped
compiling.

This adds deprecated attributes to them, so that C++98/03/11/14 code
will get a warning if it uses them. I'll also backport this to the
release branches so that users can find out about the deprecation before
they start using C++17.

In order to give deprecated warnings even in C++98 mode this patch makes
_GLIBCXX_DEPRECATED work even for C++98, adds _GLIBCXX11_DEPRECATED for
the old meaning of _GLIBCXX_DEPRECATED, and adds new macros such as
_GLIBCXX_DEPRECATED_SUGGEST for suggesting alternatives to deprecated
features.

libstdc++-v3/ChangeLog:

	* include/bits/c++config (_GLIBCXX_DEPRECATED): Define for all
	standard modes.
	(_GLIBCXX_DEPRECATED_SUGGEST): New macro for "use 'foo' instead"
	message in deprecated warnings.
	(_GLIBCXX11_DEPRECATED, _GLIBCXX11_DEPRECATED_SUGGEST): New
	macros for marking features derpecated in C++11.
	(_GLIBCXX17_DEPRECATED_SUGGEST, _GLIBCXX20_DEPRECATED_SUGGEST):
	New macros.
	* include/backward/auto_ptr.h (auto_ptr_ref, auto_ptr<void>):
	Use _GLIBCXX11_DEPRECATED instead of _GLIBCXX_DEPRECATED.
	(auto_ptr): Use _GLIBCXX11_DEPRECATED_SUGGEST.
	* include/backward/binders.h (binder1st, binder2nd): Likewise.
	* include/bits/ios_base.h (io_state, open_mode, seek_dir)
	(streampos, streamoff): Use _GLIBCXX_DEPRECATED_SUGGEST.
	* include/std/streambuf (stossc): Replace C++11 attribute
	with _GLIBCXX_DEPRECATED_SUGGEST.
	* include/std/type_traits (__is_nullptr_t): Use
	_GLIBCXX_DEPRECATED_SUGGEST instead of _GLIBCXX_DEPRECATED.
	* testsuite/27_io/types/1.cc: Check for deprecated warnings.
	Also check for io_state, open_mode and seek_dir typedefs.
2020-08-19 12:13:23 +01:00
Jonathan Wakely
4e39f563c0 libstdc++: Do not set eofbit eagerly in operator>>(istream&, char(&)[N])
Similar to the bugs I fixed recently in istream::ignore, we incorrectly
set eofbit too often in operator>>(istream&, string&) and
operator>>(istream&.  char(&)[N]).

We should only set eofbit if we reach EOF but would have kept going
otherwise. If we've already extracted the maximum number of characters
(whether that's because of the buffer size or the istream's width())
then we should not set eofbit.

libstdc++-v3/ChangeLog:

	* include/bits/basic_string.tcc
	(operator>>(basic_istream&, basic_string&)): Do not set eofbit
	if extraction stopped after in.width() characters.
	* src/c++98/istream-string.cc (operator>>(istream&, string&)):
	Likewise.
	* include/bits/istream.tcc (__istream_extract): Do not set
	eofbit if extraction stopped after n-1 characters.
	* src/c++98/istream.cc (__istream_extract): Likewise.
	* testsuite/21_strings/basic_string/inserters_extractors/char/13.cc: New test.
	* testsuite/21_strings/basic_string/inserters_extractors/wchar_t/13.cc: New test.
	* testsuite/27_io/basic_istream/extractors_character/char/5.cc: New test.
	* testsuite/27_io/basic_istream/extractors_character/wchar_t/5.cc: New test.
2020-08-06 19:23:14 +01:00
Jonathan Wakely
6251ea15f5 libstdc++: Adjust overflow prevention to operator>>
This adjusts the overflow prevention added to operator>> so that we can
distinguish "unknown size" from "zero size", and avoid writing anything
at all in to zero sized buffers.

This also removes the incorrect comment saying extraction stops at a
null byte.

libstdc++-v3/ChangeLog:

	* include/std/istream (operator>>(istream&, char*)): Add
	attributes to get warnings for pointers that are null or known
	to point to the end of a buffer. Request upper bound from
	__builtin_object_size check and handle zero-sized buffer case.
	(operator>>(istream&, signed char))
	(operator>>(istream&, unsigned char*)): Add attributes.
	* testsuite/27_io/basic_istream/extractors_character/char/overflow.cc:
	Check extracting into the middle of a buffer.
	* testsuite/27_io/basic_istream/extractors_character/wchar_t/overflow.cc: New test.
2020-08-06 18:26:45 +01:00
Jonathan Wakely
17abcc7734 libstdc++: Replace operator>>(istream&, char*) [LWG 2499]
P0487R1 resolved LWG 2499 for C++20 by removing the operator>> overloads
that have high risk of buffer overflows. They were replaced by
equivalents that only accept a reference to an array, and so can
guarantee not to write past the end of the array.

In order to support both the old and new functionality, this patch
introduces a new overloaded __istream_extract function which takes a
maximum length. The new operator>> overloads use the array size as the
maximum length. The old overloads now use __builtin_object_size to
determine the available buffer size if available (which requires -O2) or
use numeric_limits<streamsize>::max()/sizeof(char_type) otherwise. This
is a change in behaviour, as the old overloads previously always used
numeric_limits<streamsize>::max(), without considering sizeof(char_type)
and without attempting to prevent overflows.

Because they now do little more than call __istream_extract, the old
operator>> overloads are very small inline functions. This means there
is no advantage to explicitly instantiating them in the library (in fact
that would prevent the __builtin_object_size checks from ever working).
As a result, the explicit instantiation declarations can be removed from
the header. The explicit instantiation definitions are still needed, for
backwards compatibility with existing code that expects to link to the
definitions in the library.

While working on this change I noticed that src/c++11/istream-inst.cc
has the following explicit instantiation definition:
  template istream& operator>>(istream&, char*);
This had no effect (and so should not have been present in that file),
because there was an explicit specialization declared in <istream> and
defined in src/++98/istream.cc. However, this change removes the
explicit specialization, and now the explicit instantiation definition
is necessary to ensure the symbol gets defined in the library.

libstdc++-v3/ChangeLog:

	* config/abi/pre/gnu.ver (GLIBCXX_3.4.29): Export new symbols.
	* include/bits/istream.tcc (__istream_extract): New function
	template implementing both of operator>>(istream&, char*) and
	operator>>(istream&, char(&)[N]). Add explicit instantiation
	declaration for it. Remove explicit instantiation declarations
	for old function templates.
	* include/std/istream (__istream_extract): Declare.
	(operator>>(basic_istream<C,T>&, C*)): Define inline and simply
	call __istream_extract.
	(operator>>(basic_istream<char,T>&, signed char*)): Likewise.
	(operator>>(basic_istream<char,T>&, unsigned char*)): Likewise.
	(operator>>(basic_istream<C,T>&, C(7)[N])): Define for LWG 2499.
	(operator>>(basic_istream<char,T>&, signed char(&)[N])):
	Likewise.
	(operator>>(basic_istream<char,T>&, unsigned char(&)[N])):
	Likewise.
	* include/std/streambuf (basic_streambuf): Declare char overload
	of __istream_extract as a friend.
	* src/c++11/istream-inst.cc: Add explicit instantiation
	definition for wchar_t overload of __istream_extract. Remove
	explicit instantiation definitions of old operator>> overloads
	for versioned-namespace build.
	* src/c++98/istream.cc (operator>>(istream&, char*)): Replace
	with __istream_extract(istream&, char*, streamsize).
	* testsuite/27_io/basic_istream/extractors_character/char/3.cc:
	Do not use variable-length array.
	* testsuite/27_io/basic_istream/extractors_character/char/4.cc:
	Do not run test for C++20.
	* testsuite/27_io/basic_istream/extractors_character/char/9555-ic.cc:
	Do not test writing to pointers for C++20.
	* testsuite/27_io/basic_istream/extractors_character/char/9826.cc:
	Use array instead of pointer.
	* testsuite/27_io/basic_istream/extractors_character/wchar_t/3.cc:
	Do not use variable-length array.
	* testsuite/27_io/basic_istream/extractors_character/wchar_t/4.cc:
	Do not run test for C++20.
	* testsuite/27_io/basic_istream/extractors_character/wchar_t/9555-ic.cc:
	Do not test writing to pointers for C++20.
	* testsuite/27_io/basic_istream/extractors_character/char/lwg2499.cc:
	New test.
	* testsuite/27_io/basic_istream/extractors_character/char/lwg2499_neg.cc:
	New test.
	* testsuite/27_io/basic_istream/extractors_character/char/overflow.cc:
	New test.
	* testsuite/27_io/basic_istream/extractors_character/wchar_t/lwg2499.cc:
	New test.
	* testsuite/27_io/basic_istream/extractors_character/wchar_t/lwg2499_neg.cc:
	New test.
2020-08-05 22:17:18 +01:00
Jonathan Wakely
8011f718e2 libstdc++: Fix tests that fail for C++98
libstdc++-v3/ChangeLog:

	* testsuite/27_io/basic_istream/ignore/char/94749.cc: Use 0
	instead of nullptr.
	* testsuite/27_io/basic_istream/ignore/wchar_t/94749.cc:
	Likewise.
2020-07-31 19:58:36 +01:00
Jonathan Wakely
6458742a15 libstdc++: Ensure c++NN effective target present in all C++17 tests
Also reorder some directives so that the dg-options setting -std=gnu++17
comes before the dg-do that requires c++17.

libstdc++-v3/ChangeLog:

	* testsuite/17_intro/headers/c++2017/all_attributes.cc: Add
	c++17 effective-target.
	* testsuite/17_intro/headers/c++2017/all_no_exceptions.cc:
	Likewise.
	* testsuite/17_intro/headers/c++2017/all_no_rtti.cc: Likewise.
	* testsuite/17_intro/headers/c++2017/all_pedantic_errors.cc:
	Likewise.
	* testsuite/17_intro/headers/c++2017/operator_names.cc:
	Likewise.
	* testsuite/17_intro/headers/c++2017/stdc++.cc: Likewise.
	* testsuite/17_intro/headers/c++2017/stdc++_multiple_inclusion.cc:
	Likewise.
	* testsuite/18_support/uncaught_exceptions/uncaught_exceptions.cc:
	Likewise.
	* testsuite/19_diagnostics/error_code/is_error_code_v.cc:
	Likewise.
	* testsuite/20_util/any/assign/1.cc: Likewise.
	* testsuite/20_util/any/assign/2.cc: Likewise.
	* testsuite/20_util/any/assign/emplace.cc: Likewise.
	* testsuite/20_util/any/assign/exception.cc: Likewise.
	* testsuite/20_util/any/assign/self.cc: Likewise.
	* testsuite/20_util/any/cons/1.cc: Likewise.
	* testsuite/20_util/any/cons/2.cc: Likewise.
	* testsuite/20_util/any/cons/aligned.cc: Likewise.
	* testsuite/20_util/any/cons/explicit.cc: Likewise.
	* testsuite/20_util/any/cons/in_place.cc: Likewise.
	* testsuite/20_util/any/cons/nontrivial.cc: Likewise.
	* testsuite/20_util/any/make_any.cc: Likewise.
	* testsuite/20_util/any/misc/any_cast.cc: Likewise.
	* testsuite/20_util/any/misc/any_cast_no_rtti.cc: Likewise.
	* testsuite/20_util/any/misc/swap.cc: Likewise.
	* testsuite/20_util/any/modifiers/1.cc: Likewise.
	* testsuite/20_util/any/observers/type.cc: Likewise.
	* testsuite/20_util/any/requirements.cc: Likewise.
	* testsuite/20_util/any/typedefs.cc: Likewise.
	* testsuite/20_util/as_const/1.cc: Likewise.
	* testsuite/20_util/as_const/rvalue_neg.cc: Likewise.
	* testsuite/20_util/bind/is_placeholder_v.cc: Likewise.
	* testsuite/20_util/bool_constant/requirements.cc: Likewise.
	* testsuite/20_util/duration/requirements/treat_as_floating_point_v.cc:
	Likewise.
	* testsuite/20_util/duration_cast/rounding.cc: Likewise.
	* testsuite/20_util/enable_shared_from_this/members/weak_from_this.cc:
	Likewise.
	* testsuite/20_util/function_objects/invoke/59768.cc: Likewise.
	* testsuite/20_util/function_objects/not_fn/1.cc: Likewise.
	* testsuite/20_util/function_objects/searchers.cc: Likewise.
	* testsuite/20_util/in_place/requirements.cc: Likewise.
	* testsuite/20_util/is_invocable/requirements/explicit_instantiation.cc:
	Likewise.
	* testsuite/20_util/is_invocable/requirements/typedefs.cc:
	Likewise.
	* testsuite/20_util/is_invocable/value.cc: Likewise.
	* testsuite/20_util/is_nothrow_invocable/requirements/explicit_instantiation.cc:
	Likewise.
	* testsuite/20_util/is_nothrow_invocable/requirements/typedefs.cc:
	Likewise.
	* testsuite/20_util/is_nothrow_swappable/requirements/explicit_instantiation.cc:
	Likewise.
	* testsuite/20_util/is_nothrow_swappable/requirements/typedefs.cc:
	Likewise.
	* testsuite/20_util/is_nothrow_swappable/value.cc: Likewise.
	* testsuite/20_util/is_nothrow_swappable_with/requirements/explicit_instantiation.cc:
	Likewise.
	* testsuite/20_util/is_nothrow_swappable_with/requirements/typedefs.cc:
	Likewise.
	* testsuite/20_util/is_nothrow_swappable_with/value.cc:
	Likewise.
	* testsuite/20_util/is_swappable/requirements/explicit_instantiation.cc:
	Likewise.
	* testsuite/20_util/is_swappable/requirements/typedefs.cc:
	Likewise.
	* testsuite/20_util/is_swappable/value.cc: Likewise.
	* testsuite/20_util/is_swappable_with/requirements/explicit_instantiation.cc:
	Likewise.
	* testsuite/20_util/is_swappable_with/requirements/typedefs.cc:
	Likewise.
	* testsuite/20_util/is_swappable_with/value.cc: Likewise.
	* testsuite/20_util/logical_traits/requirements/explicit_instantiation.cc:
	Likewise.
	* testsuite/20_util/logical_traits/requirements/typedefs.cc:
	Likewise.
	* testsuite/20_util/logical_traits/value.cc: Likewise.
	* testsuite/20_util/optional/constexpr/make_optional.cc: Likewise.
	* testsuite/20_util/optional/constexpr/observers/2.cc: Likewise.
	* testsuite/20_util/optional/constexpr/observers/3.cc: Likewise.
	* testsuite/20_util/optional/hash.cc: Likewise.
	* testsuite/20_util/pair/swap_cxx17.cc: Likewise.
	* testsuite/20_util/ratio/requirements/ratio_equal_v.cc: Likewise.
	* testsuite/20_util/shared_ptr/requirements/weak_type.cc:
	Likewise.
	* testsuite/20_util/specialized_algorithms/memory_management_tools/1.cc:
	Likewise.
	* testsuite/20_util/tuple/apply/1.cc: Likewise.
	* testsuite/20_util/tuple/make_from_tuple/1.cc: Likewise.
	* testsuite/20_util/tuple/swap_cxx17.cc: Likewise.
	* testsuite/20_util/tuple/tuple_size_v.cc: Likewise.
	* testsuite/20_util/unique_ptr/specialized_algorithms/swap_cxx17.cc:
	Likewise.
	* testsuite/20_util/uses_allocator/requirements/uses_allocator_v.cc:
	Likewise.
	* testsuite/20_util/variant/any.cc: Likewise.
	* testsuite/20_util/variant/compile.cc: Likewise.
	* testsuite/20_util/variant/hash.cc: Likewise.
	* testsuite/20_util/variant/index_type.cc: Likewise.
	* testsuite/20_util/variant/run.cc: Likewise.
	* testsuite/20_util/void_t/1.cc: Likewise.
	* testsuite/21_strings/basic_string/79162.cc: Likewise.
	* testsuite/21_strings/basic_string/cons/char/7.cc: Likewise.
	* testsuite/21_strings/basic_string/cons/wchar_t/7.cc: Likewise.
	* testsuite/21_strings/basic_string/lwg2758.cc: Likewise.
	* testsuite/21_strings/basic_string/lwg2946.cc: Likewise.
	* testsuite/21_strings/basic_string/modifiers/append/char/4.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/append/wchar_t/4.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/assign/char/4.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/assign/wchar_t/4.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/insert/char/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/insert/wchar_t/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/replace/char/7.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/replace/wchar_t/7.cc:
	Likewise.
	* testsuite/21_strings/basic_string/operations/compare/char/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string/operations/compare/wchar_t/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string/operations/data/char/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string/operations/data/wchar_t/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string/operations/find/char/5.cc:
	Likewise.
	* testsuite/21_strings/basic_string/operations/find/wchar_t/5.cc:
	Likewise.
	* testsuite/21_strings/basic_string/operators/char/5.cc: Likewise.
	* testsuite/21_strings/basic_string/operators/wchar_t/5.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/capacity/1.cc: Likewise.
	* testsuite/21_strings/basic_string_view/cons/char/1.cc: Likewise.
	* testsuite/21_strings/basic_string_view/cons/char/2.cc: Likewise.
	* testsuite/21_strings/basic_string_view/cons/char/3.cc: Likewise.
	* testsuite/21_strings/basic_string_view/cons/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/cons/wchar_t/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/cons/wchar_t/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/char/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/char/empty.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/char/front_back.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/empty.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/front_back.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/include.cc: Likewise.
	* testsuite/21_strings/basic_string_view/inserters/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/inserters/char/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/inserters/char/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/inserters/pod/10081-out.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/inserters/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/inserters/wchar_t/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/inserters/wchar_t/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/literals/types-char8_t.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/literals/types.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/literals/values-char8_t.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/literals/values.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/modifiers/remove_prefix/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/modifiers/remove_prefix/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/modifiers/remove_suffix/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/modifiers/remove_suffix/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/compare/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/compare/char/13650.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/compare/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/compare/wchar_t/13650.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/copy/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/copy/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/data/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/data/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/find/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/find/char/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/find/char/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/find/char/4.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/find/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/find/wchar_t/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/find/wchar_t/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/find/wchar_t/4.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/rfind/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/rfind/char/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/rfind/char/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/rfind/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/rfind/wchar_t/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/rfind/wchar_t/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/string_conversion/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/substr/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/substr/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/range_access/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/range_access/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char16_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char32_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char8_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/requirements/typedefs.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/typedefs.cc: Likewise.
	* testsuite/21_strings/basic_string_view/types/1.cc: Likewise.
	* testsuite/23_containers/array/specialized_algorithms/swap_cxx17.cc:
	Likewise.
	* testsuite/23_containers/map/modifiers/extract.cc: Likewise.
	* testsuite/23_containers/map/modifiers/insert_or_assign/1.cc:
	Likewise.
	* testsuite/23_containers/map/modifiers/merge.cc: Likewise.
	* testsuite/23_containers/map/modifiers/try_emplace/1.cc: Likewise.
	* testsuite/23_containers/multimap/modifiers/extract.cc: Likewise.
	* testsuite/23_containers/multimap/modifiers/merge.cc: Likewise.
	* testsuite/23_containers/multiset/modifiers/extract.cc: Likewise.
	* testsuite/23_containers/multiset/modifiers/merge.cc: Likewise.
	* testsuite/23_containers/set/modifiers/extract.cc: Likewise.
	* testsuite/23_containers/set/modifiers/merge.cc: Likewise.
	* testsuite/23_containers/unordered_map/modifiers/extract.cc:
	Likewise.
	* testsuite/23_containers/unordered_map/modifiers/insert_or_assign.cc:
	Likewise.
	* testsuite/23_containers/unordered_map/modifiers/merge.cc:
	Likewise.
	* testsuite/23_containers/unordered_map/modifiers/try_emplace.cc:
	Likewise.
	* testsuite/23_containers/unordered_multimap/modifiers/extract.cc:
	Likewise.
	* testsuite/23_containers/unordered_multimap/modifiers/merge.cc:
	Likewise.
	* testsuite/23_containers/unordered_multiset/modifiers/extract.cc:
	Likewise.
	* testsuite/23_containers/unordered_multiset/modifiers/merge.cc:
	Likewise.
	* testsuite/23_containers/unordered_set/modifiers/extract.cc:
	Likewise.
	* testsuite/23_containers/unordered_set/modifiers/merge.cc:
	Likewise.
	* testsuite/24_iterators/headers/iterator/range_access_c++17.cc:
	Likewise.
	* testsuite/24_iterators/headers/iterator/synopsis_c++17.cc:
	Likewise.
	* testsuite/25_algorithms/clamp/1.cc: Likewise.
	* testsuite/25_algorithms/clamp/2.cc: Likewise.
	* testsuite/25_algorithms/clamp/constexpr.cc: Likewise.
	* testsuite/25_algorithms/clamp/requirements/explicit_instantiation/1.cc:
	Likewise.
	* testsuite/25_algorithms/clamp/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/26_numerics/headers/cmath/functions_std_c++17.cc:
	Likewise.
	* testsuite/26_numerics/headers/cmath/special_functions_global.cc:
	Likewise.
	* testsuite/27_io/basic_ostream/inserters_other/char/lwg2221.cc:
	Likewise.
	* testsuite/29_atomics/atomic/is_always_lock_free.cc: Likewise.
	* testsuite/29_atomics/atomic_integral/is_always_lock_free.cc:
	Likewise.
	* testsuite/30_threads/shared_lock/70766.cc: Likewise.
	* testsuite/30_threads/shared_mutex/cons/1.cc: Likewise.
	* testsuite/30_threads/shared_mutex/cons/assign_neg.cc:
	Likewise.
	* testsuite/30_threads/shared_mutex/cons/copy_neg.cc:
	Likewise.
	* testsuite/30_threads/shared_mutex/requirements/standard_layout.cc:
	Likewise.
	* testsuite/30_threads/shared_mutex/try_lock/1.cc: Likewise.
	* testsuite/30_threads/shared_mutex/try_lock/2.cc: Likewise.
	* testsuite/30_threads/shared_mutex/unlock/1.cc: Likewise.
2020-07-31 19:58:02 +01:00
Jonathan Wakely
4d1c5b4957 libstdc++: Avoid overflow in istream::get(streambuf&) [LWG 3464]
Similar to the recent changes to basic_istream::ignore, this change
ensures that _M_gcount doesn't overflow when extracting characters and
inserting them into another streambuf.

The solution used here is to use unsigned long long for the count. We
assume that the number of characters extracted won't exceed the maximum
value for that type, but even if it does we avoid any undefined
behaviour.

libstdc++-v3/ChangeLog:

	* include/bits/istream.tcc
	(basic_istream::get(__streambuf_type&, char_type): Use unsigned
	long long for counter and check if it would overflow _M_gcount.
	* testsuite/27_io/basic_istream/get/char/lwg3464.cc: New test.
	* testsuite/27_io/basic_istream/get/wchar_t/lwg3464.cc: New test.
2020-07-20 20:06:46 +01:00
Jonathan Wakely
ba8fe4b483 libstdc++: Fix istream::ignore exit conditions (PR 94749, PR 96161)
My previous fix for PR 94749 did fix the reported case, so that the next
character is not discarded if it happens to equal the delimiter when __n
characters have already been read. But it introduced a new bug, which is
that the delimiter character would *not* be discarded if the number of
characters discarded is numeric_limits<streamsize>::max() or more before
reaching the delimiter.

The new bug happens because I changed the code to check _M_gcount < __n.
But when __n == numeric_limits<streamsize>::max() that is false, and so
we don't discard the delimiter. It's not sufficient to check for the
delimiter when the __large_ignore condition is true, because there's an
edge case where the delimiter is reached when _M_gcount == __n and so
we break out of the loop without setting __large_ignore.

PR 96161 is a similar bug to the original PR 94749 report, where eofbit
is set after discarding __n characters if there happen to be no more
characters in the stream.

This patch fixes both cases (and the regression) by checking different
conditions for the __n == max case and the __n < max case. For the
former case, we know that we must have either reached the delimiter or
EOF, and the value of _M_gcount doesn't matter (except to avoid integer
overflow). For the latter case we need to check _M_gcount first and only
set eofbit or discard the delimiter if it didn't reach __n. For the
latter case overflow can't happen because _M_gcount <= __n < max.

libstdc++-v3/ChangeLog:

	PR libstdc++/94749
	PR libstdc++/96161
	* include/bits/istream.tcc (basic_istream::ignore(streamsize))
	[n == max]: Check overflow conditions on _M_gcount. Rely on
	the fact that either EOF or the delimiter was reached.
	[n < max]: Check _M_gcount < n before checking for EOF or
	delimiter.
	(basic_istream::ignore(streamsize, char_type): Likewise.
	* src/c++98/compatibility.cc (istream::ignore(streamsize))
	(wistream::ignore(streamsize)): Likewise.
	* src/c++98/istream.cc (istream::ignore(streamsize, char_type))
	(wistream::ignore(streamsize, char_type)): Likewise.
	* testsuite/27_io/basic_istream/ignore/char/94749.cc: Check that
	delimiter is discarded if the number of characters ignored
	doesn't fit in streamsize.
	* testsuite/27_io/basic_istream/ignore/wchar_t/94749.cc:
	Likewise.
	* testsuite/27_io/basic_istream/ignore/char/96161.cc: New test.
	* testsuite/27_io/basic_istream/ignore/wchar_t/96161.cc: New test.
2020-07-13 12:09:44 +01:00
Jonathan Wakely
5079855e7e libstdc++: Require c++98_only effective target for a test
This test checks a conversion which only exists in C++98 and won't
compile since C++11. It uses { dg-options "-std=gnu++98" } so that it is
explicitly run in C++98 mode. This change also adds a target selector so
that the test will be skipped if the dg-options directive is filtered
out or overridden.

libstdc++-v3/ChangeLog:

	* testsuite/27_io/basic_ios/conv/voidptr.cc: Add c++98_only
	target selector.
2020-07-02 21:27:22 +01:00
Jonathan Wakely
b857b17977 libstdc++: Require c++98_only effective target for some tests
These tests verify that including C++11 headers fails to compile in
C++98 mode. They use { dg-options "-std=gnu++98" } so that they are
explicitly run in C++98 mode. This change also adds a target selector so
that the tests will be skipped even if the dg-options directive is
filtered out or overridden. This is in preparation for a desired future
change where tests do not use -std options, so that they can be tested
with e.g. --target_board=unix\"{-std=gnu++17,-std=gnu++20}\"

In some cases the dg-options and dg-do directives need to be reordered,
so that the -std=gnu++98 option is already added to the options before
the target selector is checked.

libstdc++-v3/ChangeLog:

	* testsuite/18_support/headers/cstdalign/std_c++0x_neg.cc: Add
	c++98_only target selector.
	* testsuite/18_support/headers/cstdbool/std_c++0x_neg.cc:
	Likewise.
	* testsuite/18_support/headers/cstdint/std_c++0x_neg.cc:
	Likewise.
	* testsuite/18_support/headers/new/synopsis_cxx98.cc: Likewise.
	* testsuite/19_diagnostics/headers/system_error/std_c++0x_neg.cc:
	Likewise.
	* testsuite/20_util/headers/type_traits/std_c++0x_neg.cc:
	Likewise.
	* testsuite/23_containers/headers/array/std_c++0x_neg.cc:
	Likewise.
	* testsuite/23_containers/headers/tuple/std_c++0x_neg.cc:
	Likewise.
	* testsuite/23_containers/headers/unordered_map/std_c++0x_neg.cc:
	Likewise.
	* testsuite/23_containers/headers/unordered_set/std_c++0x_neg.cc:
	Likewise.
	* testsuite/26_numerics/headers/ccomplex/std_c++0x_neg.cc:
	Likewise.
	* testsuite/26_numerics/headers/cfenv/std_c++0x_neg.cc:
	Likewise.
	* testsuite/26_numerics/headers/cmath/c99_classification_macros_c++98.cc:
	Likewise.
	* testsuite/26_numerics/headers/ctgmath/std_c++0x_neg.cc:
	Likewise.
	* testsuite/26_numerics/headers/random/std_c++0x_neg.cc:
	Likewise.
	* testsuite/27_io/headers/cinttypes/std_c++0x_neg.cc: Likewise.
	* testsuite/28_regex/headers/regex/std_c++0x_neg.cc: Likewise.
	* testsuite/29_atomics/headers/atomic/std_c++0x_neg.cc:
	Likewise.
	* testsuite/30_threads/headers/condition_variable/std_c++0x_neg.cc:
	Likewise.
	* testsuite/30_threads/headers/future/std_c++0x_neg.cc:
	Likewise.
	* testsuite/30_threads/headers/mutex/std_c++0x_neg.cc: Likewise.
	* testsuite/30_threads/headers/thread/std_c++0x_neg.cc:
	Likewise.
2020-07-02 21:27:12 +01:00
Jonathan Wakely
b32eea9c0c libstdc++: Fix istream::ignore discarding too many chars (PR 94749)
The current code assumes that if the next character in the stream is
equal to the delimiter then we stopped because we saw that delimiter,
and so discards it.  But in the testcase for the PR we stop because we
reached the maximum number of characters, and it's coincidence that the
next character equals the delimiter. We should not discard the next
character in that case.

The fix is to check that we haven't discarded __n characters already,
instead of checking whether the next character equals __delim. Because
we've already checked for EOF, if we haven't discarded __n yet then we
know we stopped because we saw the delimiter. On the other hand, if the
next character is the delimiter we don't know if that's why we stopped.

	PR libstdc++/94749
	* include/bits/istream.tcc (basic_istream::ignore(streamsize, CharT)):
	Only discard an extra character if we didn't already reach the
	maximum number.
	* src/c++98/istream.cc (istream::ignore(streamsiz, char))
	(wistream::ignore(streamsize, wchar_t)): Likewise.
	* testsuite/27_io/basic_istream/ignore/char/94749.cc: New test.
	* testsuite/27_io/basic_istream/ignore/wchar_t/94749.cc: New test.
2020-06-11 18:41:37 +01:00
Jonathan Wakely
988b853f9c libstdc++: Simplify filesystem::path SFINAE constraints
This replaces the filesystem::__detail::_Path SFINAE helper with two
separate helpers, _Path and _Path2. This avoids having one helper which
tries to check two different sets of requirements.

The _Path helper now uses variable templates instead of a set of
overloaded functions to detect specializations of basic_string or
basic_string_view.

The __not_<is_void<remove_pointer_t<_Tp1>> check is not necessary in
C++20 because iterator_traits<void*> is now empty. For C++17 replace
that check with a __safe_iterator_traits helper with partial
specializations for void pointers.

Finally, the __is_encoded_char check no longer uses remove_const_t,
which means that iterators with a const value_type will no longer be
accepted as arguments for path creation. Such iterators resulted in
undefined behaviour anyway, so it's still conforming to reject them in
the constraint checks.

	* include/bits/fs_path.h (filesystem::__detail::__is_encoded_char):
	Replace alias template with variable template. Don't remove const.
	(filesystem::__detail::__is_path_src): Replace overloaded function
	template with variable template and specializations.
	(filesystem::__detail::__is_path_iter_src): Replace alias template
	with class template.
	(filesystem::__detail::_Path): Use __is_path_src. Remove support for
	iterator pairs.
	(filesystem::__detail::_Path2): New alias template for checking
	InputIterator requirements.
	(filesystem::__detail::__constructible_from): Remove.
	(filesystem::path): Replace _Path<Iter, Iter> with _Path2<Iter>.
	* testsuite/27_io/filesystem/path/construct/80762.cc: Check with two
	constructor arguments of void and void* types.
2020-05-23 09:40:16 +01:00
Jonathan Wakely
d43919bf88 libstdc++: Add comparison operators to std::filesystem types
Some more C++20 changes from P1614R2, "The Mothership has Landed".

	* include/bits/fs_dir.h (file_status): Define operator== for C++20.
	(directory_entry): Define operator<=> and remove redundant comparison
	operators for C++20.
	* include/bits/fs_fwd.h (space_info): Define operator== for C++20.
	* include/bits/fs_path.h (path): Define operator<=> and remove
	redundant comparison operators for C++20.
	* testsuite/27_io/filesystem/path/compare/compare.cc: Fix comment.
	* testsuite/27_io/filesystem/path/compare/lwg2936.cc: Likewise.
	* testsuite/27_io/filesystem/path/compare/path.cc: Likewise.
	* testsuite/27_io/filesystem/path/compare/strings.cc: Likewise.
2020-04-15 21:01:42 +01:00
Jonathan Wakely
9fc985118d libstdc++: Fix path::generic_string allocator handling (PR 94242)
It's not possible to construct a path::string_type from an allocator of
a different type. Create the correct specialization of basic_string, and
adjust path::_S_str_convert to use a basic_string_view so that it is
independent of the allocator type.

	PR libstdc++/94242
	* include/bits/fs_path.h (path::_S_str_convert): Replace first
	parameter with basic_string_view so that strings with different
	allocators can be accepted.
	(path::generic_string<C,T,A>()): Use basic_string object that uses the
	right allocator type.
	* testsuite/27_io/filesystem/path/generic/94242.cc: New test.
	* testsuite/27_io/filesystem/path/generic/generic_string.cc: Improve
	test coverage.
2020-03-21 22:04:48 +00:00
Jonathan Wakely
ea182fe636 libstdc++: Handle type-changing path concatenations (PR 94063)
The filesystem::path::operator+= and filesystem::path::concat functions
operate directly on the native format of the path and so can cause a
path to mutate to a completely different type.

For Windows combining a filename "x" with a filename ":" produces a
root-name "x:". Similarly, a Cygwin root-directory "/" combined with a
root-directory and filename "/x" produces a root-name "//x".

Before this patch the implemenation didn't support those kind of
mutations, assuming that concatenating two filenames would always
produce a filename and concatenating with a root-dir would still have a
root-dir.

This patch fixes it simply by checking for the problem cases and
creating a new path by re-parsing the result of the string
concatenation. This is slightly suboptimal because the argument has
already been parsed if it's a path, but more importantly it doesn't
reuse any excess capacity that the path object being modified might
already have allocated. That can be fixed later though.

	PR libstdc++/94063
	* src/c++17/fs_path.cc (path::operator+=(const path&)): Add kluge to
	handle concatenations that change the type of the first component.
	(path::operator+=(basic_string_view<value_type>)): Likewise.
	* testsuite/27_io/filesystem/path/concat/94063.cc: New test.
2020-03-09 23:22:57 +00:00
Jonathan Wakely
180eeeaeb2 libstdc++: Fix failing filesystem::path tests (PR 93244)
The checks for PR 93244 don't actually pass on Windows (which is the
target where the bug is present) because of a different bug, PR 94063.

This adjusts the tests to not be affected by 94063 so that they verify
that 93244 was fixed.

	PR libstdc++/93244
	* testsuite/27_io/filesystem/path/generic/generic_string.cc: Adjust
	test to not fail due to PR 94063.
	* testsuite/27_io/filesystem/path/generic/utf.cc: Likewise.
	* testsuite/27_io/filesystem/path/generic/wchar_t.cc: Likewise.
2020-03-06 11:30:56 +00:00
Jonathan Wakely
9412b35aff libstdc++: Fix some warnings in filesystem tests
There's a -Wunused-but-set-variable warning in operations/all.cc which
can be fixed with [[maybe_unused]].

The statements in operations/copy.cc give -Wunused-value warnings. I
think I meant to use |= rather than !=.

And operations/file_size.cc gets -Wsign-compare warnings.

	* testsuite/27_io/filesystem/operations/all.cc: Mark unused variable.
	* testsuite/27_io/filesystem/operations/copy.cc: Fix typo.
	* testsuite/experimental/filesystem/operations/copy.cc: Likewise.
	* testsuite/27_io/filesystem/operations/file_size.cc: Use correct type
	for return value, and in comparison.
	* testsuite/experimental/filesystem/operations/file_size.cc: Likewise.
2020-03-05 17:23:44 +00:00
Jonathan Wakely
a51a546c17 libstdc++: Fix FS-dependent filesystem tests
These tests were failing on XFS because it doesn't support setting file
timestamps past 2038, so the expected overflow when reading back a huge
timestamp into a file_time_type didn't happen.

Additionally, the std::filesystem::file_time_type::clock has an
epoch that is out of range of 32-bit time_t so testing times around that
epoch may also fail.

This fixes the tests to give up gracefully if the filesystem doesn't
support times that can't be represented in 32-bit time_t.

	* testsuite/27_io/filesystem/operations/last_write_time.cc: Fixes for
	filesystems that silently truncate timestamps.
	* testsuite/experimental/filesystem/operations/last_write_time.cc:
	Likewise.
2020-02-28 12:58:28 +00:00
Alexandre Oliva
7a900bceca tolerate padding in mbstate_t
Padding in mbstate_t objects may get the memcmp to fail.
Attempt to avoid the failure with zero initialization.


for  libstdc++-v3/ChangeLog

	* testsuite/27_io/fpos/mbstate_t/1.cc: Zero-init mbstate_t.
2020-01-23 16:36:34 -03:00
Jonathan Wakely
fe7cc34fd5 libstdc++: Ensure root-dir converted to forward slash (PR93244)
PR libstdc++/93244
	* include/bits/fs_path.h (path::generic_string<C,A>)
	[_GLIBCXX_FILESYSTEM_IS_WINDOWS]: Convert root-dir to forward-slash.
	* testsuite/27_io/filesystem/path/generic/generic_string.cc: Check
	root-dir is converted to forward slash in generic pathname.
	* testsuite/27_io/filesystem/path/generic/utf.cc: New test.
	* testsuite/27_io/filesystem/path/generic/wchar_t.cc: New test.
2020-01-13 13:22:48 +00:00
Jonathan Wakely
fff148b787 libstdc++: Fix error handling in filesystem::remove_all (PR93201)
When recursing into a directory, any errors that occur while removing a
directory entry are ignored, because the subsequent increment of the
directory iterator clears the error_code object.

This fixes that bug by checking the result of each recursive operation
before incrementing. This is a change in observable behaviour, because
previously other directory entries would still be removed even if one
(or more) couldn't be removed due to errors. Now the operation stops on
the first error, which is what the code intended to do all along. The
standard doesn't specify what happens in this case (because the order
that the entries are processed is unspecified anyway).

It also improves the error reporting so that the name of the file that
could not be removed is included in the filesystem_error exception. This
is done by introducing a new helper type for reporting errors with
additional context and a new function that uses that type. Then the
overload of std::filesystem::remove_all that throws an exception can use
the new function to ensure any exception contains the additional
information.

For std::experimental::filesystem::remove_all just fix the bug where
errors are ignored.

	PR libstdc++/93201
	* src/c++17/fs_ops.cc (do_remove_all): New function implementing more
	detailed error reporting for remove_all. Check result of recursive
	call before incrementing iterator.
	(remove_all(const path&), remove_all(const path&, error_code&)): Use
	do_remove_all.
	* src/filesystem/ops.cc (remove_all(const path&, error_code&)): Check
	result of recursive call before incrementing iterator.
	* testsuite/27_io/filesystem/operations/remove_all.cc: Check errors
	are reported correctly.
	* testsuite/experimental/filesystem/operations/remove_all.cc: Likewise.

From-SVN: r280014
2020-01-08 16:44:45 +00:00
Jakub Jelinek
8d9254fc8a Update copyright years.
From-SVN: r279813
2020-01-01 12:51:42 +01:00
Jonathan Wakely
1d214c3f83 libstdc++: Improve testing for path::operator+=(const string&)
* testsuite/27_io/filesystem/path/concat/strings.cc: Test more cases.

From-SVN: r279111
2019-12-09 09:59:00 +00:00
Jonathan Wakely
023a3fb491 libstdc++: fix buffer overflow in path::operator+= (PR92853)
When concatenating a path ending in a root-directory onto another path,
we added an empty filename to the end of the path twice, but only
reserved space for one. That meant the second write went past the end of
the allocated buffer.

	PR libstdc++/92853
	* src/c++17/fs_path.cc (filesystem::path::operator+=(const path&)):
	Do not process a trailing directory separator twice.
	* testsuite/27_io/filesystem/path/concat/92853.cc: New test.
	* testsuite/27_io/filesystem/path/concat/path.cc: Test more cases.

From-SVN: r279110
2019-12-09 09:58:56 +00:00
Tom Honermann
cd502796cf libstdc++: P1423R3 char8_t remediation (4/4)
New tests

This patch adds new tests to validate new deleted overloads of wchar_t,
char8_t, char16_t, and char32_t for ordinary and wide formatted character and
string ostream inserters.

Additionally, new tests are added to validate invocations of u8path with
sequences of char8_t for both the C++17 and filesystem TS implementations.

2019-11-29  Tom Honermann  <tom@honermann.net>

	New tests
	* testsuite/27_io/basic_ostream/inserters_character/char/deleted.cc:
	New test to validate deleted overloads of character and string
	inserters for narrow ostreams.
	* testsuite/27_io/basic_ostream/inserters_character/wchar_t/deleted.cc:
	New test to validate deleted overloads of character and string
	inserters for wide ostreams.
	* testsuite/27_io/filesystem/path/factory/u8path-char8_t.cc: New test
	to validate u8path invocations with sequences of char8_t.
	* testsuite/experimental/filesystem/path/factory/u8path-char8_t.cc:
	New test to validate u8path invocations with sequences of char8_t.

From-SVN: r278858
2019-11-29 17:43:51 +00:00
Tom Honermann
2b68cdc7e5 libstdc++: P1423R3 char8_t remediation (3/4)
Updates to existing tests

This patch updates existing tests to validate the new value for the
__cpp_lib_char8_t feature test macros and to exercise u8path factory
function invocations with std::string, std::string_view, and interator
pair arguments.

2019-11-29  Tom Honermann  <tom@honermann.net>

	Updates to existing tests
	* testsuite/experimental/feat-char8_t.cc: Updated the expected
	__cpp_lib_char8_t feature test macro value.
	* testsuite/27_io/filesystem/path/factory/u8path.cc: Added testing of
	u8path invocation with std::string, std::string_view, and iterators
	thereof.
	* testsuite/experimental/filesystem/path/factory/u8path.cc: Added
	testing of u8path invocation with std::string, std::string_view, and
	iterators thereof.

From-SVN: r278857
2019-11-29 17:43:46 +00:00