[llvm-branch-commits] [libcxx] 27cc825 - Revert "[libc++] P3798R1: The unexpected in std::expected (#204826)"

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Jun 24 09:32:08 PDT 2026


Author: A. Jiang
Date: 2026-06-25T00:32:04+08:00
New Revision: 27cc825176b47f5584dc30401526a87ade68089c

URL: https://github.com/llvm/llvm-project/commit/27cc825176b47f5584dc30401526a87ade68089c
DIFF: https://github.com/llvm/llvm-project/commit/27cc825176b47f5584dc30401526a87ade68089c.diff

LOG: Revert "[libc++]  P3798R1: The unexpected in std::expected (#204826)"

This reverts commit 45a65bb48b5925707f43d08e30df2263a5e4e268.

Added: 
    

Modified: 
    libcxx/docs/FeatureTestMacroTable.rst
    libcxx/docs/ReleaseNotes/23.rst
    libcxx/docs/Status/Cxx29Papers.csv
    libcxx/include/__expected/expected.h
    libcxx/include/version
    libcxx/test/libcxx/utilities/expected/nodiscard.verify.cpp
    libcxx/test/std/language.support/support.limits/support.limits.general/expected.version.compile.pass.cpp
    libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
    libcxx/utils/generate_feature_test_macro_components.py

Removed: 
    libcxx/test/std/utilities/expected/expected.expected/observers/has_error.pass.cpp
    libcxx/test/std/utilities/expected/expected.void/observers/has_error.pass.cpp


################################################################################
diff  --git a/libcxx/docs/FeatureTestMacroTable.rst b/libcxx/docs/FeatureTestMacroTable.rst
index 47f10324e2523..429cf2a7250fb 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -332,7 +332,7 @@ Status
     ---------------------------------------------------------- -----------------
     ``__cpp_lib_containers_ranges``                            ``202202L``
     ---------------------------------------------------------- -----------------
-    ``__cpp_lib_expected``                                     ``202606L``
+    ``__cpp_lib_expected``                                     ``202211L``
     ---------------------------------------------------------- -----------------
     ``__cpp_lib_flat_map``                                     ``202511L``
     ---------------------------------------------------------- -----------------

diff  --git a/libcxx/docs/ReleaseNotes/23.rst b/libcxx/docs/ReleaseNotes/23.rst
index a491306a3cffb..8055792f697ea 100644
--- a/libcxx/docs/ReleaseNotes/23.rst
+++ b/libcxx/docs/ReleaseNotes/23.rst
@@ -52,7 +52,6 @@ Implemented Papers
 - P3383R3: ``mdspan.at()`` (`Github <https://llvm.org/PR175213>`__)
 - P3369R0: constexpr for ``uninitialized_default_construct`` (`Github <https://llvm.org/PR118380>`__)
 - P3508R0: Wording for "constexpr for specialized memory algorithms" (`Github <https://llvm.org/PR118379>`__)
-- P3798R1: The unexpected in ``std::expected`` (`Github <https://llvm.org/PR204394>`__)
 - P4206R0: Revert string support in ``std::constant_wrapper`` (`Github <https://llvm.org/PR203338>`__)
 
 Improvements and New Features

diff  --git a/libcxx/docs/Status/Cxx29Papers.csv b/libcxx/docs/Status/Cxx29Papers.csv
index 790e8b290cc80..3c48fe89be33d 100644
--- a/libcxx/docs/Status/Cxx29Papers.csv
+++ b/libcxx/docs/Status/Cxx29Papers.csv
@@ -3,7 +3,7 @@
 "`P4101R1 <https://wg21.link/P4101R1>`__","Consteval-only Values for C++26","2026-06 (Brno)","","","`#204391 <https://github.com/llvm/llvm-project/issues/204391>`__","Voted as a Defect Report."
 "`P2414R12 <https://wg21.link/P2414R12>`__","Pointer lifetime-end zap proposed solutions","2026-06 (Brno)","","","`#204392 <https://github.com/llvm/llvm-project/issues/204392>`__","Voted as a Defect Report."
 "`P3319R6 <https://wg21.link/P3319R6>`__","Add an ``iota`` object for ``simd`` (and more)","2026-06 (Brno)","","","`#204393 <https://github.com/llvm/llvm-project/issues/204393>`__",""
-"`P3798R1 <https://wg21.link/P3798R1>`__","The unexpected in ``std::expected``","2026-06 (Brno)","|Complete|","23","`#204394 <https://github.com/llvm/llvm-project/issues/204394>`__","Applied as a Defect Report."
+"`P3798R1 <https://wg21.link/P3798R1>`__","The unexpected in ``std::expected``","2026-06 (Brno)","","","`#204394 <https://github.com/llvm/llvm-project/issues/204394>`__",""
 "`P3052R2 <https://wg21.link/P3052R2>`__","``view_interface::at()``","2026-06 (Brno)","","","`#204395 <https://github.com/llvm/llvm-project/issues/204395>`__",""
 "`P4206R0 <https://wg21.link/P4206R0>`__","Revert string support in ``std::constant_wrapper``","2026-06 (Brno)","|Complete|","23","`#203336 <https://github.com/llvm/llvm-project/issues/203336>`__","Applied as a Defect Report."
 "`P3395R6 <https://wg21.link/P3395R6>`__","Fix encoding issues and add a formatter for ``std::error_code``","2026-06 (Brno)","","","`#204396 <https://github.com/llvm/llvm-project/issues/204396>`__",""

diff  --git a/libcxx/include/__expected/expected.h b/libcxx/include/__expected/expected.h
index 10b03f061f6e0..32ed81a392702 100644
--- a/libcxx/include/__expected/expected.h
+++ b/libcxx/include/__expected/expected.h
@@ -825,8 +825,6 @@ class expected : private __expected_base<_Tp, _Err> {
 
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool has_value() const noexcept { return this->__has_val(); }
 
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool has_error() const noexcept { return !this->has_value(); }
-
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& value() const& {
     static_assert(is_copy_constructible_v<_Err>, "error_type has to be copy constructible");
     if (!this->__has_val()) {
@@ -1601,8 +1599,6 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> {
 
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool has_value() const noexcept { return this->__has_val(); }
 
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool has_error() const noexcept { return !this->has_value(); }
-
   _LIBCPP_HIDE_FROM_ABI constexpr void operator*() const noexcept {
     _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
         this->__has_val(), "expected::operator* requires the expected to contain a value");

diff  --git a/libcxx/include/version b/libcxx/include/version
index 53e879959ec17..ae02006d9d1c9 100644
--- a/libcxx/include/version
+++ b/libcxx/include/version
@@ -111,7 +111,7 @@ __cpp_lib_erase_if                                      202002L <deque> <forward
 __cpp_lib_exchange_function                             201304L <utility>
 __cpp_lib_execution                                     201902L <execution>
                                                         201603L // C++17
-__cpp_lib_expected                                      202606L <expected>
+__cpp_lib_expected                                      202211L <expected>
 __cpp_lib_filesystem                                    201703L <filesystem>
 __cpp_lib_flat_map                                      202511L <flat_map>
 __cpp_lib_flat_set                                      202511L <flat_set>
@@ -502,7 +502,7 @@ __cpp_lib_void_t                                        201411L <type_traits>
 # define __cpp_lib_constexpr_memory                     202202L
 # define __cpp_lib_constexpr_typeinfo                   202106L
 # define __cpp_lib_containers_ranges                    202202L
-# define __cpp_lib_expected                             202606L
+# define __cpp_lib_expected                             202211L
 # define __cpp_lib_flat_map                             202511L
 # define __cpp_lib_flat_set                             202511L
 # define __cpp_lib_format_ranges                        202207L

diff  --git a/libcxx/test/libcxx/utilities/expected/nodiscard.verify.cpp b/libcxx/test/libcxx/utilities/expected/nodiscard.verify.cpp
index 8dd54bd3e6c15..c9af7a91c67f2 100644
--- a/libcxx/test/libcxx/utilities/expected/nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/utilities/expected/nodiscard.verify.cpp
@@ -47,7 +47,6 @@ void test() {
   *std::move(exp);  // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
 
   exp.has_value(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-  exp.has_error(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
 
   cExp.value();            // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
   exp.value();             // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
@@ -111,7 +110,6 @@ void test() {
   const std::expected<void, int> cVExp{};
 
   vExp.has_value(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-  vExp.has_error(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
 
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   cVExp.error();

diff  --git a/libcxx/test/std/language.support/support.limits/support.limits.general/expected.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/expected.version.compile.pass.cpp
index 70217f98a8570..4ec6c469dce4c 100644
--- a/libcxx/test/std/language.support/support.limits/support.limits.general/expected.version.compile.pass.cpp
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/expected.version.compile.pass.cpp
@@ -83,8 +83,8 @@
 #  ifndef __cpp_lib_expected
 #    error "__cpp_lib_expected should be defined in c++23"
 #  endif
-#  if __cpp_lib_expected != 202606L
-#    error "__cpp_lib_expected should have the value 202606L in c++23"
+#  if __cpp_lib_expected != 202211L
+#    error "__cpp_lib_expected should have the value 202211L in c++23"
 #  endif
 
 #  ifdef __cpp_lib_freestanding_expected
@@ -103,8 +103,8 @@
 #  ifndef __cpp_lib_expected
 #    error "__cpp_lib_expected should be defined in c++26"
 #  endif
-#  if __cpp_lib_expected != 202606L
-#    error "__cpp_lib_expected should have the value 202606L in c++26"
+#  if __cpp_lib_expected != 202211L
+#    error "__cpp_lib_expected should have the value 202211L in c++26"
 #  endif
 
 #  if !defined(_LIBCPP_VERSION)

diff  --git a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
index d4808fde45444..282936a0b3f63 100644
--- a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
@@ -5133,8 +5133,8 @@
 #  ifndef __cpp_lib_expected
 #    error "__cpp_lib_expected should be defined in c++23"
 #  endif
-#  if __cpp_lib_expected != 202606L
-#    error "__cpp_lib_expected should have the value 202606L in c++23"
+#  if __cpp_lib_expected != 202211L
+#    error "__cpp_lib_expected should have the value 202211L in c++23"
 #  endif
 
 #  if !defined(_LIBCPP_VERSION) || _LIBCPP_HAS_FILESYSTEM
@@ -6903,8 +6903,8 @@
 #  ifndef __cpp_lib_expected
 #    error "__cpp_lib_expected should be defined in c++26"
 #  endif
-#  if __cpp_lib_expected != 202606L
-#    error "__cpp_lib_expected should have the value 202606L in c++26"
+#  if __cpp_lib_expected != 202211L
+#    error "__cpp_lib_expected should have the value 202211L in c++26"
 #  endif
 
 #  if !defined(_LIBCPP_VERSION) || _LIBCPP_HAS_FILESYSTEM

diff  --git a/libcxx/test/std/utilities/expected/expected.expected/observers/has_error.pass.cpp b/libcxx/test/std/utilities/expected/expected.expected/observers/has_error.pass.cpp
deleted file mode 100644
index 93ee0ea2dfeea..0000000000000
--- a/libcxx/test/std/utilities/expected/expected.expected/observers/has_error.pass.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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++23
-
-// constexpr bool has_error() const noexcept;
-
-#include <cassert>
-#include <concepts>
-#include <expected>
-#include <type_traits>
-#include <utility>
-
-#include "../../types.h"
-
-constexpr bool test() {
-  {
-    const std::expected<int, int> e(std::unexpect, 5);
-    static_assert(noexcept(e.has_error()));
-    std::same_as<bool> decltype(auto) has_err = e.has_error();
-    assert(has_err);
-  }
-
-  {
-    const std::expected<int, int> e(5);
-    assert(!e.has_error());
-  }
-
-  return true;
-}
-
-int main(int, char**) {
-  test();
-  static_assert(test());
-
-  return 0;
-}

diff  --git a/libcxx/test/std/utilities/expected/expected.void/observers/has_error.pass.cpp b/libcxx/test/std/utilities/expected/expected.void/observers/has_error.pass.cpp
deleted file mode 100644
index 3072530066361..0000000000000
--- a/libcxx/test/std/utilities/expected/expected.void/observers/has_error.pass.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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++23
-
-// constexpr bool has_error() const noexcept;
-
-#include <cassert>
-#include <concepts>
-#include <expected>
-#include <type_traits>
-#include <utility>
-
-#include "../../types.h"
-
-constexpr bool test() {
-  {
-    const std::expected<void, int> e(std::unexpect, 5);
-    static_assert(noexcept(e.has_error()));
-    std::same_as<bool> decltype(auto) has_err = e.has_error();
-    assert(has_err);
-  }
-
-  {
-    const std::expected<void, int> e;
-    assert(!e.has_error());
-  }
-
-  return true;
-}
-
-int main(int, char**) {
-  test();
-  static_assert(test());
-
-  return 0;
-}

diff  --git a/libcxx/utils/generate_feature_test_macro_components.py b/libcxx/utils/generate_feature_test_macro_components.py
index 56b5d620d73a4..776689b3d3935 100644
--- a/libcxx/utils/generate_feature_test_macro_components.py
+++ b/libcxx/utils/generate_feature_test_macro_components.py
@@ -557,7 +557,7 @@ def add_version_header(tc):
         },
         {
             "name": "__cpp_lib_expected",
-            "values": {"c++23": 202606},
+            "values": {"c++23": 202211},
             "headers": ["expected"],
         },
         {


        


More information about the llvm-branch-commits mailing list