From 5ed350c82e748b38da93e6bd4c53b2cdcc43bf24 Mon Sep 17 00:00:00 2001 From: LNKLEO Date: Thu, 6 Feb 2025 16:24:00 +0800 Subject: [PATCH] [Build] compatibility with VS17.3 and later, for C++23 has been introduced in VS17.3.6, and std::expected has conflict/inconsistent with the makeshift (expected-lite) --- src/common/updating/updating.cpp | 12 ++++++++++++ src/common/updating/updating.h | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/common/updating/updating.cpp b/src/common/updating/updating.cpp index 361e77bc4f65..9d80662d5423 100644 --- a/src/common/updating/updating.cpp +++ b/src/common/updating/updating.cpp @@ -82,12 +82,20 @@ namespace updating // prevent the warning that may show up depend on the value of the constants (#defines) #pragma warning(push) #pragma warning(disable : 4702) +#if USE_STD_EXPECTED + std::future> get_github_version_info_async(const bool prerelease) +#else std::future> get_github_version_info_async(const bool prerelease) +#endif { // If the current version starts with 0.0.*, it means we're on a local build from a farm and shouldn't check for updates. if constexpr (VERSION_MAJOR == 0 && VERSION_MINOR == 0) { +#if USE_STD_EXPECTED + co_return std::unexpected(LOCAL_BUILD_ERROR); +#else co_return nonstd::make_unexpected(LOCAL_BUILD_ERROR); +#endif } try @@ -139,7 +147,11 @@ namespace updating catch (...) { } +#if USE_STD_EXPECTED + co_return std::unexpected(NETWORK_ERROR); +#else co_return nonstd::make_unexpected(NETWORK_ERROR); +#endif } #pragma warning(pop) diff --git a/src/common/updating/updating.h b/src/common/updating/updating.h index 155002361fd7..148a5e5b2544 100644 --- a/src/common/updating/updating.h +++ b/src/common/updating/updating.h @@ -6,7 +6,14 @@ #include #include #include +//#if __MSVC_VERSION__ >= 1933 // MSVC begin to support std::unexpected in 19.33 +#if __has_include( ) // use the same way with excepted-lite to detect std::unexcepted, as using it as backup +#include +#define USE_STD_EXPECTED 1 +#else #include +#define USE_STD_EXPECTED 0 +#endif #include @@ -27,7 +34,11 @@ namespace updating std::future> download_new_version(const new_version_download_info& new_version); std::filesystem::path get_pending_updates_path(); +#if USE_STD_EXPECTED + std::future> get_github_version_info_async(const bool prerelease = false); +#else std::future> get_github_version_info_async(const bool prerelease = false); +#endif void cleanup_updates(); // non-localized