From fdf5bb0179f3cca7b42a8b86f08fa5ff5aba3e69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Sch=C3=BCmann?= Date: Sun, 7 Feb 2021 10:02:12 +0100 Subject: [PATCH] refs #90, made wchar_t/wstring default on Windows --- include/ghc/filesystem.hpp | 13 ++++++++----- include/ghc/fs_std.hpp | 2 +- include/ghc/fs_std_fwd.hpp | 2 +- include/ghc/fs_std_impl.hpp | 2 +- test/CMakeLists.txt | 12 ++++++------ 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index 59610b8..160f257 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -225,10 +225,13 @@ // LWG #2937 enforces that fs::equivalent emits an error, if !fs::exists(p1)||!exists(p2) #define LWG_2937_BEHAVIOUR //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// UTF8-Everywhere is the original behaviour of ghc::filesystem. With this define you can -// enable the more standard conforming implementation option that uses wstring on Windows -// as ghc::filesystem::string_type. -// #define GHC_WIN_WSTRING_STRING_TYPE +// UTF8-Everywhere is the original behaviour of ghc::filesystem. But since v1.5 the windows +// version defaults to std::wstring storage backend. Still all std::string will be interpreted +// as UTF-8 encoded. With this define you can enfoce the old behavior on Windows, using +// std::string as backend and for fs::path::native() and char for fs::path::c_str(). This +// needs more conversions so it is (an was before v1.5) slower, bot might help keeping source +// homogenous in a multi platform project. +// #define GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Raise errors/exceptions when invalid unicode codepoints or UTF-8 sequences are found, // instead of replacing them with the unicode replacement character (U+FFFD). @@ -290,7 +293,7 @@ bool has_executable_extension(const path& p); // 30.10.8 class path class GHC_FS_API_CLASS path -#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_WSTRING_STRING_TYPE) +#if defined(GHC_OS_WINDOWS) && !defined(GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE) #define GHC_USE_WCHAR_T #define GHC_NATIVEWP(p) p.c_str() #define GHC_PLATFORM_LITERAL(str) L##str diff --git a/include/ghc/fs_std.hpp b/include/ghc/fs_std.hpp index f295e37..0d9d3cc 100644 --- a/include/ghc/fs_std.hpp +++ b/include/ghc/fs_std.hpp @@ -43,7 +43,7 @@ using fstream = std::fstream; #endif #endif #ifndef GHC_USE_STD_FS -#define GHC_WIN_WSTRING_STRING_TYPE +//#define GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE #include namespace fs { using namespace ghc::filesystem; diff --git a/include/ghc/fs_std_fwd.hpp b/include/ghc/fs_std_fwd.hpp index f07c09b..148751e 100644 --- a/include/ghc/fs_std_fwd.hpp +++ b/include/ghc/fs_std_fwd.hpp @@ -46,7 +46,7 @@ using fstream = std::fstream; #endif #endif #ifndef GHC_USE_STD_FS -#define GHC_WIN_WSTRING_STRING_TYPE +//#define GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE #define GHC_FILESYSTEM_FWD #include namespace fs { diff --git a/include/ghc/fs_std_impl.hpp b/include/ghc/fs_std_impl.hpp index d7b609d..455438d 100644 --- a/include/ghc/fs_std_impl.hpp +++ b/include/ghc/fs_std_impl.hpp @@ -37,7 +37,7 @@ #endif #endif #ifndef GHC_USE_STD_FS -#define GHC_WIN_WSTRING_STRING_TYPE +//#define GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE #define GHC_FILESYSTEM_IMPLEMENTATION #include #endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a463231..3ad4271 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -31,18 +31,18 @@ else() ParseAndAddCatchTests(filesystem_test) AddExecutableWithStdFS(std_filesystem_test filesystem_test.cpp catch.hpp) if(WIN32) - add_executable(filesystem_test_wchar filesystem_test.cpp catch.hpp) - target_link_libraries(filesystem_test_wchar ghc_filesystem) - target_compile_options(filesystem_test_wchar PRIVATE + add_executable(filesystem_test_char filesystem_test.cpp catch.hpp) + target_link_libraries(filesystem_test_char ghc_filesystem) + target_compile_options(filesystem_test_char PRIVATE $<$:-Wall -Wextra -Werror> $<$:-Wall -Werror> $<$:/WX>) if(CMAKE_CXX_COMPILER_ID MATCHES MSVC) - target_compile_definitions(filesystem_test_wchar PRIVATE _CRT_SECURE_NO_WARNINGS GHC_WIN_WSTRING_STRING_TYPE) + target_compile_definitions(filesystem_test_char PRIVATE _CRT_SECURE_NO_WARNINGS GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE) else() - target_compile_definitions(filesystem_test_wchar PRIVATE GHC_WIN_WSTRING_STRING_TYPE) + target_compile_definitions(filesystem_test_char PRIVATE GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE) endif() - ParseAndAddCatchTests(filesystem_test_wchar) + ParseAndAddCatchTests(filesystem_test_char) endif() if("cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES) AddTestExecutableWithStdCpp(17 filesystem_test.cpp catch.hpp)