gcc/libstdc++-v3/include
Jonathan Wakely 73d968d945 Fix bugs in filesystem::path::lexically_normal()
Using path::_List::erase(const_iterator) to remove a non-final component
in path::lexically_normal() is a bug, because it leaves the following
component with an incorrect _M_pos value.

Instead of providing erase members that allow removing components from
the middle, replace them with pop_back() and
_M_erase_from(const_iterator) which only allow removing elements at the
end. Most uses of erase are unaffected, because they only remove
elements from the end anyway. The one use of erasure from the middle in
lexically_normal() is replaced by calls to pop_back() and/or clearing
the last component to leave it as an empty final filename.

Also replace the "???" comment in lexically_normal() to document when
that branch is taken.

	* include/bits/fs_path.h (path::_List::erase): Replace both overloads
	with ...
	(path::pop_back(), path::_M_erase_from(const_iterator)): New member
	functions that will only erase elements at the end.
	* src/filesystem/std-path.cc (path::_List::_Impl::pop_back()): Define.
	(path::_List::_Impl::_M_erase_from(const_iterator)): Define.
	(path::_List::operator=(const _List&)): Use _M_erase_from(p) instead
	of erase(p, end()).
	(path::_List::pop_back()): Define.
	(path::_List::_M_erase_from(const_iterator)): Define.
	(path::operator/=(const path&)): Use pop_back to remove last component
	and _M_erase_from to remove multiple components.
	(path::_M_append(basic_string_view<value_type>)): Likewise.
	(path::operator+=(const path&)): Likewise.
	(path::_M_concat(basic_string_view<value_type>)): Likewise.
	(path::remove_filename()): Likewise.
	(path::lexically_normal()): Use _List::_Impl iterators instead of
	path::iterator. Use pop_back to remove components from the end. Clear
	trailing filename, instead of using erase(const_iterator) to remove
	a non-final component.
	* testsuite/27_io/filesystem/path/generation/normal.cc: Test
	additional cases.
	* testsuite/27_io/filesystem/path/generation/normal2.cc: New test.

From-SVN: r267576
2019-01-04 14:03:59 +00:00
..
backward Update copyright years. 2019-01-01 13:31:55 +01:00
bits Fix bugs in filesystem::path::lexically_normal() 2019-01-04 14:03:59 +00:00
c Update copyright years. 2019-01-01 13:31:55 +01:00
c_compatibility Update copyright years. 2019-01-01 13:31:55 +01:00
c_global Update copyright years. 2019-01-01 13:31:55 +01:00
c_std Update copyright years. 2019-01-01 13:31:55 +01:00
debug PR libstdc++/88607 replace or remove unnecessary UTF-8 characters 2019-01-03 20:38:11 +00:00
decimal Update copyright years. 2019-01-01 13:31:55 +01:00
experimental PR libstdc++/88607 replace some more UTF-8 characters 2019-01-03 22:07:52 +00:00
ext Update copyright years. 2019-01-01 13:31:55 +01:00
parallel PR libstdc++/88607 replace or remove unnecessary UTF-8 characters 2019-01-03 20:38:11 +00:00
precompiled Update copyright years. 2019-01-01 13:31:55 +01:00
profile Update copyright years. 2019-01-01 13:31:55 +01:00
std PR libstdc++/88607 replace some more UTF-8 characters 2019-01-03 22:07:52 +00:00
tr1 Update copyright years. 2019-01-01 13:31:55 +01:00
tr2 Update copyright years. 2019-01-01 13:31:55 +01:00
Makefile.am Update copyright years. 2019-01-01 13:31:55 +01:00
Makefile.in Implement uniform container erasure for C++20. 2018-11-28 16:44:25 +00:00