From c1557a72ac282b04596f9d82706123881ae49f5d Mon Sep 17 00:00:00 2001 From: mutouyun Date: Sun, 15 May 2022 19:58:53 +0800 Subject: [PATCH] fix: [vs2015] error C3250: 'u': declaration is not allowed in 'constexpr' function body --- include/libimp/horrible_cast.h | 16 +++++++++++----- include/libimp/result.h | 2 +- src/libimp/CMakeLists.txt | 5 +++++ src/libipc/CMakeLists.txt | 5 +++++ 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/include/libimp/horrible_cast.h b/include/libimp/horrible_cast.h index 88520c6..cce6ef7 100644 --- a/include/libimp/horrible_cast.h +++ b/include/libimp/horrible_cast.h @@ -12,14 +12,20 @@ LIBIMP_NAMESPACE_BEG_ +namespace detail_horrible_cast { + +template +union temp { + std::decay_t in; + T out; +}; + +} // namespace detail_horrible_cast + template constexpr auto horrible_cast(U &&in) noexcept -> std::enable_if_t<(sizeof(T) == sizeof(std::decay_t)), T> { - union { - std::decay_t in; - T out; - } u {std::forward(in)}; - return u.out; + return detail_horrible_cast::temp>{std::forward(in)}.out; } LIBIMP_NAMESPACE_END_ diff --git a/include/libimp/result.h b/include/libimp/result.h index e72052b..81f94c8 100644 --- a/include/libimp/result.h +++ b/include/libimp/result.h @@ -154,7 +154,7 @@ LIBIMP_NAMESPACE_END_ template struct fmt::formatter<::LIBIMP_::result> { - constexpr auto parse(format_parse_context& ctx) { + constexpr auto parse(format_parse_context& ctx) const { return ctx.end(); } diff --git a/src/libimp/CMakeLists.txt b/src/libimp/CMakeLists.txt index 65e3405..4e5fc42 100644 --- a/src/libimp/CMakeLists.txt +++ b/src/libimp/CMakeLists.txt @@ -1,5 +1,10 @@ project(imp) +if(NOT MSVC) + add_compile_options( + -Wno-attributes) +endif() + aux_source_directory(${LIBIPC_PROJECT_DIR}/src/libimp SRC_FILES) file(GLOB HEAD_FILES diff --git a/src/libipc/CMakeLists.txt b/src/libipc/CMakeLists.txt index 60007c1..7eed20b 100644 --- a/src/libipc/CMakeLists.txt +++ b/src/libipc/CMakeLists.txt @@ -1,5 +1,10 @@ project(ipc) +if(NOT MSVC) + add_compile_options( + -Wno-attributes) +endif() + aux_source_directory(${LIBIPC_PROJECT_DIR}/src/libipc SRC_FILES) file(GLOB HEAD_FILES