[libcxx-commits] [libcxx] [libc++] P3798R1: The unexpected in std::expected (PR #204826)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Jun 21 18:47:55 PDT 2026
================
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++29
+
+// constexpr bool has_error() const noexcept;
+
+#include <cassert>
+#include <concepts>
+#include <expected>
+#include <type_traits>
+#include <utility>
+
+#include "../../types.h"
+
+static_assert(noexcept(std::expected<int, int>().has_error()));
+
+constexpr bool test() {
+ {
+ const std::expected<int, int> e(std::unexpect, 5);
+ assert(e.has_error());
----------------
frederick-vs-ja wrote:
It seems better to expand these lines to:
```suggestion
static_assert(noexcept(e.has_error()));
std::same_as<bool> decltype(auto) has_err = e.has_error();
assert(has_err);
```
(same for `libcxx/test/std/utilities/expected/expected.void/observers/has_error.pass.cpp`)
https://github.com/llvm/llvm-project/pull/204826
More information about the libcxx-commits
mailing list