[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()));
----------------
frederick-vs-ja wrote:

This `static_assert` additionally asserts that the default constructor of `std::expected<int, int>` is `noexcept`. Perhaps it would be clearer to only test `has_error`, see below.

https://github.com/llvm/llvm-project/pull/204826


More information about the libcxx-commits mailing list