59 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++17, c++2010 11// constexpr void emplace() noexcept;12//13// Effects: If has_value() is false, destroys unex and sets has_val to true.14 15#include <cassert>16#include <concepts>17#include <expected>18#include <type_traits>19#include <utility>20 21#include "../../types.h"22#include "test_macros.h"23 24template <class T>25concept EmplaceNoexcept =26 requires(T t) {27 { t.emplace() } noexcept;28 };29static_assert(!EmplaceNoexcept<int>);30 31static_assert(EmplaceNoexcept<std::expected<void, int>>);32 33constexpr bool test() {34 // has_value35 {36 std::expected<void, int> e;37 e.emplace();38 assert(e.has_value());39 }40 41 // !has_value42 {43 Traced::state state{};44 std::expected<int, Traced> e(std::unexpect, state, 5);45 e.emplace();46 47 assert(state.dtorCalled);48 assert(e.has_value());49 }50 51 return true;52}53 54int main(int, char**) {55 test();56 static_assert(test());57 return 0;58}59