brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1008 B · c6b9f3c Raw
40 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 const E& error() const & noexcept;12 13#include <cassert>14#include <concepts>15#include <expected>16#include <utility>17 18template <class T>19concept ErrorNoexcept =20    requires(const T& t) {21      { t.error() } noexcept;22    };23 24static_assert(!ErrorNoexcept<int>);25static_assert(ErrorNoexcept<std::unexpected<int>>);26 27constexpr bool test() {28  const std::unexpected<int> unex(5);29  decltype(auto) i = unex.error();30  static_assert(std::same_as<decltype(i), const int&>);31  assert(i == 5);32  return true;33}34 35int main(int, char**) {36  test();37  static_assert(test());38  return 0;39}40