Skip to content

Commit

Permalink
GCC/MSVC fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
snej committed Sep 29, 2023
1 parent 9eb10ba commit 81556c4
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 9 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions include/Awaitable.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#pragma once
#include "Result.hh"

#include <functional>

namespace crouton {

/** Pure-virtual interface declaring the coroutine methods needed to support `co_await`
Expand Down
4 changes: 2 additions & 2 deletions include/Error.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include <array>
#include <concepts>
#include <exception>
#include <stdexcept>
#include <type_traits>
#include <typeinfo>

Expand Down Expand Up @@ -51,7 +51,7 @@ namespace crouton {
template <typename T>
concept ErrorDomain = requires {
std::is_enum_v<T>;
std::same_as<std::underlying_type_t<T>, errorcode_t>;
requires std::same_as<std::underlying_type_t<T>, errorcode_t>;
{ErrorDomainInfo<T>::name} -> std::convertible_to<string_view>;
{ErrorDomainInfo<T>::description} -> std::convertible_to<ErrorDescriptionFunc>;
};
Expand Down
1 change: 1 addition & 0 deletions include/EventLoop.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "Future.hh"

#include <functional>
#include <optional>

struct uv_timer_s;

Expand Down
4 changes: 2 additions & 2 deletions include/Future.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace crouton {
template <typename T>
class Future : public Coroutine<FutureImpl<T>>, public ISelectable {
public:
using nonvoidT = std::conditional<std::is_void_v<T>, std::byte, T>::type;
using nonvoidT = typename std::conditional<std::is_void_v<T>, std::byte, T>::type;

/// Creates a Future from a FutureProvider.
explicit Future(FutureProvider<T> state) :_state(std::move(state)) {assert(_state);}
Expand Down Expand Up @@ -260,7 +260,7 @@ namespace crouton {
public:
using super = CoroutineImpl<FutureImpl<T>, true>;
using handle_type = typename super::handle_type;
using nonvoidT = std::conditional<std::is_void_v<T>, std::byte, T>::type;
using nonvoidT = typename std::conditional<std::is_void_v<T>, std::byte, T>::type;

FutureImpl() = default;

Expand Down
2 changes: 2 additions & 0 deletions include/LinkedList.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class LINK>
static LINK& downcast(Link& link) {return static_cast<LINK&>(link);}
Expand Down
2 changes: 2 additions & 0 deletions include/Result.hh
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ namespace crouton {



#if 0
/// Syntactic sugar to handle a `Result<T>`, 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.
Expand All @@ -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
}
7 changes: 4 additions & 3 deletions src/io/FileStream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ namespace crouton::io {
_readBuf = make_unique<Buffer>();
assert(_readBuf->empty());
MutableBytes buf(_readBuf->data, Buffer::kCapacity);
size_t n = TRY_AWAIT(_preadv(&buf, 1, -1));

_readBuf->size = uint32_t(n);
Result<size_t> 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();
}
Expand Down

0 comments on commit 81556c4

Please sign in to comment.