diff --git a/include/rapidcheck/Maybe.h b/include/rapidcheck/Maybe.h index c34d5145..398ac541 100644 --- a/include/rapidcheck/Maybe.h +++ b/include/rapidcheck/Maybe.h @@ -81,7 +81,7 @@ class Maybe { ~Maybe(); private: - alignas(T) unsigned char m_storage[sizeof(T)]; + alignas(T) uint8_t m_storage[sizeof(T)]; bool m_initialized; }; diff --git a/include/rapidcheck/Maybe.hpp b/include/rapidcheck/Maybe.hpp index b7e4778c..82a12a4c 100644 --- a/include/rapidcheck/Maybe.hpp +++ b/include/rapidcheck/Maybe.hpp @@ -52,7 +52,7 @@ template template void Maybe::init(Args &&... args) { reset(); - new (&m_storage) T(std::forward(args)...); + new (m_storage) T(std::forward(args)...); m_initialized = true; } @@ -66,27 +66,27 @@ void Maybe::reset() { template T &Maybe::operator*() & { - return *reinterpret_cast(&m_storage); + return *reinterpret_cast(m_storage); } template const T &Maybe::operator*() const & { - return *reinterpret_cast(&m_storage); + return *reinterpret_cast(m_storage); } template T &&Maybe::operator*() && { - return std::move(*reinterpret_cast(&m_storage)); + return std::move(*reinterpret_cast(m_storage)); } template T *Maybe::operator->() { - return reinterpret_cast(&m_storage); + return reinterpret_cast(m_storage); } template const T *Maybe::operator->() const { - return reinterpret_cast(&m_storage); + return reinterpret_cast(m_storage); } template diff --git a/include/rapidcheck/detail/AlignedUnion.h b/include/rapidcheck/detail/AlignedUnion.h index 15843e18..d4b97d90 100644 --- a/include/rapidcheck/detail/AlignedUnion.h +++ b/include/rapidcheck/detail/AlignedUnion.h @@ -15,12 +15,5 @@ struct MaxOf std::size_t, (V1 > MaxOf::value ? V1 : MaxOf::value)> {}; -/// Replacement for std::aligned_union for compiles that do not have it. -template -struct alignas(MaxOf::value) AlignedUnion -{ - unsigned char bytes[MaxOf::value]; -}; - } // namespace detail } // namespace rc diff --git a/include/rapidcheck/detail/Traits.h b/include/rapidcheck/detail/Traits.h index 67b421ea..ea1e6a3c 100644 --- a/include/rapidcheck/detail/Traits.h +++ b/include/rapidcheck/detail/Traits.h @@ -9,12 +9,12 @@ namespace detail { #define RC_SFINAE_TRAIT(Name, expression) \ struct Name##Impl { \ template \ - static std::true_type test(const T &); \ + static std::true_type test(const T *); \ static std::false_type test(...); \ }; \ \ template \ - using Name = decltype(Name##Impl::test(std::declval())); + using Name = decltype(Name##Impl::test(static_cast(nullptr))); RC_SFINAE_TRAIT(IsStreamInsertible, decltype(std::cout << std::declval())) diff --git a/include/rapidcheck/detail/Variant.h b/include/rapidcheck/detail/Variant.h index bc178518..7732a144 100644 --- a/include/rapidcheck/detail/Variant.h +++ b/include/rapidcheck/detail/Variant.h @@ -90,8 +90,8 @@ class Variant { static constexpr bool isValidType(); std::size_t m_typeIndex; - using Storage = AlignedUnion; - Storage m_storage; + alignas(MaxOf::value) + uint8_t m_storage[MaxOf::value]; }; template diff --git a/include/rapidcheck/detail/Variant.hpp b/include/rapidcheck/detail/Variant.hpp index e1b2da01..4970396a 100644 --- a/include/rapidcheck/detail/Variant.hpp +++ b/include/rapidcheck/detail/Variant.hpp @@ -32,7 +32,7 @@ Variant::Variant(T &&value) noexcept( static_assert(isValidType>(), "T is not a valid type of this variant"); - new (&m_storage) Decay(std::forward(value)); + new (m_storage) Decay(std::forward(value)); } template @@ -43,11 +43,11 @@ operator=(const T &value) noexcept { const auto newIndex = indexOfType(); if (newIndex == m_typeIndex) { - *reinterpret_cast(&m_storage) = value; + *reinterpret_cast(m_storage) = value; } else { - destroy(m_typeIndex, &m_storage); + destroy(m_typeIndex, m_storage); m_typeIndex = newIndex; - new (&m_storage) T(value); + new (m_storage) T(value); } return *this; } @@ -60,11 +60,11 @@ operator=(T &&value) noexcept { const auto newIndex = indexOfType(); if (newIndex == m_typeIndex) { - *reinterpret_cast(&m_storage) = std::move(value); + *reinterpret_cast(m_storage) = std::move(value); } else { - destroy(m_typeIndex, &m_storage); + destroy(m_typeIndex, m_storage); m_typeIndex = newIndex; - new (&m_storage) T(std::move(value)); + new (m_storage) T(std::move(value)); } return *this; } @@ -73,14 +73,14 @@ template template T &Variant::get() & { assert(indexOfType() == m_typeIndex); - return *reinterpret_cast(&m_storage); + return *reinterpret_cast(m_storage); } template template const T &Variant::get() const & { assert(indexOfType() == m_typeIndex); - return *reinterpret_cast(&m_storage); + return *reinterpret_cast(m_storage); } template @@ -97,7 +97,7 @@ bool Variant::match(T &value) const { return false; } - value = *reinterpret_cast(&m_storage); + value = *reinterpret_cast(m_storage); return true; } @@ -123,7 +123,7 @@ bool Variant::operator==(const Variant &rhs) const { static bool (*const equalsFuncs[])(const void *, const void *) = { &variantEqualsImpl, &variantEqualsImpl...}; - return equalsFuncs[m_typeIndex](&m_storage, &rhs.m_storage); + return equalsFuncs[m_typeIndex](m_storage, rhs.m_storage); } template @@ -136,21 +136,21 @@ void Variant::printTo(std::ostream &os) const { static void (*printToFuncs[])(std::ostream &, const void *) = { &variantPrintToImpl, &variantPrintToImpl...}; - printToFuncs[m_typeIndex](os, &m_storage); + printToFuncs[m_typeIndex](os, m_storage); } template Variant::Variant(const Variant &other) noexcept( AllIs::value) : m_typeIndex(other.m_typeIndex) { - copy(m_typeIndex, &m_storage, &other.m_storage); + copy(m_typeIndex, m_storage, other.m_storage); } template Variant::Variant(Variant &&other) noexcept( AllIs::value) : m_typeIndex(other.m_typeIndex) { - move(m_typeIndex, &m_storage, &other.m_storage); + move(m_typeIndex, m_storage, other.m_storage); } template @@ -163,12 +163,12 @@ operator=(const Variant &rhs) noexcept( "AllIs types must be nothrow move-constructible to use copy assignment"); if (m_typeIndex == rhs.m_typeIndex) { - copyAssign(m_typeIndex, &m_storage, &rhs.m_storage); + copyAssign(m_typeIndex, m_storage, rhs.m_storage); } else { - Storage tmp; - copy(rhs.m_typeIndex, &tmp, &rhs.m_storage); - destroy(m_typeIndex, &m_storage); - move(rhs.m_typeIndex, &m_storage, &tmp); + decltype(m_storage) tmp; + copy(rhs.m_typeIndex, tmp, rhs.m_storage); + destroy(m_typeIndex, m_storage); + move(rhs.m_typeIndex, m_storage, tmp); m_typeIndex = rhs.m_typeIndex; } @@ -184,11 +184,11 @@ operator=(Variant &&rhs) noexcept( "AllIs types must be nothrow move-constructible to use copy assignment"); if (m_typeIndex == rhs.m_typeIndex) { - moveAssign(m_typeIndex, &m_storage, &rhs.m_storage); + moveAssign(m_typeIndex, m_storage, rhs.m_storage); } else { - destroy(m_typeIndex, &m_storage); + destroy(m_typeIndex, m_storage); m_typeIndex = rhs.m_typeIndex; - move(m_typeIndex, &m_storage, &rhs.m_storage); + move(m_typeIndex, m_storage, rhs.m_storage); } return *this; @@ -196,7 +196,7 @@ operator=(Variant &&rhs) noexcept( template Variant::~Variant() noexcept { - destroy(m_typeIndex, &m_storage); + destroy(m_typeIndex, m_storage); } template diff --git a/test/detail/MulticastTestListenerTests.cpp b/test/detail/MulticastTestListenerTests.cpp index c9d32cbf..f1787330 100644 --- a/test/detail/MulticastTestListenerTests.cpp +++ b/test/detail/MulticastTestListenerTests.cpp @@ -75,7 +75,7 @@ TEST_CASE("MulticastTestListener") { prop("passes on correct arguments", [](const TestMetadata &metadata, const TestResult &result) { MockTestListener mock; - mock.onTestFinishedCallback = [=](const TestMetadata &meta, + mock.onTestFinishedCallback = [&](const TestMetadata &meta, const TestResult &res) { RC_ASSERT(meta == metadata); RC_ASSERT(res == result);