Commit 8df860e8 authored by Dominik Charousset's avatar Dominik Charousset

Fix conversion warnings

parent 54c7c6e2
......@@ -18,6 +18,7 @@
#pragma once
#include <algorithm>
#include <cstdint>
#include <cstring>
......@@ -81,44 +82,44 @@ public:
// -- bitwise member operators -----------------------------------------------
/// Bitwise ANDs `*this` and `other`.
Derived& operator&=(const Derived& other) {
Derived& operator&=(const Derived& other) noexcept {
auto& buf = dref().bytes();
for (size_t index = 0; index < Derived::num_bytes; ++index)
buf[index] &= other[index];
buf[index] = static_cast<uint8_t>(buf[index] & other[index]);
return dref();
}
/// Bitwise ORs `*this` and `other`.
Derived& operator|=(const Derived& other) {
Derived& operator|=(const Derived& other) noexcept {
auto& buf = dref().bytes();
for (size_t index = 0; index < Derived::num_bytes; ++index)
buf[index] |= other[index];
buf[index] = static_cast<uint8_t>(buf[index] | other[index]);
return dref();
}
/// Bitwise XORs `*this` and `other`.
Derived& operator^=(const Derived& other) {
Derived& operator^=(const Derived& other) noexcept {
auto& buf = dref().bytes();
for (size_t index = 0; index < Derived::num_bytes; ++index)
buf[index] ^= other[index];
buf[index] = static_cast<uint8_t>(buf[index] ^ other[index]);
return dref();
}
// -- bitwise free operators -------------------------------------------------
friend Derived operator&(const Derived& x, const Derived& y) {
friend Derived operator&(const Derived& x, const Derived& y) noexcept {
Derived result{x};
result &= y;
return result;
}
friend Derived operator|(const Derived& x, const Derived& y) {
friend Derived operator|(const Derived& x, const Derived& y) noexcept {
Derived result{x};
result |= y;
return result;
}
friend Derived operator^(const Derived& x, const Derived& y) {
friend Derived operator^(const Derived& x, const Derived& y) noexcept {
Derived result{x};
result ^= y;
return result;
......
......@@ -238,7 +238,7 @@ public:
size_t cpt = 0;
for (auto v: rhs) {
for (int k = 0; k < 8; ++k) {
lhs[cpt] = ((v & (1 << k)) != 0);
lhs[cpt] = (v & (1 << k)) != 0;
if (++cpt >= len)
return;
}
......@@ -249,7 +249,7 @@ public:
lhs.resize((rhs.size() - 1) / 8 + 1, 0);
for (bool b: rhs) {
if (b)
lhs[k / 8] |= (1 << (k % 8));
lhs[k / 8] = static_cast<uint8_t>(lhs[k / 8] | (1 << (k % 8)));
++k;
}
}
......
......@@ -36,12 +36,12 @@ bool add_ascii(T& x, char c, enable_if_tt<std::is_integral<T>, int> u = 0) {
CAF_IGNORE_UNUSED(u);
if (x > (std::numeric_limits<T>::max() / Base))
return false;
x *= Base;
x = static_cast<T>(x * Base);
ascii_to_int<Base, T> f;
auto y = f(c);
if (x > (std::numeric_limits<T>::max() - y))
return false;
x += y;
x = static_cast<T>(x + y);
return true;
}
......@@ -50,11 +50,10 @@ bool add_ascii(T& x, char c,
enable_if_tt<std::is_floating_point<T>, int> u = 0) {
CAF_IGNORE_UNUSED(u);
ascii_to_int<Base, T> f;
x = (x * Base) + f(c);
x = static_cast<T>((x * Base) + f(c));
return true;
}
} // namespace parser
} // namespace detail
} // namespace caf
......@@ -36,12 +36,12 @@ bool sub_ascii(T& x, char c, enable_if_tt<std::is_integral<T>, int> u = 0) {
CAF_IGNORE_UNUSED(u);
if (x < (std::numeric_limits<T>::min() / Base))
return false;
x *= Base;
x = static_cast<T>(x * Base);
ascii_to_int<Base, T> f;
auto y = f(c);
if (x < (std::numeric_limits<T>::min() + y))
return false;
x -= y;
x = static_cast<T>(x - y);
return true;
}
......@@ -50,12 +50,10 @@ bool sub_ascii(T& x, char c,
enable_if_tt<std::is_floating_point<T>, int> u = 0) {
CAF_IGNORE_UNUSED(u);
ascii_to_int<Base, T> f;
x = (x * Base) - f(c);
x = static_cast<T>((x * Base) - f(c));
return true;
}
} // namespace parser
} // namespace detail
} // namespace caf
......@@ -33,8 +33,8 @@ public:
// -- constants --------------------------------------------------------------
/// Stores the offset of an embedded IPv4 subnet in bits.
static constexpr uint8_t v4_offset =
static_cast<uint8_t>(ipv6_address::num_bytes - ipv4_address::num_bytes) * 8;
static constexpr size_t v4_offset =
(ipv6_address::num_bytes - ipv4_address::num_bytes) * 8;
// -- constructors, destructors, and assignment operators --------------------
......
......@@ -29,13 +29,14 @@
#include <sys/resource.h>
#endif
#include <cmath>
#include <mutex>
#include <chrono>
#include <vector>
#include <cmath>
#include <cstdint>
#include <fstream>
#include <iomanip>
#include <mutex>
#include <unordered_map>
#include <vector>
#include "caf/actor_system_config.hpp"
#include "caf/defaults.hpp"
......@@ -262,7 +263,7 @@ public:
}
template <class Time, class Label>
void record(Time t, Label label, size_t rec_id, const measurement& m) {
void record(Time t, Label label, uint64_t rec_id, const measurement& m) {
using std::setw;
file_ << setw(21) << t.time_since_epoch().count()
<< setw(10) << label
......
......@@ -114,10 +114,10 @@ protected:
uint8_t buf[16];
auto i = buf;
while (x > 0x7f) {
*i++ = (static_cast<uint8_t>(x) & 0x7f) | 0x80;
*i++ = static_cast<uint8_t>((x & 0x7f) | 0x80);
x >>= 7;
}
*i++ = static_cast<uint8_t>(x) & 0x7f;
*i++ = static_cast<uint8_t>(x & 0x7f);
auto res = streambuf_.sputn(reinterpret_cast<char_type*>(buf),
static_cast<std::streamsize>(i - buf));
if (res != (i - buf))
......
......@@ -79,7 +79,7 @@ protected:
pos_type default_seekoff(off_type off, std::ios_base::seekdir dir,
std::ios_base::openmode which) {
auto new_off = pos_type(off_type(-1));
auto new_off = off_type{-1};
auto get = (which & std::ios_base::in) == std::ios_base::in;
auto put = (which & std::ios_base::out) == std::ios_base::out;
if (!(get || put))
......@@ -220,7 +220,7 @@ protected:
auto available = this->epptr() - this->pptr();
auto actual = std::min(n, static_cast<std::streamsize>(available));
std::memcpy(this->pptr(), s,
static_cast<size_t>(actual * sizeof(char_type)));
static_cast<size_t>(actual) * sizeof(char_type));
this->safe_pbump(actual);
return actual;
}
......@@ -231,7 +231,7 @@ protected:
auto available = this->egptr() - this->gptr();
auto actual = std::min(n, static_cast<std::streamsize>(available));
std::memcpy(s, this->gptr(),
static_cast<size_t>(actual * sizeof(char_type)));
static_cast<size_t>(actual) * sizeof(char_type));
this->safe_gbump(actual);
return actual;
}
......@@ -349,7 +349,7 @@ protected:
auto available = this->egptr() - this->gptr();
auto actual = std::min(n, static_cast<std::streamsize>(available));
std::memcpy(s, this->gptr(),
static_cast<size_t>(actual * sizeof(char_type)));
static_cast<size_t>(actual) * sizeof(char_type));
this->safe_gbump(actual);
return actual;
}
......
......@@ -179,8 +179,9 @@ public:
using other_signatures = detail::type_list<Ts...>;
using m = interface_mismatch_t<other_signatures, signatures>;
// trigger static assert on mismatch
detail::static_error_printer<sizeof...(Ts), m::value,
typename m::xs, typename m::ys> guard;
detail::static_error_printer<static_cast<int>(sizeof...(Ts)), m::value,
typename m::xs, typename m::ys>
guard;
CAF_IGNORE_UNUSED(guard);
}
......@@ -200,7 +201,7 @@ public:
// -- modifiers --------------------------------------------------------------
/// Exchanges the contents of this and other.
inline void swap(typed_behavior& other) {
void swap(typed_behavior& other) {
bhvr_.swap(other.bhvr_);
}
......@@ -242,8 +243,9 @@ private:
using found_signatures = detail::type_list<deduce_mpi_t<Ts>...>;
using m = interface_mismatch_t<found_signatures, signatures>;
// trigger static assert on mismatch
detail::static_error_printer<sizeof...(Ts), m::value,
typename m::xs, typename m::ys> guard;
detail::static_error_printer<static_cast<int>(sizeof...(Ts)), m::value,
typename m::xs, typename m::ys>
guard;
CAF_IGNORE_UNUSED(guard);
// final (type-erasure) step
intrusive_ptr<detail::behavior_impl> ptr = std::move(bp);
......@@ -260,4 +262,3 @@ template <class... Sigs>
struct is_typed_behavior<typed_behavior<Sigs...>> : std::true_type { };
} // namespace caf
......@@ -29,14 +29,14 @@ ipv6_subnet::ipv6_subnet() : prefix_length_(0) {
}
ipv6_subnet::ipv6_subnet(ipv4_subnet subnet)
: address_(ipv6_address{subnet.network_address()}),
prefix_length_(v4_offset + subnet.prefix_length()){
: address_(ipv6_address{subnet.network_address()}) {
prefix_length_ = static_cast<uint8_t>(v4_offset + subnet.prefix_length());
detail::mask_bits(address_.bytes(), prefix_length_);
}
ipv6_subnet::ipv6_subnet(ipv4_address network_address, uint8_t prefix_length)
: address_(network_address),
prefix_length_(prefix_length + v4_offset) {
: address_(network_address) {
prefix_length_ = static_cast<uint8_t>(prefix_length + v4_offset);
detail::mask_bits(address_.bytes(), prefix_length_);
}
......
......@@ -386,9 +386,9 @@ void logger::init(actor_system_config& cfg) {
file_verbosity = get_or(cfg, "logger.file-verbosity", file_verbosity);
console_verbosity =
get_or(cfg, "logger.console-verbosity", console_verbosity);
cfg_.file_verbosity = to_level_int(file_verbosity);
cfg_.console_verbosity = to_level_int(console_verbosity);
cfg_.verbosity = std::max(cfg_.file_verbosity, cfg_.console_verbosity);
cfg_.file_verbosity = to_level_int(file_verbosity) & 0xFu;
cfg_.console_verbosity = to_level_int(console_verbosity) & 0xFu;
cfg_.verbosity = std::max(cfg_.file_verbosity, cfg_.console_verbosity) & 0xFu;
// Parse the format string.
file_format_ =
parse_format(get_or(cfg, "logger.file-format", lg::file_format));
......
......@@ -975,8 +975,8 @@ uint64_t scheduled_actor::set_timeout(atom_value type,
stream_slot scheduled_actor::next_slot() {
stream_slot result = 1;
auto nslot = [](const stream_manager_map& x) -> stream_slot {
return x.rbegin()->first + 1;
auto nslot = [](const stream_manager_map& x) {
return static_cast<stream_slot>(x.rbegin()->first + 1);
};
if (!stream_managers_.empty())
result = std::max(nslot(stream_managers_), result);
......
......@@ -83,7 +83,7 @@ CAF_TEST(depth3) {
CAF_TEST(depth2_type_mismatch) {
auto stage1 = sys.spawn(multiplier, 4);
auto stage2 = sys.spawn(float_adder, 10);
auto stage2 = sys.spawn(float_adder, 10.f);
auto testee = stage2 * stage1;
self->send(testee, 1);
expect((int), from(self).to(stage1).with(1));
......
......@@ -556,7 +556,7 @@ bool basp_broker_state::deliver_pending(execution_unit* ctx,
ep.hdr, payload, false, ep, none))
return false;
i = ep.pending.erase(i);
ep.seq_incoming += 1;
++ep.seq_incoming;
}
// Set a timeout if there are still pending messages.
if (!ep.pending.empty() && !ep.did_set_timeout)
......
......@@ -23,9 +23,9 @@
#include "caf/io/network/default_multiplexer.hpp"
#ifdef CAF_WINDOWS
# include <winsock2.h>
#include <winsock2.h>
#else
# include <sys/socket.h>
#include <sys/socket.h>
#endif
namespace caf {
......@@ -33,11 +33,11 @@ namespace io {
namespace network {
event_handler::event_handler(default_multiplexer& dm, native_socket sockfd)
: fd_(sockfd),
state_{true, false, false, false,
to_integer(receive_policy_flag::at_least)},
eventbf_(0),
backend_(dm) {
: fd_(sockfd),
state_{true, false, false, false,
to_integer(receive_policy_flag::at_least) & 0x2u},
eventbf_(0),
backend_(dm) {
set_fd_flags();
}
......
......@@ -174,7 +174,7 @@ bool instance::handle(execution_unit* ctx, new_datagram_msg& dm,
return true;
}
// This is the expected message.
ep.seq_incoming += 1;
++ep.seq_incoming;
// TODO: add optional reliability here
if (!is_handshake(ep.hdr) && !is_heartbeat(ep.hdr)
&& ep.hdr.dest_node != this_node_) {
......
......@@ -55,7 +55,7 @@ void stream::activate(stream_manager* mgr) {
}
void stream::configure_read(receive_policy::config config) {
state_.rd_flag = to_integer(config.first);
state_.rd_flag = to_integer(config.first) & 0x2;
max_ = config.second;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment