Skip to content

Commit

Permalink
fix type wrapper maybe uninitialized
Browse files Browse the repository at this point in the history
  • Loading branch information
jxy-s committed Oct 13, 2024
1 parent b478350 commit 79314b5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
3 changes: 3 additions & 0 deletions radiant/TypeTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ using RemoveRef = typename remove_reference<T>::type;
template <typename T>
using RemoveCV = typename remove_cv<T>::type;

template <typename T>
using RemoveCVRef = RemoveCV<RemoveRef<T>>;

template <typename T>
using RemoveConst = typename remove_const<T>::type;

Expand Down
26 changes: 15 additions & 11 deletions radiant/TypeWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ class TypeWrapper<T, false>
template <typename T>
class TypeWrapper<T, true>
{
private:

using PointerType = RemoveRef<T>*;

public:

using Type = T;
Expand All @@ -165,55 +169,55 @@ class TypeWrapper<T, true>

template <typename U, EnIf<IsCtor<T, U>, int> = 0>
constexpr explicit TypeWrapper(U&& val) noexcept
: m_ref(Forward<U>(val))
: m_value(AddrOf(Forward<U>(val)))
{
}

template <typename U, EnIf<IsLRefBindable<T, U&>, int> = 0>
constexpr explicit TypeWrapper(TypeWrapper<U>& r) noexcept
: m_ref(r.Get())
: m_value(AddrOf(r.Get()))
{
}

template <typename U, EnIf<IsLRefBindable<T, const U&>, int> = 0>
constexpr explicit TypeWrapper(const TypeWrapper<U>& r) noexcept
: m_ref(r.Get())
: m_value(AddrOf(r.Get()))
{
}

template <typename U, EnIf<IsLRefBindable<T, U&>, int> = 0>
constexpr explicit TypeWrapper(TypeWrapper<U>&& r) noexcept
: m_ref(r.Get())
: m_value(AddrOf(r.Get()))
{
}

template <typename U, EnIf<IsCtor<T, U>, int> = 0>
template <typename U, EnIf<IsLRefBindable<T, U&>, int> = 0>
constexpr TypeWrapper& operator=(U&& val) noexcept
{
new (this) TypeWrapper(Forward<U>(val));
m_value = AddrOf(Forward<U>(val));
return *this;
}

template <typename U, EnIf<IsCtor<T, U&>, int> = 0>
template <typename U, EnIf<IsLRefBindable<T, U&>, int> = 0>
constexpr TypeWrapper& operator=(TypeWrapper<U>& r) noexcept
{
new (this) TypeWrapper(r.Get());
m_value = AddrOf(r.Get());
return *this;
}

constexpr T& Get() noexcept
{
return m_ref;
return *m_value;
}

constexpr const T& Get() const noexcept
{
return m_ref;
return *m_value;
}

private:

T m_ref;
PointerType m_value;
};

template <typename T, typename U>
Expand Down
9 changes: 0 additions & 9 deletions test/test_Result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@
#include <string>
#include <utility>

#if !RAD_DBG && defined(RAD_GCC_VERSION)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif

namespace testnoexcept
{

Expand Down Expand Up @@ -3193,7 +3188,3 @@ TEST(ResultTests, CompareRes)
EXPECT_FALSE(value != rad::ResultErr<MYSTATUS>(MYSTATUS_UNSUCCESSFUL));
EXPECT_FALSE(rad::ResultErr<MYSTATUS>(MYSTATUS_UNSUCCESSFUL) != value);
}

#if !RAD_DBG && defined(RAD_GCC_VERSION)
#pragma GCC diagnostic pop
#endif
2 changes: 2 additions & 0 deletions test/test_TypeWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ RAD_S_ASSERT(!noexcept(TW<TO>(rad::DeclVal<TO&>())));
RAD_S_ASSERT(noexcept(TW<NTO>(rad::DeclVal<NTO&&>())));
RAD_S_ASSERT(!noexcept(TW<TO>(rad::DeclVal<TO&&>())));

#if RAD_ENABLE_STD
// noexcept passthrough initializer_list ctor
RAD_S_ASSERT(noexcept(TW<NTO>({ 1, 2 })));
RAD_S_ASSERT(!noexcept(TW<TO>({ 1, 2 })));
#endif

// noexcept passthrough wrapper default copy ctor
RAD_S_ASSERT(noexcept(TW<NTO>(rad::DeclVal<TW<NTO>&>())));
Expand Down

0 comments on commit 79314b5

Please sign in to comment.