1 // Copyright (c) 2019-2020 Antony Polukhin.
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #ifndef BOOST_PFR_DETAIL_UNSAFE_DECLVAL_HPP
7 #define BOOST_PFR_DETAIL_UNSAFE_DECLVAL_HPP
9 #include <boost/pfr/detail/config.hpp>
11 #include <type_traits>
13 namespace boost { namespace pfr { namespace detail {
15 // This function serves as a link-time assert. If linker requires it, then
16 // `unsafe_declval()` is used at runtime.
17 void report_if_you_see_link_error_with_this_function() noexcept;
19 // For returning non default constructible types. Do NOT use at runtime!
21 // GCCs std::declval may not be used in potentionally evaluated contexts,
24 constexpr T unsafe_declval() noexcept {
25 report_if_you_see_link_error_with_this_function();
27 typename std::remove_reference<T>::type* ptr = 0;
28 ptr += 42; // suppresses 'null pointer dereference' warnings
29 return static_cast<T>(*ptr);
32 }}} // namespace boost::pfr::detail
35 #endif // BOOST_PFR_DETAIL_UNSAFE_DECLVAL_HPP