From 6cda876da273e36bb65f843a9bf39576258ebf19 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Tue, 15 May 2018 13:07:09 +0100 Subject: PR libstdc++/84159 fix appending strings to paths The path::operator/=(const Source&) and path::append overloads were still following the semantics of the Filesystem TS not C++17. Only the path::operator/=(const path&) overload was correct. This change adds more tests for path::operator/=(const path&) and adds new tests to verify that the other append operations have equivalent behaviour. PR libstdc++/84159 * include/bits/fs_path.h (path::operator/=, path::append): Construct temporary path before calling _M_append. (path::_M_append): Change parameter to path and implement C++17 semantics. * testsuite/27_io/filesystem/path/append/path.cc: Add helper function and more examples from the standard. * testsuite/27_io/filesystem/path/append/source.cc: New. * testsuite/27_io/filesystem/path/decompose/filename.cc: Add comment. * testsuite/27_io/filesystem/path/nonmember/append.cc: New. From-SVN: r260255 --- libstdc++-v3/include/bits/fs_path.h | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'libstdc++-v3/include') diff --git a/libstdc++-v3/include/bits/fs_path.h b/libstdc++-v3/include/bits/fs_path.h index 6703e91..53bf237 100644 --- a/libstdc++-v3/include/bits/fs_path.h +++ b/libstdc++-v3/include/bits/fs_path.h @@ -265,20 +265,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 template _Path<_Source>& operator/=(_Source const& __source) - { return append(__source); } + { return _M_append(path(__source)); } template _Path<_Source>& append(_Source const& __source) - { - return _M_append(_S_convert(_S_range_begin(__source), - _S_range_end(__source))); - } + { return _M_append(path(__source)); } template _Path<_InputIterator, _InputIterator>& append(_InputIterator __first, _InputIterator __last) - { return _M_append(_S_convert(__first, __last)); } + { return _M_append(path(__first, __last)); } // concatenation @@ -406,17 +403,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 enum class _Split { _Stem, _Extension }; - path& _M_append(string_type&& __str) + path& + _M_append(path __p) { + if (__p.is_absolute()) + operator=(std::move(__p)); #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS - operator/=(path(std::move(__str))); -#else - if (!_M_pathname.empty() && !_S_is_dir_sep(_M_pathname.back()) - && (__str.empty() || !_S_is_dir_sep(__str.front()))) - _M_pathname += preferred_separator; - _M_pathname += __str; - _M_split_cmpts(); + else if (__p.has_root_name() && __p.root_name() != root_name()) + operator=(std::move(__p)); #endif + else + operator/=(const_cast(__p)); return *this; } -- cgit v1.1