From 81556c4281bcd17f1f94b076ffc8b6c44b817895 Mon Sep 17 00:00:00 2001 From: Jens Alfke Date: Fri, 29 Sep 2023 14:49:58 -0700 Subject: [PATCH] GCC/MSVC fixes --- CMakeLists.txt | 5 +++-- include/Awaitable.hh | 2 ++ include/Error.hh | 4 ++-- include/EventLoop.hh | 1 + include/Future.hh | 4 ++-- include/LinkedList.hh | 2 ++ include/Result.hh | 2 ++ src/io/FileStream.cc | 7 ++++--- 8 files changed, 18 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ce0082..7360972 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,7 +49,7 @@ if (MSVC) # MSVC: add_definitions(-DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0A00 -DNOMINMAX) add_compile_options( - /W4 # I think this means 'turn on lots of warnings' + # /W4 # I think this means 'turn on lots of warnings' /wd4068 # ignore unknown pragma /wd4100 # ignore unused fn parameters /wd4244 # ignore implicit sign conversion @@ -76,7 +76,8 @@ else() add_compile_options( -Wno-gnu-zero-variadic-macro-arguments -Wno-gnu-conditional-omitted-operand # Allow `x ?: y` - -Wno-gnu-statement-expression-from-macro-expansion # Allow `({...})` + -Wno-gnu-statement-expression # Allow `({...})` + -Wno-gnu-statement-expression-from-macro-expansion ) endif() endif() diff --git a/include/Awaitable.hh b/include/Awaitable.hh index 135f530..1bdbc1f 100644 --- a/include/Awaitable.hh +++ b/include/Awaitable.hh @@ -19,6 +19,8 @@ #pragma once #include "Result.hh" +#include + namespace crouton { /** Pure-virtual interface declaring the coroutine methods needed to support `co_await` diff --git a/include/Error.hh b/include/Error.hh index 1b9cd3b..fb52dff 100644 --- a/include/Error.hh +++ b/include/Error.hh @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include @@ -51,7 +51,7 @@ namespace crouton { template concept ErrorDomain = requires { std::is_enum_v; - std::same_as, errorcode_t>; + requires std::same_as, errorcode_t>; {ErrorDomainInfo::name} -> std::convertible_to; {ErrorDomainInfo::description} -> std::convertible_to; }; diff --git a/include/EventLoop.hh b/include/EventLoop.hh index dacdd17..f337f30 100644 --- a/include/EventLoop.hh +++ b/include/EventLoop.hh @@ -20,6 +20,7 @@ #include "Future.hh" #include +#include struct uv_timer_s; diff --git a/include/Future.hh b/include/Future.hh index 54e3b7f..6e783ff 100644 --- a/include/Future.hh +++ b/include/Future.hh @@ -61,7 +61,7 @@ namespace crouton { template class Future : public Coroutine>, public ISelectable { public: - using nonvoidT = std::conditional, std::byte, T>::type; + using nonvoidT = typename std::conditional, std::byte, T>::type; /// Creates a Future from a FutureProvider. explicit Future(FutureProvider state) :_state(std::move(state)) {assert(_state);} @@ -260,7 +260,7 @@ namespace crouton { public: using super = CoroutineImpl, true>; using handle_type = typename super::handle_type; - using nonvoidT = std::conditional, std::byte, T>::type; + using nonvoidT = typename std::conditional, std::byte, T>::type; FutureImpl() = default; diff --git a/include/LinkedList.hh b/include/LinkedList.hh index ca7b268..f33b0ab 100644 --- a/include/LinkedList.hh +++ b/include/LinkedList.hh @@ -111,6 +111,8 @@ namespace crouton::util { protected: Link* _begin() {return _head._next;} Link* _end() {return &_head;} + Link const* _begin() const {return _head._next;} + Link const* _end() const {return &_head;} template static LINK& downcast(Link& link) {return static_cast(link);} diff --git a/include/Result.hh b/include/Result.hh index c26d994..048a8a0 100644 --- a/include/Result.hh +++ b/include/Result.hh @@ -133,6 +133,7 @@ namespace crouton { +#if 0 /// Syntactic sugar to handle a `Result`, similar to Swift's `try`. /// - If R has a value, evaluates to its value. /// - If R has an error, `co_return`s the error from the current coroutine. @@ -148,4 +149,5 @@ namespace crouton { /// - If the future returns a value, evaluates to that value. /// - If the future returns an error, `co_return`s the error. #define TRY_AWAIT(F) UNWRAP(AWAIT NoThrow(F)) +#endif } diff --git a/src/io/FileStream.cc b/src/io/FileStream.cc index 0f1da1d..b4f0c0c 100644 --- a/src/io/FileStream.cc +++ b/src/io/FileStream.cc @@ -108,9 +108,10 @@ namespace crouton::io { _readBuf = make_unique(); assert(_readBuf->empty()); MutableBytes buf(_readBuf->data, Buffer::kCapacity); - size_t n = TRY_AWAIT(_preadv(&buf, 1, -1)); - - _readBuf->size = uint32_t(n); + Result n = AWAIT _preadv(&buf, 1, -1); + if (auto err = n.error()) + RETURN err; + _readBuf->size = uint32_t(n.value()); _readBuf->used = 0; RETURN _readBuf->bytes(); }