Commit c077fbc0 authored by Dominik Charousset's avatar Dominik Charousset

Merge branch 'topic/warnings'

parents 9aeefaf7 dc0e57d7
......@@ -236,7 +236,7 @@ if(CAF_MORE_WARNINGS)
"-Wno-global-constructors -Wno-missing-prototypes "
"-Wno-c++98-compat-pedantic -Wno-unused-member-function "
"-Wno-unused-const-variable -Wno-switch-enum "
"-Wno-abstract-vbase-init "
"-Wno-abstract-vbase-init -Wno-shadow "
"-Wno-missing-noreturn -Wno-covered-switch-default")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(WFLAGS "-Waddress -Wall -Warray-bounds "
......
......@@ -27,7 +27,9 @@ template <int Base, class T>
struct ascii_to_int {
// @pre `c` is a valid ASCII digit, i.e., matches [0-9].
constexpr T operator()(char c) const {
return c - '0';
// Result is guaranteed to have a value between 0 and 10 and can be safely
// cast to any integer type.
return static_cast<T>(c - '0');
}
};
......@@ -38,7 +40,11 @@ struct ascii_to_int<16, T> {
// Numbers start at position 48 in the ASCII table.
// Uppercase characters start at position 65 in the ASCII table.
// Lowercase characters start at position 97 in the ASCII table.
return c <= '9' ? c - '0' : (c <= 'F' ? 10 + (c - 'A') : 10 + (c - 'a'));
// Result is guaranteed to have a value between 0 and 16 and can be safely
// cast to any integer type.
return static_cast<T>(c <= '9'
? c - '0'
: (c <= 'F' ? 10 + (c - 'A') : 10 + (c - 'a')));
}
};
......
......@@ -43,8 +43,8 @@ struct read_ipv4_octet_consumer {
std::array<uint8_t, 4> bytes;
int octets = 0;
inline void value(uint8_t octet) {
bytes[octets++] = octet;
void value(uint8_t octet) {
bytes[static_cast<size_t>(octets++)] = octet;
}
};
......
......@@ -159,7 +159,7 @@ struct is_primitive {
};
/// Checks whether `T1` is comparable with `T2`.
template <class T1, typename T2>
template <class T1, class T2>
class is_comparable {
// SFINAE: If you pass a "bool*" as third argument, then
// decltype(cmp_help_fun(...)) is bool if there's an
......@@ -168,16 +168,25 @@ class is_comparable {
// cmp_help_fun(A*, B*, void*). If there's no operator==(A, B)
// available, then cmp_help_fun(A*, B*, void*) is the only
// candidate and thus decltype(cmp_help_fun(...)) is void.
template <class A, typename B>
template <class A, class B>
static bool cmp_help_fun(const A* arg0, const B* arg1,
decltype(*arg0 == *arg1)* = nullptr);
decltype(*arg0 == *arg1)*,
std::integral_constant<bool, false>);
template <class A, typename B>
static void cmp_help_fun(const A*, const B*, void* = nullptr);
// silences float-equal warnings caused by decltype(*arg0 == *arg1)
template <class A, class B>
static bool cmp_help_fun(const A*, const B*, bool*,
std::integral_constant<bool, true>);
template <class A, class B, class C>
static void cmp_help_fun(const A*, const B*, void*, C);
using result_type = decltype(cmp_help_fun(
static_cast<T1*>(nullptr), static_cast<T2*>(nullptr),
static_cast<bool*>(nullptr),
std::integral_constant<bool, std::is_arithmetic<T1>::value
&& std::is_arithmetic<T2>::value>{}));
using result_type = decltype(cmp_help_fun(static_cast<T1*>(nullptr),
static_cast<T2*>(nullptr),
static_cast<bool*>(nullptr)));
public:
static constexpr bool value = std::is_same<bool, result_type>::value;
};
......
......@@ -140,8 +140,9 @@ public:
// dequeue attempts
auto& strategies = d(self).strategies;
resumable* job = nullptr;
for (int k = 0; k < 2; ++k) { // iterate over the first two strategies
for (size_t i = 0; i < strategies[k].attempts; i += strategies[k].step_size) {
for (size_t k = 0; k < 2; ++k) { // iterate over the first two strategies
for (size_t i = 0; i < strategies[k].attempts;
i += strategies[k].step_size) {
job = d(self).queue.take_head();
if (job)
return job;
......
......@@ -122,10 +122,10 @@ using sum_type_visit_result_t =
typename sum_type_visit_result<detail::decay_t<F>,
detail::decay_t<Ts>...>::type;
template <class Result, int I, class Visitor>
template <class Result, size_t I, class Visitor>
struct visit_impl_continuation;
template <class Result, int I>
template <class Result, size_t I>
struct visit_impl {
template <class Visitor, class T, class... Ts>
static Result apply(Visitor&& f, T&& x, Ts&&... xs) {
......@@ -145,7 +145,7 @@ struct visit_impl<Result, 0> {
};
template <class Result, int I, class Visitor>
template <class Result, size_t I, class Visitor>
struct visit_impl_continuation {
Visitor& f;
template <class... Ts>
......
......@@ -47,11 +47,6 @@ struct kvstate {
std::unordered_map<key_type, std::pair<mapped_type, subscriber_set>> data;
std::unordered_map<strong_actor_ptr, topic_set> subscribers;
static const char* name;
template <class Processor>
friend void serialize(Processor& proc, kvstate& x, unsigned int) {
proc & x.data;
proc & x.subscribers;
}
};
const char* kvstate::name = "config_server";
......
......@@ -177,8 +177,9 @@ auto config_option_set::parse(config_map& config, argument_iterator first,
if (opt == nullptr)
return {pec::not_an_option, i};
auto code = consume(*opt,
assign_op == npos ? i->end()
: i->begin() + assign_op + 1,
assign_op == npos
? i->end()
: i->begin() + static_cast<ptrdiff_t>(assign_op + 1),
i->end());
if (code != pec::success)
return {code, i};
......
......@@ -94,7 +94,8 @@ error parse(string_view str, ipv4_address& dest) {
parser::read_ipv4_address(res, f);
if (res.code == pec::success)
return none;
return make_error(res.code, res.line, res.column);
return make_error(res.code, static_cast<size_t>(res.line),
static_cast<size_t>(res.column));
}
} // namespace caf
......@@ -183,8 +183,8 @@ std::string to_string(ipv6_address x) {
// Output buffer.
std::string result;
// Utility for appending chunks to the result.
auto add_chunk = [&](uint16_t x) {
append_v6_hex(result, reinterpret_cast<uint8_t*>(&x));
auto add_chunk = [&](uint16_t chunk) {
append_v6_hex(result, reinterpret_cast<uint8_t*>(&chunk));
};
auto add_chunks = [&](u16_iterator i, u16_iterator e) {
if (i != e) {
......@@ -217,7 +217,8 @@ error parse(string_view str, ipv6_address& dest) {
parser::read_ipv6_address(res, f);
if (res.code == pec::success)
return none;
return make_error(res.code, res.line, res.column);
return make_error(res.code, static_cast<size_t>(res.line),
static_cast<size_t>(res.column));
}
} // namespace caf
......@@ -104,15 +104,15 @@ meta_state ms_res_meta{
return make_error(pec::type_mismatch);
},
[](void* ptr, const config_value& x) {
*static_cast<size_t*>(ptr) = get<timespan>(x).count() / 1000000;
*static_cast<size_t*>(ptr) = static_cast<size_t>(get<timespan>(x).count()
/ 1000000);
},
[](const void* ptr) -> config_value {
auto ival = static_cast<int64_t>(*static_cast<const size_t*>(ptr));
timespan val{ival * 1000000};
return config_value{val};
},
detail::type_name<timespan>()
};
detail::type_name<timespan>()};
} // namespace
......
......@@ -130,12 +130,12 @@ scheduled_actor::scheduled_actor(actor_config& cfg)
CAF_ASSERT(interval.count() > 0);
stream_ticks_.interval(interval);
CAF_ASSERT(sys_cfg.stream_max_batch_delay.count() > 0);
max_batch_delay_ticks_ = sys_cfg.stream_max_batch_delay.count()
/ interval.count();
auto div = [](timespan x, timespan y) {
return static_cast<size_t>(x.count() / y.count());
};
max_batch_delay_ticks_ = div(sys_cfg.stream_max_batch_delay, interval);
CAF_ASSERT(max_batch_delay_ticks_ > 0);
CAF_ASSERT(sys_cfg.stream_credit_round_interval.count() > 0);
credit_round_ticks_ = sys_cfg.stream_credit_round_interval.count()
/ interval.count();
credit_round_ticks_ = div(sys_cfg.stream_credit_round_interval, interval);
CAF_ASSERT(credit_round_ticks_ > 0);
CAF_LOG_DEBUG(CAF_ARG(interval) << CAF_ARG(max_batch_delay_ticks_)
<< CAF_ARG(credit_round_ticks_));
......
......@@ -75,10 +75,11 @@ void replace_all(std::string& str, string_view what, string_view with) {
while (i != str.end()) {
auto before = std::distance(str.begin(), i);
CAF_ASSERT(before >= 0);
str.replace(i, i + what.size(), with.begin(), with.end());
auto ws = static_cast<decltype(before)>(what.size());
str.replace(i, i + ws, with.begin(), with.end());
// Iterator i became invalidated -> use new iterator pointing to the first
// character after the replaced text.
i = next(str.begin() + before + with.size());
i = next(str.begin() + before + ws);
}
}
......
......@@ -105,7 +105,8 @@ error parse(string_view str, uri& dest) {
dest = builder.make();
return none;
}
return make_error(res.code, res.line, res.column);
return make_error(res.code, static_cast<size_t>(res.line),
static_cast<size_t>(res.column));
}
} // namespace caf
......@@ -95,7 +95,7 @@ void uri_impl::add_encoded(string_view x, bool is_path) {
str += ch;
break;
}
// fall through
CAF_ANNOTATE_FALLTHROUGH;
case ' ':
case ':':
case '?':
......
......@@ -30,12 +30,12 @@ using namespace caf;
namespace {
template <class... Ts>
void print(const char* format, Ts... xs) {
char buf[200];
snprintf(buf, 200, format, xs...);
CAF_MESSAGE(buf);
}
#define PRINT(format, ...) \
{ \
char buf[200]; \
snprintf(buf, 200, format, __VA_ARGS__); \
CAF_MESSAGE(buf); \
}
struct fixture {
inbound_path::stats_t x;
......@@ -53,11 +53,11 @@ struct fixture {
int32_t t = total_time;
int32_t m = t > 0 ? std::max((c * n) / t, 1) : 1;
int32_t b = t > 0 ? std::max((d * n) / t, 1) : 1;
print("with a cycle C = %ldns, desied complexity D = %ld,", c, d);
print("number of items N = %ld, and time delta t = %ld:", n, t);
print("- throughput M = max(C * N / t, 1) = max(%ld * %ld / %ld, 1) = %ld",
PRINT("with a cycle C = %dns, desied complexity D = %d,", c, d);
PRINT("number of items N = %d, and time delta t = %d:", n, t);
PRINT("- throughput M = max(C * N / t, 1) = max(%d * %d / %d, 1) = %d",
c, n, t, m);
print("- items/batch B = max(D * N / t, 1) = max(%ld * %ld / %ld, 1) = %ld",
PRINT("- items/batch B = max(D * N / t, 1) = max(%d * %d / %d, 1) = %d",
d, n, t, b);
auto cr = x.calculate(timespan(c), timespan(d));
CAF_CHECK_EQUAL(cr.items_per_batch, b);
......
......@@ -131,11 +131,11 @@ CAF_TEST(containerbuf_reset_get_area) {
std::vector<char> buf;
vectorbuf vb{buf};
// We can always write to the underlying buffer; no put area needed.
auto n = vb.sputn(str.data(), str.size());
auto n = vb.sputn(str.data(), static_cast<std::streamsize>(str.size()));
CAF_REQUIRE_EQUAL(n, 6);
// Readjust the get area.
CAF_REQUIRE_EQUAL(buf.size(), 6u);
vb.pubsetbuf(buf.data() + 3, buf.size() - 3);
vb.pubsetbuf(buf.data() + 3, static_cast<std::streamsize>(buf.size() - 3));
// Now read from a new get area into a buffer.
char bar[3];
n = vb.sgetn(bar, 3);
......
......@@ -34,13 +34,6 @@
namespace {
struct tostring_visitor : caf::static_visitor<std::string> {
template <class T>
inline std::string operator()(const T& value) {
return to_string(value);
}
};
class union_type {
public:
friend struct caf::default_sum_type_access<union_type>;
......@@ -59,11 +52,6 @@ public:
destroy();
}
template <class T>
union_type(T x) : union_type() {
*this = x;
}
union_type& operator=(T0 value) {
destroy();
index_ = 0;
......
......@@ -184,7 +184,7 @@ public:
return pos;
auto offset = static_cast<size_t>(std::distance(begin(), pos));
auto old_size = size_;
resize(old_size + n);
resize(old_size + static_cast<size_t>(n));
pos = begin() + offset;
if (offset != old_size) {
memmove(pos + n, pos, old_size - offset);
......
......@@ -52,16 +52,6 @@ struct seq_num_visitor {
basp_broker_state* state;
};
struct close_visitor {
using result_type = void;
close_visitor(broker* ptr) : b(ptr) { }
template <class T>
result_type operator()(const T& hdl) {
b->close(hdl);
}
broker* b;
};
} // namespace anonymous
const char* basp_broker_state::name = "basp_broker";
......
......@@ -66,21 +66,6 @@ bool operator==(const maybe<T>& x, const T& y) {
return x.val ? x.val == y : true;
}
template <class T>
bool operator==(const T& x, const maybe<T>& y) {
return y.val ? x == y.val : true;
}
template <class T>
bool operator!=(const maybe<T>& x, const T& y) {
return !(x == y);
}
template <class T>
bool operator!=(const T& x, const maybe<T>& y) {
return !(x == y);
}
constexpr uint8_t no_flags = 0;
constexpr uint32_t no_payload = 0;
constexpr uint64_t no_operation_data = 0;
......
......@@ -70,21 +70,6 @@ bool operator==(const maybe<T>& x, const T& y) {
return x.val ? x.val == y : true;
}
template <class T>
bool operator==(const T& x, const maybe<T>& y) {
return y.val ? x == y.val : true;
}
template <class T>
bool operator!=(const maybe<T>& x, const T& y) {
return !(x == y);
}
template <class T>
bool operator!=(const T& x, const maybe<T>& y) {
return !(x == y);
}
constexpr uint8_t no_flags = 0;
constexpr uint32_t no_payload = 0;
constexpr uint64_t no_operation_data = 0;
......
......@@ -39,45 +39,48 @@ CAF_POP_WARNINGS
#include "caf/openssl/middleman_actor.hpp"
#if OPENSSL_VERSION_NUMBER < 0x10100000L
struct CRYPTO_dynlock_value {
std::mutex mtx;
};
namespace caf {
namespace openssl {
namespace {
#if OPENSSL_VERSION_NUMBER < 0x10100000L
static int init_count = 0;
static std::mutex init_mutex;
static std::vector<std::mutex> mutexes;
int init_count = 0;
std::mutex init_mutex;
std::vector<std::mutex> mutexes;
static void locking_function(int mode, int n,
const char* /* file */, int /* line */) {
void locking_function(int mode, int n, const char*, int) {
if (mode & CRYPTO_LOCK)
mutexes[n].lock();
mutexes[static_cast<size_t>(n)].lock();
else
mutexes[n].unlock();
mutexes[static_cast<size_t>(n)].unlock();
}
static CRYPTO_dynlock_value* dynlock_create(const char* /* file */,
int /* line */) {
return new CRYPTO_dynlock_value{};
CRYPTO_dynlock_value* dynlock_create(const char*, int) {
return new CRYPTO_dynlock_value;
}
static void dynlock_lock(int mode, CRYPTO_dynlock_value* dynlock,
const char* /* file */, int /* line */) {
void dynlock_lock(int mode, CRYPTO_dynlock_value* dynlock, const char*, int) {
if (mode & CRYPTO_LOCK)
dynlock->mtx.lock();
else
dynlock->mtx.unlock();
}
static void dynlock_destroy(CRYPTO_dynlock_value* dynlock,
const char* /* file */, int /* line */) {
void dynlock_destroy(CRYPTO_dynlock_value* dynlock, const char*, int) {
delete dynlock;
}
} // namespace <anonymous>
#endif
namespace caf {
namespace openssl {
manager::~manager() {
#if OPENSSL_VERSION_NUMBER < 0x10100000L
std::lock_guard<std::mutex> lock{init_mutex};
......@@ -119,12 +122,11 @@ void manager::init(actor_system_config&) {
if (system().config().openssl_key.size() == 0)
CAF_RAISE_ERROR("No private key configured for SSL endpoint");
}
#if OPENSSL_VERSION_NUMBER < 0x10100000L
std::lock_guard<std::mutex> lock{init_mutex};
++init_count;
if (init_count == 1) {
mutexes = std::vector<std::mutex>(CRYPTO_num_locks());
mutexes = std::vector<std::mutex>{static_cast<size_t>(CRYPTO_num_locks())};
CRYPTO_set_locking_callback(locking_function);
CRYPTO_set_dynlock_create_callback(dynlock_create);
CRYPTO_set_dynlock_lock_callback(dynlock_lock);
......
......@@ -109,7 +109,7 @@ class scribe_impl : public io::scribe {
// nop
}
~scribe_impl() {
~scribe_impl() override {
CAF_LOG_TRACE("");
}
......
......@@ -244,6 +244,8 @@ void bootstrap(actor_system& system,
return 1; \
} while (true)
namespace {
struct config : actor_system_config {
config() {
opt_group{custom_options_, "global"}
......@@ -254,6 +256,8 @@ struct config : actor_system_config {
string wdir;
};
} // namespace <anonymous>
int main(int argc, char** argv) {
config cfg;
cfg.parse(argc, argv);
......
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