From 053f503770118d2fa614b939869930cc1e734741 Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Mon, 3 Feb 2020 16:07:50 +0100 Subject: [PATCH] Update ghc::filesystem, eliminating the warnings --- src/external/ghc/filesystem.hpp | 126 ++++++++++++++++++++------------ 1 file changed, 78 insertions(+), 48 deletions(-) diff --git a/src/external/ghc/filesystem.hpp b/src/external/ghc/filesystem.hpp index 4e57b724..899eefde 100644 --- a/src/external/ghc/filesystem.hpp +++ b/src/external/ghc/filesystem.hpp @@ -171,13 +171,13 @@ // as ghc::filesystem::string_type. // #define GHC_WIN_WSTRING_STRING_TYPE //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// Rais errors/exceptions when invalid unicode codepoints or UTF-8 sequences are found, +// Raise errors/exceptions when invalid unicode codepoints or UTF-8 sequences are found, // instead of replacing them with the unicode replacement character (U+FFFD). // #define GHC_RAISE_UNICODE_ERRORS //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // ghc::filesystem version in decimal (major * 10000 + minor * 100 + patch) -#define GHC_FILESYSTEM_VERSION 10205L +#define GHC_FILESYSTEM_VERSION 10211L namespace ghc { namespace filesystem { @@ -192,24 +192,40 @@ public: } }; -// 30.10.8 class path -class GHC_FS_API_CLASS path +template +class path_helper_base { public: + using value_type = char_type; #ifdef GHC_OS_WINDOWS -#ifdef GHC_WIN_WSTRING_STRING_TYPE -#define GHC_USE_WCHAR_T - using value_type = std::wstring::value_type; -#else - using value_type = std::string::value_type; -#endif - using string_type = std::basic_string; static constexpr value_type preferred_separator = '\\'; #else - using value_type = std::string::value_type; - using string_type = std::basic_string; static constexpr value_type preferred_separator = '/'; #endif +}; + +#if __cplusplus < 201703L +template +constexpr char_type path_helper_base::preferred_separator; +#endif + +// 30.10.8 class path +class GHC_FS_API_CLASS path +#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_WSTRING_STRING_TYPE) +#define GHC_USE_WCHAR_T + : private path_helper_base +{ +public: + using path_helper_base::value_type; +#else + : private path_helper_base +{ +public: + using path_helper_base::value_type; +#endif + using string_type = std::basic_string; + using path_helper_base::preferred_separator; + // 30.10.10.1 enumeration format /// The path format in wich the constructor argument is given. enum format { @@ -661,7 +677,7 @@ private: file_status _symlink_status; uintmax_t _file_size = 0; #ifndef GHC_OS_WINDOWS - uintmax_t _hard_link_count; + uintmax_t _hard_link_count = 0; #endif time_t _last_write_time = 0; }; @@ -1070,7 +1086,7 @@ enum class portable_error { }; GHC_FS_API std::error_code make_error_code(portable_error err); #ifdef GHC_OS_WINDOWS -GHC_FS_API std::error_code make_system_error(DWORD err = 0); +GHC_FS_API std::error_code make_system_error(uint32_t err = 0); #else GHC_FS_API std::error_code make_system_error(int err = 0); #endif @@ -1125,7 +1141,7 @@ GHC_INLINE std::error_code make_error_code(portable_error err) } #ifdef GHC_OS_WINDOWS -GHC_INLINE std::error_code make_system_error(DWORD err) +GHC_INLINE std::error_code make_system_error(uint32_t err) { return std::error_code(err ? static_cast(err) : static_cast(::GetLastError()), std::system_category()); } @@ -1197,7 +1213,7 @@ namespace detail { GHC_INLINE bool in_range(uint32_t c, uint32_t lo, uint32_t hi) { - return ((uint32_t)(c - lo) < (hi - lo + 1)); + return (static_cast(c - lo) < (hi - lo + 1)); } GHC_INLINE bool is_surrogate(uint32_t c) @@ -1265,7 +1281,7 @@ GHC_INLINE bool validUtf8(const std::string& utf8String) unsigned utf8_state = S_STRT; std::uint32_t codepoint = 0; while (iter < utf8String.end()) { - if ((utf8_state = consumeUtf8Fragment(utf8_state, (uint8_t)*iter++, codepoint)) == S_RJCT) { + if ((utf8_state = consumeUtf8Fragment(utf8_state, static_cast(*iter++), codepoint)) == S_RJCT) { return false; } } @@ -1296,14 +1312,14 @@ inline StringType fromUtf8(const std::string& utf8String, const typename StringT unsigned utf8_state = S_STRT; std::uint32_t codepoint = 0; while (iter < utf8String.end()) { - if ((utf8_state = consumeUtf8Fragment(utf8_state, (uint8_t)*iter++, codepoint)) == S_STRT) { + if ((utf8_state = consumeUtf8Fragment(utf8_state, static_cast(*iter++), codepoint)) == S_STRT) { if (codepoint <= 0xffff) { - result += (typename StringType::value_type)codepoint; + result += static_cast(codepoint); } else { codepoint -= 0x10000; - result += (typename StringType::value_type)((codepoint >> 10) + 0xd800); - result += (typename StringType::value_type)((codepoint & 0x3ff) + 0xdc00); + result += static_cast((codepoint >> 10) + 0xd800); + result += static_cast((codepoint & 0x3ff) + 0xdc00); } codepoint = 0; } @@ -1311,7 +1327,7 @@ inline StringType fromUtf8(const std::string& utf8String, const typename StringT #ifdef GHC_RAISE_UNICODE_ERRORS throw filesystem_error("Illegal byte sequence for unicode character.", utf8String, std::make_error_code(std::errc::illegal_byte_sequence)); #else - result += (typename StringType::value_type)0xfffd; + result += static_cast(0xfffd); utf8_state = S_STRT; codepoint = 0; #endif @@ -1321,7 +1337,7 @@ inline StringType fromUtf8(const std::string& utf8String, const typename StringT #ifdef GHC_RAISE_UNICODE_ERRORS throw filesystem_error("Illegal byte sequence for unicode character.", utf8String, std::make_error_code(std::errc::illegal_byte_sequence)); #else - result += (typename StringType::value_type)0xfffd; + result += static_cast(0xfffd); #endif } return result; @@ -1336,7 +1352,7 @@ inline StringType fromUtf8(const std::string& utf8String, const typename StringT unsigned utf8_state = S_STRT; std::uint32_t codepoint = 0; while (iter < utf8String.end()) { - if ((utf8_state = consumeUtf8Fragment(utf8_state, (uint8_t)*iter++, codepoint)) == S_STRT) { + if ((utf8_state = consumeUtf8Fragment(utf8_state, static_cast(*iter++), codepoint)) == S_STRT) { result += static_cast(codepoint); codepoint = 0; } @@ -1344,7 +1360,7 @@ inline StringType fromUtf8(const std::string& utf8String, const typename StringT #ifdef GHC_RAISE_UNICODE_ERRORS throw filesystem_error("Illegal byte sequence for unicode character.", utf8String, std::make_error_code(std::errc::illegal_byte_sequence)); #else - result += (typename StringType::value_type)0xfffd; + result += static_cast(0xfffd); utf8_state = S_STRT; codepoint = 0; #endif @@ -1354,7 +1370,7 @@ inline StringType fromUtf8(const std::string& utf8String, const typename StringT #ifdef GHC_RAISE_UNICODE_ERRORS throw filesystem_error("Illegal byte sequence for unicode character.", utf8String, std::make_error_code(std::errc::illegal_byte_sequence)); #else - result += (typename StringType::value_type)0xfffd; + result += static_cast(0xfffd); #endif } return result; @@ -1578,11 +1594,6 @@ GHC_INLINE std::string systemErrorText(ErrorNumber code = 0) using CreateSymbolicLinkW_fp = BOOLEAN(WINAPI*)(LPCWSTR, LPCWSTR, DWORD); using CreateHardLinkW_fp = BOOLEAN(WINAPI*)(LPCWSTR, LPCWSTR, LPSECURITY_ATTRIBUTES); -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-function-type" -#endif - GHC_INLINE void create_symlink(const path& target_name, const path& new_symlink, bool to_directory, std::error_code& ec) { std::error_code tec; @@ -1591,7 +1602,14 @@ GHC_INLINE void create_symlink(const path& target_name, const path& new_symlink, ec = detail::make_error_code(detail::portable_error::not_supported); return; } +#if defined(__GNUC__) && __GNUC__ >= 8 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-function-type" +#endif static CreateSymbolicLinkW_fp api_call = reinterpret_cast(GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "CreateSymbolicLinkW")); +#if defined(__GNUC__) && __GNUC__ >= 8 +#pragma GCC diagnostic pop +#endif if (api_call) { if (api_call(detail::fromUtf8(new_symlink.u8string()).c_str(), detail::fromUtf8(target_name.u8string()).c_str(), to_directory ? 1 : 0) == 0) { auto result = ::GetLastError(); @@ -1608,7 +1626,14 @@ GHC_INLINE void create_symlink(const path& target_name, const path& new_symlink, GHC_INLINE void create_hardlink(const path& target_name, const path& new_hardlink, std::error_code& ec) { +#if defined(__GNUC__) && __GNUC__ >= 8 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-function-type" +#endif static CreateHardLinkW_fp api_call = reinterpret_cast(GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "CreateHardLinkW")); +#if defined(__GNUC__) && __GNUC__ >= 8 +#pragma GCC diagnostic pop +#endif if (api_call) { if (api_call(detail::fromUtf8(new_hardlink.u8string()).c_str(), detail::fromUtf8(target_name.u8string()).c_str(), NULL) == 0) { ec = detail::make_system_error(); @@ -1618,11 +1643,6 @@ GHC_INLINE void create_hardlink(const path& target_name, const path& new_hardlin ec = detail::make_system_error(ERROR_NOT_SUPPORTED); } } - -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif - #else GHC_INLINE void create_symlink(const path& target_name, const path& new_symlink, bool, std::error_code& ec) { @@ -1752,7 +1772,7 @@ GHC_INLINE path resolveSymlink(const path& p, std::error_code& ec) #else size_t bufferSize = 256; while (true) { - std::vector buffer(bufferSize, (char)0); + std::vector buffer(bufferSize, static_cast(0)); auto rc = ::readlink(p.c_str(), buffer.data(), buffer.size()); if (rc < 0) { ec = detail::make_system_error(); @@ -2505,7 +2525,7 @@ GHC_INLINE path path::parent_path() const } else { path pp; - for (const string_type& s : input_iterator_range(begin(), --end())) { + for (string_type s : input_iterator_range(begin(), --end())) { if (s == "/") { // don't use append to join a path- pp += s; @@ -2531,12 +2551,12 @@ GHC_INLINE path path::stem() const { impl_string_type fn = filename().string(); if (fn != "." && fn != "..") { - impl_string_type::size_type n = fn.rfind("."); + impl_string_type::size_type n = fn.rfind('.'); if (n != impl_string_type::npos && n != 0) { - return fn.substr(0, n); + return path{fn.substr(0, n)}; } } - return fn; + return path{fn}; } GHC_INLINE path path::extension() const @@ -2615,7 +2635,8 @@ GHC_INLINE bool path::is_relative() const GHC_INLINE path path::lexically_normal() const { path dest; - for (const string_type& s : *this) { + bool lastDotDot = false; + for (string_type s : *this) { if (s == ".") { dest /= ""; continue; @@ -2633,7 +2654,10 @@ GHC_INLINE path path::lexically_normal() const continue; } } - dest /= s; + if (!(s.empty() && lastDotDot)) { + dest /= s; + } + lastDotDot = s == ".."; } if (dest.empty()) { dest = "."; @@ -3369,7 +3393,7 @@ GHC_INLINE bool create_directories(const path& p, std::error_code& ec) noexcept { path current; ec.clear(); - for (const path::string_type& part : p) { + for (path::string_type part : p) { current /= part; if (current != p.root_name() && current != p.root_path()) { std::error_code tec; @@ -3381,7 +3405,12 @@ GHC_INLINE bool create_directories(const path& p, std::error_code& ec) noexcept if (!exists(fs)) { create_directory(current, ec); if (ec) { - return false; + std::error_code tmp_ec; + if (is_directory(current, tmp_ec)) { + ec.clear(); + } else { + return false; + } } } #ifndef LWG_2935_BEHAVIOUR @@ -3529,7 +3558,7 @@ GHC_INLINE path current_path(std::error_code& ec) #else size_t pathlen = static_cast(std::max(int(::pathconf(".", _PC_PATH_MAX)), int(PATH_MAX))); std::unique_ptr buffer(new char[pathlen + 1]); - if (::getcwd(buffer.get(), pathlen) == NULL) { + if (::getcwd(buffer.get(), pathlen) == nullptr) { ec = detail::make_system_error(); return path(); } @@ -4161,7 +4190,7 @@ GHC_INLINE void rename(const path& from, const path& to, std::error_code& ec) no ec.clear(); #ifdef GHC_OS_WINDOWS if (from != to) { - if (!MoveFileW(detail::fromUtf8(from.u8string()).c_str(), detail::fromUtf8(to.u8string()).c_str())) { + if (!MoveFileExW(detail::fromUtf8(from.u8string()).c_str(), detail::fromUtf8(to.u8string()).c_str(), (DWORD)MOVEFILE_REPLACE_EXISTING)) { ec = detail::make_system_error(); } } @@ -4237,6 +4266,7 @@ GHC_INLINE space_info space(const path& p, std::error_code& ec) noexcept } return {static_cast(sfs.f_blocks * sfs.f_frsize), static_cast(sfs.f_bfree * sfs.f_frsize), static_cast(sfs.f_bavail * sfs.f_frsize)}; #else + (void)p; ec = detail::make_error_code(detail::portable_error::not_supported); return {static_cast(-1), static_cast(-1), static_cast(-1)}; #endif