From eef2c2ba55ccf453fca6988b09e761940d49d748 Mon Sep 17 00:00:00 2001 From: Steffen Schuemann Date: Sat, 26 Dec 2020 15:14:32 +0100 Subject: [PATCH] refs #81, work on incomplete string_view support when using c++17 --- .clang-tidy | 3 +++ include/ghc/filesystem.hpp | 12 ++++++------ test/CMakeLists.txt | 17 +++++++++++++++++ test/filesystem_test.cpp | 7 ++++++- 4 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..203d506 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,3 @@ +--- +Checks: -modernize-use-nodiscard +... diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index f247ead..0b12242 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -1569,14 +1569,14 @@ inline StringType fromUtf8(const std::string& utf8String, const typename StringT return result; } -template ::type size = 1> -inline std::string toUtf8(const std::basic_string& unicodeString) +template ::value && (sizeof(typename strT::value_type) == 1), int>::type size = 1> +inline std::string toUtf8(const strT& unicodeString) { return std::string(unicodeString.begin(), unicodeString.end()); } -template ::type size = 2> -inline std::string toUtf8(const std::basic_string& unicodeString) +template ::value && (sizeof(typename strT::value_type) == 2), int>::type size = 2> +inline std::string toUtf8(const strT& unicodeString) { std::string result; for (auto iter = unicodeString.begin(); iter != unicodeString.end(); ++iter) { @@ -1604,8 +1604,8 @@ inline std::string toUtf8(const std::basic_string& unicode return result; } -template ::type size = 4> -inline std::string toUtf8(const std::basic_string& unicodeString) +template ::value && (sizeof(typename strT::value_type) == 4), int>::type size = 4> +inline std::string toUtf8(const strT& unicodeString) { std::string result; for (auto c : unicodeString) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 72ff653..8b2d9f3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -44,6 +44,23 @@ else() endif() ParseAndAddCatchTests(filesystem_test_wchar) endif() + if("cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES) + add_executable(filesystem_test_cpp17 filesystem_test.cpp catch.hpp) + set_property(TARGET filesystem_test_cpp17 PROPERTY CXX_STANDARD 17) + target_link_libraries(filesystem_test_cpp17 ghc_filesystem) + target_compile_options(filesystem_test_cpp17 PRIVATE + $<$:-s DISABLE_EXCEPTION_CATCHING=0> + $<$:-Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wpedantic -Werror> + $<$:-Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wpedantic -Wno-psabi -Werror> + $<$:/WX>) + if(CMAKE_CXX_COMPILER_ID MATCHES MSVC) + target_compile_definitions(filesystem_test_cpp17 PRIVATE _CRT_SECURE_NO_WARNINGS) + endif() + if(EMSCRIPTEN) + set_target_properties(filesystem_test_cpp17 PROPERTIES LINK_FLAGS "-g4 -s DISABLE_EXCEPTION_CATCHING=0 -s ALLOW_MEMORY_GROWTH=1") + endif() + ParseAndAddCatchTests(filesystem_test_cpp17) + endif() endif() add_executable(multifile_test multi1.cpp multi2.cpp catch.hpp) diff --git a/test/filesystem_test.cpp b/test/filesystem_test.cpp index c3df41a..d473213 100644 --- a/test/filesystem_test.cpp +++ b/test/filesystem_test.cpp @@ -2689,6 +2689,7 @@ 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 + using namespace std::literals; { std::string p("foo/bar"); std::string_view sv(p); @@ -2698,7 +2699,11 @@ TEST_CASE("std::string_view support", "[filesystem][fs.string_view]") CHECK(p2 == "foo"); CHECK(p2.compare(std::string_view("foo")) == 0); } - + { + auto p = fs::path{"XYZ"}; + p /= "Appendix"sv; + CHECK(p == "XYZ/Appendix"); + } #if defined(IS_WCHAR_PATH) || defined(GHC_USE_WCHAR_T) { std::wstring p(L"foo/bar");