From a5cadd2e5060da75315f79971dae56a0e91a8023 Mon Sep 17 00:00:00 2001 From: Steffen Schuemann Date: Thu, 9 Apr 2020 11:45:36 +0200 Subject: [PATCH] refs #63, work on issues with wchar and clang in windows. --- include/ghc/filesystem.hpp | 14 +++++++++++--- test/filesystem_test.cpp | 29 ++++++++++++++++++++++------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index 9cbde6d..5cd76ae 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -1676,6 +1676,14 @@ inline path::path(const std::string_view& source, format fmt) _path = detail::toUtf8(std::string(source)); postprocess_path_with_format(_path, fmt); } +#ifdef GHC_USE_WCHAR_T +template <> +inline path::path(const std::wstring_view& source, format fmt) +{ + _path = detail::toUtf8(std::wstring(source).c_str()); + postprocess_path_with_format(_path, fmt); +} +#endif #endif template @@ -4506,9 +4514,9 @@ GHC_INLINE space_info space(const path& p, std::error_code& ec) noexcept { ec.clear(); #ifdef GHC_OS_WINDOWS - ULARGE_INTEGER freeBytesAvailableToCaller = {0, 0}; - ULARGE_INTEGER totalNumberOfBytes = {0, 0}; - ULARGE_INTEGER totalNumberOfFreeBytes = {0, 0}; + ULARGE_INTEGER freeBytesAvailableToCaller = {{0, 0}}; + ULARGE_INTEGER totalNumberOfBytes = {{0, 0}}; + ULARGE_INTEGER totalNumberOfFreeBytes = {{0, 0}}; if (!GetDiskFreeSpaceExW(detail::fromUtf8(p.u8string()).c_str(), &freeBytesAvailableToCaller, &totalNumberOfBytes, &totalNumberOfFreeBytes)) { ec = detail::make_system_error(); return {static_cast(-1), static_cast(-1), static_cast(-1)}; diff --git a/test/filesystem_test.cpp b/test/filesystem_test.cpp index 8e21369..82e0495 100644 --- a/test/filesystem_test.cpp +++ b/test/filesystem_test.cpp @@ -2628,13 +2628,28 @@ TEST_CASE("30.10.15.39 weakly_canonical", "[filesystem][operations][fs.op.weakly TEST_CASE("std::string_view support", "[filesystem][fs.string_view]") { #if __cpp_lib_string_view - std::string p("foo/bar"); - std::string_view sv(p); - CHECK(fs::path(sv, fs::path::format::generic_format).generic_string() == "foo/bar"); - fs::path p2("fo"); - p2 += std::string_view("o"); - CHECK(p2 == "foo"); - CHECK(p2.compare(std::string_view("foo")) == 0); + { + std::string p("foo/bar"); + std::string_view sv(p); + CHECK(fs::path(sv, fs::path::format::generic_format).generic_string() == "foo/bar"); + fs::path p2("fo"); + p2 += std::string_view("o"); + CHECK(p2 == "foo"); + CHECK(p2.compare(std::string_view("foo")) == 0); + } + +#if defined(IS_WCHAR_PATH) || defined(GHC_USE_WCHAR_T) + { + std::wsting p(L"foo/bar"); + std::wstring_view sv(p); + CHECK(fs::path(sv, fs::path::format::generic_format).generic_string() == "foo/bar"); + fs::path p2(L"fo"); + p2 += std::wstring_view(L"o"); + CHECK(p2 == "foo"); + CHECK(p2.compare(std::wstring_view(L"foo")) == 0); + } +#endif + #else WARN("std::string_view specific tests are empty without std::string_view."); #endif