[libc-commits] [libc] [libc] add LIBC_INLINE for expected, use CTAD in abs_timeout (PR #94348)
via libc-commits
libc-commits at lists.llvm.org
Tue Jun 4 05:53:38 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: None (c8ef)
<details>
<summary>Changes</summary>
close: #<!-- -->91904
---
Full diff: https://github.com/llvm/llvm-project/pull/94348.diff
2 Files Affected:
- (modified) libc/src/__support/CPP/expected.h (+18-14)
- (modified) libc/src/__support/time/linux/abs_timeout.h (+2-2)
``````````diff
diff --git a/libc/src/__support/CPP/expected.h b/libc/src/__support/CPP/expected.h
index 9682de981a834..c35f0a1dc5369 100644
--- a/libc/src/__support/CPP/expected.h
+++ b/libc/src/__support/CPP/expected.h
@@ -9,6 +9,8 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_EXPECTED_H
#define LLVM_LIBC_SRC___SUPPORT_CPP_EXPECTED_H
+#include "src/__support/macros/attributes.h"
+
namespace LIBC_NAMESPACE::cpp {
// This is used to hold an unexpected value so that a different constructor is
@@ -17,10 +19,12 @@ template <class T> class unexpected {
T value;
public:
- constexpr explicit unexpected(T value) : value(value) {}
- constexpr T error() { return value; }
+ LIBC_INLINE constexpr explicit unexpected(T value) : value(value) {}
+ LIBC_INLINE constexpr T error() { return value; }
};
+template <class T> explicit unexpected(T) -> unexpected<T>;
+
template <class T, class E> class expected {
union {
T exp;
@@ -29,23 +33,23 @@ template <class T, class E> class expected {
bool is_expected;
public:
- constexpr expected(T exp) : exp(exp), is_expected(true) {}
- constexpr expected(unexpected<E> unexp)
+ LIBC_INLINE constexpr expected(T exp) : exp(exp), is_expected(true) {}
+ LIBC_INLINE constexpr expected(unexpected<E> unexp)
: unexp(unexp.error()), is_expected(false) {}
- constexpr bool has_value() const { return is_expected; }
+ LIBC_INLINE constexpr bool has_value() const { return is_expected; }
- constexpr T &value() { return exp; }
- constexpr E &error() { return unexp; }
- constexpr const T &value() const { return exp; }
- constexpr const E &error() const { return unexp; }
+ LIBC_INLINE constexpr T &value() { return exp; }
+ LIBC_INLINE constexpr E &error() { return unexp; }
+ LIBC_INLINE constexpr const T &value() const { return exp; }
+ LIBC_INLINE constexpr const E &error() const { return unexp; }
- constexpr operator bool() const { return is_expected; }
+ LIBC_INLINE constexpr operator bool() const { return is_expected; }
- constexpr T &operator*() { return exp; }
- constexpr const T &operator*() const { return exp; }
- constexpr T *operator->() { return &exp; }
- constexpr const T *operator->() const { return &exp; }
+ LIBC_INLINE constexpr T &operator*() { return exp; }
+ LIBC_INLINE constexpr const T &operator*() const { return exp; }
+ LIBC_INLINE constexpr T *operator->() { return &exp; }
+ LIBC_INLINE constexpr const T *operator->() const { return &exp; }
};
} // namespace LIBC_NAMESPACE::cpp
diff --git a/libc/src/__support/time/linux/abs_timeout.h b/libc/src/__support/time/linux/abs_timeout.h
index 6e5e59b32b7ad..0097f8abc4ee9 100644
--- a/libc/src/__support/time/linux/abs_timeout.h
+++ b/libc/src/__support/time/linux/abs_timeout.h
@@ -33,12 +33,12 @@ class AbsTimeout {
from_timespec(timespec ts, bool realtime) {
using namespace time_units;
if (ts.tv_nsec < 0 || ts.tv_nsec >= 1_s_ns)
- return cpp::unexpected<Error>(Error::Invalid);
+ return cpp::unexpected(Error::Invalid);
// POSIX allows tv_sec to be negative. We interpret this as an expired
// timeout.
if (ts.tv_sec < 0)
- return cpp::unexpected<Error>(Error::BeforeEpoch);
+ return cpp::unexpected(Error::BeforeEpoch);
return AbsTimeout{ts, realtime};
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/94348
More information about the libc-commits
mailing list