`<expected>`: Workaround LLVM-59854 (#3326)

This commit is contained in:
Casey Carter 2023-01-11 17:53:41 -08:00 коммит произвёл GitHub
Родитель 8b5a11fac9
Коммит 7045ec50d1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 19 добавлений и 3 удалений

Просмотреть файл

@ -308,7 +308,11 @@ public:
: _Unexpected(_Ilist, _STD forward<_Args>(_Vals)...), _Has_value(false) {}
// [expected.object.dtor]
constexpr ~expected() noexcept {
constexpr ~expected()
#ifndef __clang__ // TRANSITION, LLVM-59854
noexcept
#endif // __clang__
{
if (_Has_value) {
if constexpr (!is_trivially_destructible_v<_Ty>) {
_Value.~_Ty();
@ -834,7 +838,11 @@ public:
: _Unexpected(_Ilist, _STD forward<_Args>(_Vals)...), _Has_value(false) {}
// [expected.void.dtor]
constexpr ~expected() noexcept {
constexpr ~expected()
#ifndef __clang__ // TRANSITION, LLVM-59854
noexcept
#endif // __clang__
{
if (!_Has_value) {
_Unexpected.~_Err();
}

Просмотреть файл

@ -7,9 +7,9 @@
#include <concepts>
#include <exception>
#include <expected>
#include <initializer_list>
#include <type_traits>
#include <utility>
#include <vector>
using namespace std;
@ -2044,6 +2044,14 @@ void test_reinit_regression() {
}
}
// Defend against regression of llvm-project#59854, in which clang is confused
// by the explicit `noexcept` on `expected`'s destructors.
struct Data {
vector<int> vec_;
constexpr Data(initializer_list<int> il) : vec_(il) {}
};
static_assert(((void) expected<void, Data>{unexpect, {1, 2, 3}}, true));
int main() {
test_unexpected::test_all();
static_assert(test_unexpected::test_all());