fix: [vs2015] error C3250: 'u': declaration is not allowed in 'constexpr' function body

This commit is contained in:
mutouyun 2022-05-15 19:58:53 +08:00
parent d129e6221a
commit c1557a72ac
4 changed files with 22 additions and 6 deletions

View File

@ -12,14 +12,20 @@
LIBIMP_NAMESPACE_BEG_
namespace detail_horrible_cast {
template <typename T, typename U>
union temp {
std::decay_t<U> in;
T out;
};
} // namespace detail_horrible_cast
template <typename T, typename U>
constexpr auto horrible_cast(U &&in) noexcept
-> std::enable_if_t<(sizeof(T) == sizeof(std::decay_t<U>)), T> {
union {
std::decay_t<U> in;
T out;
} u {std::forward<U>(in)};
return u.out;
return detail_horrible_cast::temp<T, std::decay_t<U>>{std::forward<U>(in)}.out;
}
LIBIMP_NAMESPACE_END_

View File

@ -154,7 +154,7 @@ LIBIMP_NAMESPACE_END_
template <typename T, typename D>
struct fmt::formatter<::LIBIMP_::result<T, D>> {
constexpr auto parse(format_parse_context& ctx) {
constexpr auto parse(format_parse_context& ctx) const {
return ctx.end();
}

View File

@ -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

View File

@ -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