[gcc r12-8665] libstdc++: Rename data members of std::unexpected and std::bad_expected_access

Jonathan Wakely redi@gcc.gnu.org
Fri Aug 5 12:32:17 GMT 2022


https://gcc.gnu.org/g:0b4d2f5e7b446477abe6165f7b3a86616cf95ce0

commit r12-8665-g0b4d2f5e7b446477abe6165f7b3a86616cf95ce0
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Aug 4 10:20:18 2022 +0100

    libstdc++: Rename data members of std::unexpected and std::bad_expected_access
    
    The P2549R1 paper was accepted for C++23. I already implemented it for
    our <expected>, but I didn't rename the private daata members, only the
    public member functions. This renames the data members for consistency
    with the working draft.
    
    libstdc++-v3/ChangeLog:
    
            * include/std/expected (unexpected::_M_val): Rename to _M_unex.
            (bad_expected_access::_M_val): Likewise.
    
    (cherry picked from commit 07c7ee4d2d42f4728928556dbbe0700f9a13db90)

Diff:
---
 libstdc++-v3/include/std/expected | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/libstdc++-v3/include/std/expected b/libstdc++-v3/include/std/expected
index 3446d6dbaed..3ee13aa95f6 100644
--- a/libstdc++-v3/include/std/expected
+++ b/libstdc++-v3/include/std/expected
@@ -95,32 +95,32 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     class bad_expected_access : public bad_expected_access<void> {
     public:
       explicit
-      bad_expected_access(_Er __e) : _M_val(std::move(__e)) { }
+      bad_expected_access(_Er __e) : _M_unex(std::move(__e)) { }
 
       // XXX const char* what() const noexcept override;
 
       [[nodiscard]]
       _Er&
       error() & noexcept
-      { return _M_val; }
+      { return _M_unex; }
 
       [[nodiscard]]
       const _Er&
       error() const & noexcept
-      { return _M_val; }
+      { return _M_unex; }
 
       [[nodiscard]]
       _Er&&
       error() && noexcept
-      { return std::move(_M_val); }
+      { return std::move(_M_unex); }
 
       [[nodiscard]]
       const _Er&&
       error() const && noexcept
-      { return std::move(_M_val); }
+      { return std::move(_M_unex); }
 
     private:
-      _Er _M_val;
+      _Er _M_unex;
     };
 
   /// Tag type for constructing unexpected values in a std::expected
@@ -175,7 +175,7 @@ namespace __expected
 	constexpr explicit
 	unexpected(_Err&& __e)
 	noexcept(is_nothrow_constructible_v<_Er, _Err>)
-	: _M_val(std::forward<_Err>(__e))
+	: _M_unex(std::forward<_Err>(__e))
 	{ }
 
       template<typename... _Args>
@@ -183,7 +183,7 @@ namespace __expected
 	constexpr explicit
 	unexpected(in_place_t, _Args&&... __args)
 	noexcept(is_nothrow_constructible_v<_Er, _Args...>)
-	: _M_val(std::forward<_Args>(__args)...)
+	: _M_unex(std::forward<_Args>(__args)...)
 	{ }
 
       template<typename _Up, typename... _Args>
@@ -192,7 +192,7 @@ namespace __expected
 	unexpected(in_place_t, initializer_list<_Up> __il, _Args&&... __args)
 	noexcept(is_nothrow_constructible_v<_Er, initializer_list<_Up>&,
 					    _Args...>)
-	: _M_val(__il, std::forward<_Args>(__args)...)
+	: _M_unex(__il, std::forward<_Args>(__args)...)
 	{ }
 
       constexpr unexpected& operator=(const unexpected&) = default;
@@ -201,33 +201,33 @@ namespace __expected
 
       [[nodiscard]]
       constexpr const _Er&
-      error() const & noexcept { return _M_val; }
+      error() const & noexcept { return _M_unex; }
 
       [[nodiscard]]
       constexpr _Er&
-      error() & noexcept { return _M_val; }
+      error() & noexcept { return _M_unex; }
 
       [[nodiscard]]
       constexpr const _Er&&
-      error() const && noexcept { return std::move(_M_val); }
+      error() const && noexcept { return std::move(_M_unex); }
 
       [[nodiscard]]
       constexpr _Er&&
-      error() && noexcept { return std::move(_M_val); }
+      error() && noexcept { return std::move(_M_unex); }
 
       constexpr void
       swap(unexpected& __other) noexcept(is_nothrow_swappable_v<_Er>)
       {
 	static_assert( is_swappable_v<_Er> );
 	using std::swap;
-	swap(_M_val, __other._M_val);
+	swap(_M_unex, __other._M_unex);
       }
 
       template<typename _Err>
 	[[nodiscard]]
 	friend constexpr bool
 	operator==(const unexpected& __x, const unexpected<_Err>& __y)
-	{ return __x._M_val == __y.error(); }
+	{ return __x._M_unex == __y.error(); }
 
       friend constexpr void
       swap(unexpected& __x, unexpected& __y)
@@ -236,7 +236,7 @@ namespace __expected
       { __x.swap(__y); }
 
     private:
-      _Er _M_val;
+      _Er _M_unex;
     };
 
   template<typename _Er> unexpected(_Er) -> unexpected<_Er>;


More information about the Gcc-cvs mailing list