2
0
mirror of https://github.com/boostorg/pfr.git synced 2026-01-21 05:02:15 +00:00

Compare commits

..

4 Commits
1.0.2 ... 1.0.3

Author SHA1 Message Date
Antony Polukhin
89b1d45ff7 fix definition 2020-08-16 10:59:27 +03:00
Antony Polukhin
26867f47b7 fix warnings in tests 2020-08-16 10:58:36 +03:00
Antony Polukhin
b9166fd38e avoid copy-paste 2020-08-16 09:54:53 +03:00
Antony Polukhin
915bd9217c add link-time assertion to the unsafe_declval() function 2020-08-16 09:51:07 +03:00
4 changed files with 20 additions and 11 deletions

View File

@@ -18,6 +18,7 @@
#include <boost/pfr/detail/make_flat_tuple_of_references.hpp>
#include <boost/pfr/detail/make_integer_sequence.hpp>
#include <boost/pfr/detail/size_array.hpp>
#include <boost/pfr/detail/size_t_.hpp>
#include <boost/pfr/detail/rvalue_t.hpp>
#ifdef __clang__
@@ -32,10 +33,7 @@ namespace boost { namespace pfr { namespace detail {
///////////////////// General utility stuff
template <std::size_t Index>
using size_t_ = std::integral_constant<std::size_t, Index >;
template <class T> struct identity{
template <class T> struct identity {
typedef T type;
};

View File

@@ -37,7 +37,9 @@ struct ubiq_lref_constructor {
///////////////////// Structure that can be converted to rvalue reference to anything
struct ubiq_rref_constructor {
std::size_t ignore;
template <class Type> /*constexpr*/ operator Type&&() const noexcept {}; // Allows initialization of rvalue reference fields and move-only types
template <class Type> /*constexpr*/ operator Type&&() const noexcept { // Allows initialization of rvalue reference fields and move-only types
return detail::unsafe_declval<Type&&>();
};
};

View File

@@ -12,11 +12,20 @@
namespace boost { namespace pfr { namespace detail {
// For returning non default constructible types. Never used at runtime! GCC's
// std::declval may not be used in potentionally evaluated contexts, so it does not work here.
template <class T> constexpr T unsafe_declval() noexcept {
// This function serves as a link-time assert. If linker requires it, then
// `unsafe_declval()` is used at runtime.
void report_if_you_see_link_error_with_this_function() noexcept;
// For returning non default constructible types. Do NOT use at runtime!
//
// GCC's std::declval may not be used in potentionally evaluated contexts,
// so we reinvent it.
template <class T>
constexpr T unsafe_declval() noexcept {
report_if_you_see_link_error_with_this_function();
typename std::remove_reference<T>::type* ptr = 0;
ptr += 42; // killing 'null pointer dereference' heuristics of static analysis tools
ptr += 42; // suppresses 'null pointer dereference' warnings
return static_cast<T>(*ptr);
}

View File

@@ -59,7 +59,7 @@ void test_in_anon_ns() {
BOOST_TEST_EQ(std::get<1>(v).data, 2);
#ifdef __cpp_lib_optional
other_anon_with_optional opt{"test"};
other_anon_with_optional opt{"test", {}, {}, {}};
auto opt_val = boost::pfr::structure_tie(opt);
BOOST_TEST_EQ(std::get<0>(opt_val), "test");
#endif
@@ -76,7 +76,7 @@ void test_in_non_non_ns() {
BOOST_TEST_EQ(std::get<1>(v).data, 2);
#ifdef __cpp_lib_optional
other_anon_with_optional opt{"test again"};
other_anon_with_optional opt{"test again", {}, {}, {}};
auto opt_val = boost::pfr::structure_tie(opt);
BOOST_TEST_EQ(std::get<0>(opt_val), "test again");
#endif