From 2d06866d642929b9444c3b54a718f8a60db05c87 Mon Sep 17 00:00:00 2001 From: Denis Mikhailov Date: Mon, 4 Dec 2023 23:19:30 +0100 Subject: [PATCH] Get rid of cast_to_layout_compatible --- .../pfr/detail/cast_to_layout_compatible.hpp | 75 ------------------- include/boost/pfr/detail/core14_loophole.hpp | 1 - 2 files changed, 76 deletions(-) delete mode 100644 include/boost/pfr/detail/cast_to_layout_compatible.hpp diff --git a/include/boost/pfr/detail/cast_to_layout_compatible.hpp b/include/boost/pfr/detail/cast_to_layout_compatible.hpp deleted file mode 100644 index c9f440e6..00000000 --- a/include/boost/pfr/detail/cast_to_layout_compatible.hpp +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) 2016-2023 Antony Polukhin -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -#ifndef BOOST_PFR_DETAIL_CAST_TO_LAYOUT_COMPATIBLE_HPP -#define BOOST_PFR_DETAIL_CAST_TO_LAYOUT_COMPATIBLE_HPP -#pragma once - -#include - -#include -#include // metaprogramming stuff -#include - -namespace boost { namespace pfr { namespace detail { - -template -constexpr void static_assert_layout_compatible() noexcept { - static_assert( - std::alignment_of::value == std::alignment_of::value, - "====================> Boost.PFR: Alignment check failed, probably your structure has user-defined alignment for the whole structure or for some of the fields." - ); - static_assert(sizeof(T) == sizeof(U), "====================> Boost.PFR: Size check failed, probably your structure has bitfields or user-defined alignment."); -} - -/// @cond -#ifdef __GNUC__ -#define MAY_ALIAS __attribute__((__may_alias__)) -#else -#define MAY_ALIAS -#endif -/// @endcond - -template -MAY_ALIAS const To& cast_to_layout_compatible(const From& val) noexcept { - MAY_ALIAS const To* const t = reinterpret_cast( std::addressof(val) ); - detail::static_assert_layout_compatible(); - return *t; -} - -template -MAY_ALIAS const volatile To& cast_to_layout_compatible(const volatile From& val) noexcept { - MAY_ALIAS const volatile To* const t = reinterpret_cast( std::addressof(val) ); - detail::static_assert_layout_compatible(); - return *t; -} - - -template -MAY_ALIAS volatile To& cast_to_layout_compatible(volatile From& val) noexcept { - MAY_ALIAS volatile To* const t = reinterpret_cast( std::addressof(val) ); - detail::static_assert_layout_compatible(); - return *t; -} - - -template -MAY_ALIAS To& cast_to_layout_compatible(From& val) noexcept { - MAY_ALIAS To* const t = reinterpret_cast( std::addressof(val) ); - detail::static_assert_layout_compatible(); - return *t; -} - -#ifdef BOOST_PFR_DETAIL_STRICT_RVALUE_TESTING -template -To&& cast_to_layout_compatible(rvalue_t val) noexcept = delete; -#endif - -#undef MAY_ALIAS - - -}}} // namespace boost::pfr::detail - -#endif // BOOST_PFR_DETAIL_CAST_TO_LAYOUT_COMPATIBLE_HPP diff --git a/include/boost/pfr/detail/core14_loophole.hpp b/include/boost/pfr/detail/core14_loophole.hpp index 78534b59..9a6c48cc 100644 --- a/include/boost/pfr/detail/core14_loophole.hpp +++ b/include/boost/pfr/detail/core14_loophole.hpp @@ -27,7 +27,6 @@ #include #include -#include // still needed for enums #include #include #include