LWG 2936: update path::compare logic and optimize string comparisons
authorJonathan Wakely <jwakely@redhat.com>
Tue, 18 Dec 2018 15:52:33 +0000 (15:52 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 18 Dec 2018 15:52:33 +0000 (15:52 +0000)
commit36313a6bce37f7eabc64c66f216ff0b2adb12ed7
tree6bfdee3d10c2cddd259f3e27e75aa615b7fd5170
parent49cefcf3f084dabc327914269e5787bac8b20f46
LWG 2936: update path::compare logic and optimize string comparisons

The resolution for LWG 2936 defines the comparison more precisely, which
this patch implements. The patch also defines comparisons with strings
to work without constructing a temporary path object (so avoids any
memory allocations).

* include/bits/fs_path.h (path::compare(const string_type&))
(path::compare(const value_type*)): Add noexcept and construct a
string view to compare to instead of a path.
(path::compare(basic_string_view<value_type>)): Add noexcept. Remove
inline definition.
* src/filesystem/std-path.cc (path::_Parser): Track last type read
from input.
(path::_Parser::next()): Return a final empty component when the
input ends in a non-root directory separator.
(path::_M_append(basic_string_view<value_type>)): Remove special cases
for trailing non-root directory separator.
(path::_M_concat(basic_string_view<value_type>)): Likewise.
(path::compare(const path&)): Implement LWG 2936.
(path::compare(basic_string_view<value_type>)): Define in terms of
components returned by parser, consistent with LWG 2936.
* testsuite/27_io/filesystem/path/compare/lwg2936.cc: New.
* testsuite/27_io/filesystem/path/compare/path.cc: Test more cases.
* testsuite/27_io/filesystem/path/compare/strings.cc: Likewise.

From-SVN: r267235
libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/fs_path.h
libstdc++-v3/src/filesystem/std-path.cc
libstdc++-v3/testsuite/27_io/filesystem/path/compare/lwg2936.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/filesystem/path/compare/path.cc
libstdc++-v3/testsuite/27_io/filesystem/path/compare/strings.cc