[libcxx-commits] [libcxx] b6d8777 - [libc++] LWG3171: implement operator<< for filesystem::directory_entry.
Konstantin Varlamov via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jan 13 20:44:34 PST 2022
Author: Konstantin Varlamov
Date: 2022-01-13T20:44:18-08:00
New Revision: b6d87773feef14d7cceeed380dd6f6c9d43fd9f0
URL: https://github.com/llvm/llvm-project/commit/b6d87773feef14d7cceeed380dd6f6c9d43fd9f0
DIFF: https://github.com/llvm/llvm-project/commit/b6d87773feef14d7cceeed380dd6f6c9d43fd9f0.diff
LOG: [libc++] LWG3171: implement operator<< for filesystem::directory_entry.
Differential Revision: https://reviews.llvm.org/D116642
Added:
libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.io/directory_entry.io.pass.cpp
Modified:
libcxx/docs/Status/Cxx2bIssues.csv
libcxx/include/__filesystem/directory_entry.h
libcxx/test/std/experimental/iterator/ostream.joiner/ostream.joiner.ops/ostream_joiner.op.assign.pass.cpp
libcxx/test/std/input.output/filesystems/class.path/path.nonmember/path.io.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/docs/Status/Cxx2bIssues.csv b/libcxx/docs/Status/Cxx2bIssues.csv
index 025a0c12d3317..1a8f6a4792c18 100644
--- a/libcxx/docs/Status/Cxx2bIssues.csv
+++ b/libcxx/docs/Status/Cxx2bIssues.csv
@@ -17,7 +17,7 @@
"`3120 <https://wg21.link/LWG3120>`__","Unclear behavior of ``monotonic_buffer_resource::release()``","November 2020","",""
"`3170 <https://wg21.link/LWG3170>`__","``is_always_equal`` added to ``std::allocator`` makes the standard library treat derived types as always equal","November 2020","",""
"`3036 <https://wg21.link/LWG3036>`__","``polymorphic_allocator::destroy`` is extraneous","November 2020","",""
-"`3171 <https://wg21.link/LWG3171>`__","LWG2989 breaks ``directory_entry`` stream insertion","November 2020","",""
+"`3171 <https://wg21.link/LWG3171>`__","LWG2989 breaks ``directory_entry`` stream insertion","November 2020","|Complete|","14.0"
"`3306 <https://wg21.link/LWG3306>`__","``ranges::advance`` violates its preconditions","November 2020","","","|ranges|"
"`3403 <https://wg21.link/LWG3403>`__","Domain of ``ranges::ssize(E)`` doesn't ``match ranges::size(E)``","November 2020","","","|ranges|"
"`3404 <https://wg21.link/LWG3404>`__","Finish removing subrange's conversions from pair-like","November 2020","","","|ranges|"
diff --git a/libcxx/include/__filesystem/directory_entry.h b/libcxx/include/__filesystem/directory_entry.h
index ba3ecfe78f72e..91dd1a2145883 100644
--- a/libcxx/include/__filesystem/directory_entry.h
+++ b/libcxx/include/__filesystem/directory_entry.h
@@ -23,6 +23,7 @@
#include <chrono>
#include <cstdint>
#include <cstdlib>
+#include <iosfwd>
#include <system_error>
_LIBCPP_PUSH_MACROS
@@ -239,6 +240,12 @@ class directory_entry {
return __p_ >= __rhs.__p_;
}
+ template <class _CharT, class _Traits>
+ _LIBCPP_INLINE_VISIBILITY
+ friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const directory_entry& __d) {
+ return __os << __d.path();
+ }
+
private:
friend class directory_iterator;
friend class recursive_directory_iterator;
diff --git a/libcxx/test/std/experimental/iterator/ostream.joiner/ostream.joiner.ops/ostream_joiner.op.assign.pass.cpp b/libcxx/test/std/experimental/iterator/ostream.joiner/ostream.joiner.ops/ostream_joiner.op.assign.pass.cpp
index 20074735699b0..c0bb1fdc3a3fd 100644
--- a/libcxx/test/std/experimental/iterator/ostream.joiner/ostream.joiner.ops/ostream_joiner.op.assign.pass.cpp
+++ b/libcxx/test/std/experimental/iterator/ostream.joiner/ostream.joiner.ops/ostream_joiner.op.assign.pass.cpp
@@ -89,6 +89,8 @@ int main(int, char**) {
test<char, const char *, wchar_t> ('X', chars, chars+10, L"0X1X2X3X4X5X6X7X8X9");
test<char, const int *, wchar_t> ('x', ints, ints+10, L"10x11x12x13x14x15x16x17x18x19");
#endif
+ // TODO(var-const): uncomment when it becomes possible to instantiate a `basic_ostream` object with a sized
+ // character type (see https://llvm.org/PR53119).
// test<char, const char *, char16_t>('X', chars, chars+10, u"0X1X2X3X4X5X6X7X8X9");
// test<char, const int *, char16_t>('x', ints, ints+10, u"10x11x12x13x14x15x16x17x18x19");
// test<char, const char *, char32_t>('X', chars, chars+10, U"0X1X2X3X4X5X6X7X8X9");
diff --git a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.io/directory_entry.io.pass.cpp b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.io/directory_entry.io.pass.cpp
new file mode 100644
index 0000000000000..bc3b55df58969
--- /dev/null
+++ b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.io/directory_entry.io.pass.cpp
@@ -0,0 +1,54 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+// UNSUPPORTED: libcpp-has-no-localization
+
+// <filesystem>
+//
+// class directory_entry
+//
+// template<class charT, class traits>
+// friend basic_ostream<charT, traits>&
+// operator<<(basic_ostream<charT, traits>& os, const directory_entry& d);
+
+#include "filesystem_include.h"
+#include <cassert>
+#include <sstream>
+
+#include "test_macros.h"
+#include "make_string.h"
+
+MultiStringType InStr = MKSTR("abcdefg/\"hijklmnop\"/qrstuvwxyz/123456789");
+MultiStringType OutStr = MKSTR("\"abcdefg/\\\"hijklmnop\\\"/qrstuvwxyz/123456789\"");
+
+template <class CharT>
+void TestOutput() {
+ const char* input = static_cast<const char*>(InStr);
+ const CharT* expected_output = static_cast<const CharT*>(OutStr);
+ const fs::directory_entry dir = fs::directory_entry(fs::path(input));
+ std::basic_stringstream<CharT> stream;
+
+ auto& result = stream << dir;
+ assert(stream.str() == expected_output);
+ assert(&result == &stream);
+}
+
+int main(int, char**) {
+ TestOutput<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ TestOutput<wchar_t>();
+#endif
+ // TODO(var-const): uncomment when it becomes possible to instantiate a `basic_ostream` object with a sized character
+ // type (see https://llvm.org/PR53119).
+ //TestOutput<char8_t>();
+ //TestOutput<char16_t>();
+ //TestOutput<char32_t>();
+
+ return 0;
+}
diff --git a/libcxx/test/std/input.output/filesystems/class.path/path.nonmember/path.io.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.nonmember/path.io.pass.cpp
index 572967175ea76..501ded7c37c6a 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.nonmember/path.io.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.nonmember/path.io.pass.cpp
@@ -94,6 +94,8 @@ int main(int, char**) {
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
doIOTest<wchar_t>();
#endif
+ // TODO(var-const): uncomment when it becomes possible to instantiate a `basic_ostream` object with a sized character
+ // type (see https://llvm.org/PR53119).
//doIOTest<char16_t>();
//doIOTest<char32_t>();
test_LWG2989();
More information about the libcxx-commits
mailing list