[libc-commits] [libc] cca3db9 - [libc][NFC] Fix accessor qualifiers for `cpp::expected` (#80424)

via libc-commits libc-commits at lists.llvm.org
Sat Feb 3 03:16:00 PST 2024


Author: Guillaume Chatelet
Date: 2024-02-03T12:15:56+01:00
New Revision: cca3db93e0d441f943387d519702db2d3095f4ca

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

LOG: [libc][NFC] Fix accessor qualifiers for `cpp::expected` (#80424)

Added: 
    

Modified: 
    libc/src/__support/CPP/expected.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/CPP/expected.h b/libc/src/__support/CPP/expected.h
index 52174a054f874..9682de981a834 100644
--- a/libc/src/__support/CPP/expected.h
+++ b/libc/src/__support/CPP/expected.h
@@ -33,12 +33,14 @@ template <class T, class E> class expected {
   constexpr expected(unexpected<E> unexp)
       : unexp(unexp.error()), is_expected(false) {}
 
-  constexpr bool has_value() { return is_expected; }
+  constexpr bool has_value() const { return is_expected; }
 
-  constexpr T value() { return exp; }
-  constexpr E error() { return unexp; }
+  constexpr T &value() { return exp; }
+  constexpr E &error() { return unexp; }
+  constexpr const T &value() const { return exp; }
+  constexpr const E &error() const { return unexp; }
 
-  constexpr operator bool() { return is_expected; }
+  constexpr operator bool() const { return is_expected; }
 
   constexpr T &operator*() { return exp; }
   constexpr const T &operator*() const { return exp; }


        


More information about the libc-commits mailing list