[libc-commits] [libc] [libc][NFC] use builder pattern for ErrnoSetterMatcher (PR #79153)
via libc-commits
libc-commits at lists.llvm.org
Tue Jan 23 07:16:12 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Schrodinger ZHU Yifan (SchrodingerZhu)
<details>
<summary>Changes</summary>
ErrnoSetterMatcher::returns can be misleading as it does not initialize the errno. This is made worse as later on there is a switch statement on the errno comparator using __builtin_unreachable(). This patch make ErrnoSetterMatcher::returns give back a builder that is nomially different from ErrnoSetterMatcher.
---
Full diff: https://github.com/llvm/llvm-project/pull/79153.diff
1 Files Affected:
- (modified) libc/test/UnitTest/ErrnoSetterMatcher.h (+15-3)
``````````diff
diff --git a/libc/test/UnitTest/ErrnoSetterMatcher.h b/libc/test/UnitTest/ErrnoSetterMatcher.h
index b748c29751c328..6b15bd4e9b79a4 100644
--- a/libc/test/UnitTest/ErrnoSetterMatcher.h
+++ b/libc/test/UnitTest/ErrnoSetterMatcher.h
@@ -161,10 +161,22 @@ static internal::ErrnoSetterMatcher<RetT> Fails(int ExpectedErrno,
EQ(ExpectedErrno));
}
+template <typename RetT = int> class ErrnoSetterMatcherBuilder {
+public:
+ template <typename T> using Cmp = internal::Comparator<T>;
+ ErrnoSetterMatcherBuilder(Cmp<RetT> cmp) : return_cmp(cmp) {}
+
+ internal::ErrnoSetterMatcher<RetT> with_errno(Cmp<int> cmp) {
+ return internal::ErrnoSetterMatcher<RetT>(return_cmp, cmp);
+ }
+
+private:
+ Cmp<RetT> return_cmp;
+};
+
template <typename RetT>
-static internal::ErrnoSetterMatcher<RetT>
-returns(internal::Comparator<RetT> cmp) {
- return internal::ErrnoSetterMatcher<RetT>(cmp);
+static ErrnoSetterMatcherBuilder<RetT> returns(internal::Comparator<RetT> cmp) {
+ return ErrnoSetterMatcherBuilder<RetT>(cmp);
}
} // namespace ErrnoSetterMatcher
``````````
</details>
https://github.com/llvm/llvm-project/pull/79153
More information about the libc-commits
mailing list