Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<variant>: Workaround for LLVM-59854 in the case of destructor of variant #4903

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion stl/inc/variant
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,11 @@ public:
_Variant_storage<_Rest...> _Tail;
};

_CONSTEXPR20 ~_Variant_storage_() noexcept {
_CONSTEXPR20 ~_Variant_storage_()
#ifndef __clang__ // TRANSITION, LLVM-59854
noexcept
#endif // ^^^ no workaround ^^^
{
// explicitly non-trivial destructor (which would otherwise be defined as deleted
// since the class has a variant member with a non-trivial destructor)
}
Expand Down
83 changes: 83 additions & 0 deletions tests/std/tests/P0088R3_variant_msvc/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,89 @@ namespace msvc {
}
} // namespace gh2770

namespace gh4901 {
#if _HAS_CXX20
#define CONSTEXPR20 constexpr
#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv
#define CONSTEXPR20 inline
#endif // ^^^ !_HAS_CXX20 ^^^
struct X {
CONSTEXPR20 ~X() {}
};

struct Y {
X _;
};

struct ZA {
std::variant<Y, int> z;
};

struct ZB {
std::variant<int, Y> z;
};

#if _HAS_CXX20
static_assert(ZA{0}.z.index() == 1);
static_assert(ZA{Y{}}.z.index() == 0);
static_assert(ZB{0}.z.index() == 0);
static_assert(ZB{Y{}}.z.index() == 1);
#endif // _HAS_CXX20

static_assert(std::is_nothrow_destructible_v<X>);
static_assert(std::is_nothrow_destructible_v<Y>);
static_assert(std::is_nothrow_destructible_v<std::variant<Y, int>>);
static_assert(std::is_nothrow_destructible_v<std::variant<int, Y>>);
static_assert(std::is_nothrow_destructible_v<ZA>);
static_assert(std::is_nothrow_destructible_v<ZB>);

// Verify that variant::~variant is noexcept even when an alternative has a potentially-throwing destructor,
// per N4988 [res.on.exception.handling]/3.
struct X2 {
CONSTEXPR20 ~X2() noexcept(false) {}
};

struct Y2 {
X2 _;
};

struct ZA2 {
std::variant<Y2, int> z;
};

struct ZB2 {
std::variant<int, Y2> z;
};

#if _HAS_CXX20
static_assert(ZA2{0}.z.index() == 1);
static_assert(ZA2{Y2{}}.z.index() == 0);
static_assert(ZB2{0}.z.index() == 0);
static_assert(ZB2{Y2{}}.z.index() == 1);
#endif // _HAS_CXX20

static_assert(!std::is_nothrow_destructible_v<X2>);
static_assert(!std::is_nothrow_destructible_v<Y2>);
static_assert(std::is_nothrow_destructible_v<std::variant<Y2, int>>);
static_assert(std::is_nothrow_destructible_v<std::variant<int, Y2>>);
static_assert(std::is_nothrow_destructible_v<ZA2>);
static_assert(std::is_nothrow_destructible_v<ZB2>);

struct ZC {
std::variant<Y, int, Y2> z;
};

#if _HAS_CXX20
static_assert(ZC{Y{}}.z.index() == 0);
static_assert(ZC{0}.z.index() == 1);
static_assert(ZC{Y2{}}.z.index() == 2);
#endif // _HAS_CXX20

static_assert(std::is_nothrow_destructible_v<std::variant<Y, int, Y2>>);
static_assert(std::is_nothrow_destructible_v<ZC>);
#undef CONSTEXPR20
} // namespace gh4901
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved

namespace assign_cv {
template <class T>
struct TypeIdentityImpl {
Expand Down