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