brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · d6a71fa Raw
54 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 expected() noexcept;12 13#include <cassert>14#include <expected>15#include <type_traits>16 17#include "test_macros.h"18 19// Test noexcept20 21struct NoDefaultCtor {22  constexpr NoDefaultCtor() = delete;23};24 25static_assert(std::is_nothrow_default_constructible_v<std::expected<void, int>>);26static_assert(std::is_nothrow_default_constructible_v<std::expected<void, NoDefaultCtor>>);27 28struct MyInt {29  int i;30  friend constexpr bool operator==(const MyInt&, const MyInt&) = default;31};32 33constexpr bool test() {34  // default constructible35  {36    std::expected<void, int> e;37    assert(e.has_value());38  }39 40  // non-default constructible41  {42    std::expected<void, NoDefaultCtor> e;43    assert(e.has_value());44  }45 46  return true;47}48 49int main(int, char**) {50  test();51  static_assert(test());52  return 0;53}54