From 56cf7082bf9da70b3cbee6c912dd7e7b3e60c56a Mon Sep 17 00:00:00 2001 From: statementreply Date: Sun, 17 Jan 2021 15:23:52 +0800 Subject: [PATCH 1/3] Implement LWG-3171 --- stl/inc/filesystem | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/stl/inc/filesystem b/stl/inc/filesystem index 0f9bec6e02c..1178c7e474f 100644 --- a/stl/inc/filesystem +++ b/stl/inc/filesystem @@ -2469,6 +2469,14 @@ namespace filesystem { return _Path >= _Rhs._Path; } + // [fs.dir.entry.io], inserter + template + friend _STD basic_ostream<_Elem, _Traits>& operator<<( + _STD basic_ostream<_Elem, _Traits>& _Ostr, const directory_entry& _Entry) { + // insert a directory_entry into a stream + return _Ostr << _Entry.path(); + } + private: void _Refresh(const __std_fs_find_data& _Data) noexcept { _Cached_data._Attributes = _Data._Attributes; From 0a680fb2af7b914b8b3f11dac96f9be050bfd251 Mon Sep 17 00:00:00 2001 From: statementreply Date: Sun, 17 Jan 2021 15:27:42 +0800 Subject: [PATCH 2/3] Add test for LWG-3171 --- tests/std/tests/P0218R1_filesystem/test.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/std/tests/P0218R1_filesystem/test.cpp b/tests/std/tests/P0218R1_filesystem/test.cpp index 7273aff888f..610e1003b8b 100644 --- a/tests/std/tests/P0218R1_filesystem/test.cpp +++ b/tests/std/tests/P0218R1_filesystem/test.cpp @@ -1224,6 +1224,12 @@ void test_directory_entry() { EXPECT(good(ec)); remove(dirPath, ec); EXPECT(good(ec)); + + // LWG-3171 "LWG-2989 breaks directory_entry stream insertion" + const directory_entry iostreamEntry{path{R"(one\two\three)"}}; + ostringstream oss; + oss << iostreamEntry; + EXPECT(oss.str() == R"("one\\two\\three")"); } template @@ -3838,8 +3844,13 @@ basic_ostream& operator<<(basic_ostream& str, const return str << status.type() << L' ' << status.permissions(); } +struct directory_entry_wrapper { + directory_entry value; +}; + template -basic_ostream& operator<<(basic_ostream& str, const directory_entry& de) { +basic_ostream& operator<<(basic_ostream& str, const directory_entry_wrapper& de_wrapper) { + const directory_entry& de = de_wrapper.value; return str << L"\n symlink_status: " << de.symlink_status() << L"\n status: " << de.status() << L"\n size: " << de.file_size() << L"\n last_write_time: " << de.last_write_time().time_since_epoch().count() << L"\n hard_link_count: " << de.hard_link_count(); @@ -3872,7 +3883,7 @@ void run_interactive_tests(int argc, wchar_t* argv[]) { } else if (starts_with(arg, L"-stat:"sv)) { wcerr << quoted(arg) << L" => " << status(the_rest) << "\n"; } else if (starts_with(arg, L"-de:"sv)) { - wcerr << quoted(arg) << L" => " << directory_entry(the_rest) << "\n"; + wcerr << quoted(arg) << L" => " << directory_entry_wrapper{directory_entry(the_rest)} << "\n"; } else if (starts_with(arg, L"-mkdir:"sv)) { wcerr << L"create_directory => " << create_directory(the_rest) << "\n"; } else if (starts_with(arg, L"-mkdirs:"sv)) { From d239fd52de00ffff7953b15a8255cf1ec938cea1 Mon Sep 17 00:00:00 2001 From: statementreply Date: Tue, 19 Jan 2021 21:21:16 +0800 Subject: [PATCH 3/3] Add TRANSITION comment Follows `operator <<(basic_ostream, path)`. --- stl/inc/filesystem | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stl/inc/filesystem b/stl/inc/filesystem index 1178c7e474f..c0444a29bd9 100644 --- a/stl/inc/filesystem +++ b/stl/inc/filesystem @@ -2471,8 +2471,8 @@ namespace filesystem { // [fs.dir.entry.io], inserter template - friend _STD basic_ostream<_Elem, _Traits>& operator<<( - _STD basic_ostream<_Elem, _Traits>& _Ostr, const directory_entry& _Entry) { + friend _STD basic_ostream<_Elem, _Traits>& operator<<( // TRANSITION, VSO-570323 + _STD basic_ostream<_Elem, _Traits>& _Ostr, const directory_entry& _Entry) { // TRANSITION, VSO-570323 // insert a directory_entry into a stream return _Ostr << _Entry.path(); }