diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000000..4098004d2c --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,30 @@ +--- +Checks: 'clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-alpha*,modernize-*,performance-*,readability-*,-readability-braces-around-statements,-readability-named-parameter' +WarningsAsErrors: '' +HeaderFilterRegex: '/caf/' +AnalyzeTemporaryDtors: false +CheckOptions: + - key: cert-oop11-cpp.UseCERTSemantics + value: '1' + - key: google-readability-braces-around-statements.ShortStatementLines + value: '1' + - key: google-readability-function-size.StatementThreshold + value: '800' + - key: google-readability-namespace-comments.ShortNamespaceLines + value: '10' + - key: google-readability-namespace-comments.SpacesBeforeComments + value: '2' + - key: modernize-loop-convert.MaxCopySize + value: '16' + - key: modernize-loop-convert.MinConfidence + value: reasonable + - key: modernize-loop-convert.NamingStyle + value: CamelCase + - key: modernize-pass-by-value.IncludeStyle + value: llvm + - key: modernize-replace-auto-ptr.IncludeStyle + value: llvm + - key: modernize-use-nullptr.NullMacros + value: 'NULL' +... + diff --git a/examples/broker/protobuf_broker.cpp b/examples/broker/protobuf_broker.cpp index c5becb718a..1952feee15 100644 --- a/examples/broker/protobuf_broker.cpp +++ b/examples/broker/protobuf_broker.cpp @@ -137,7 +137,7 @@ void protobuf_io(broker* self, connection_handle hdl, const actor& buddy) { self->become(await_length_prefix); } -behavior server(broker* self, actor buddy) { +behavior server(broker* self, const actor& buddy) { print_on_exit(self, "server"); aout(self) << "server is running" << endl; return { diff --git a/examples/curl/curl_fuse.cpp b/examples/curl/curl_fuse.cpp index b8e36b45d7..0047444b85 100644 --- a/examples/curl/curl_fuse.cpp +++ b/examples/curl/curl_fuse.cpp @@ -1,4 +1,4 @@ -/******************************************************************************\ +/****************************************************************************** * This example * * - emulates a client launching a request every 10-300ms * * - uses a CURL-backend consisting of a master and 10 workers * @@ -28,12 +28,12 @@ * | |<--/ * * | <-------------(reply)-------------- | * * X * -\ ******************************************************************************/ + ******************************************************************************/ // C includes -#include -#include -#include +#include +#include +#include // C++ includes #include @@ -129,7 +129,7 @@ struct base_state { }; // encapsulates an HTTP request -behavior client_job(stateful_actor* self, actor parent) { +behavior client_job(stateful_actor* self, const actor& parent) { if (!self->state.init("client-job", color::blue)) return {}; // returning an empty behavior terminates the actor self->send(parent, read_atom::value, @@ -164,7 +164,7 @@ struct client_state : base_state { }; // spawns HTTP requests -behavior client(stateful_actor* self, actor parent) { +behavior client(stateful_actor* self, const actor& parent) { using std::chrono::milliseconds; self->link_to(parent); if (!self->state.init("client", color::green)) @@ -190,8 +190,8 @@ struct curl_state : base_state { // nop } - ~curl_state() { - if (curl) + ~curl_state() override { + if (curl != nullptr) curl_easy_cleanup(curl); } @@ -206,7 +206,7 @@ struct curl_state : base_state { bool init(std::string m_name, std::string m_color) override { curl = curl_easy_init(); - if (!curl) + if (curl == nullptr) return false; curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &curl_state::callback); curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); @@ -218,7 +218,7 @@ struct curl_state : base_state { }; // manages a CURL session -behavior curl_worker(stateful_actor* self, actor parent) { +behavior curl_worker(stateful_actor* self, const actor& parent) { if (!self->state.init("curl-worker", color::yellow)) return {}; // returning an empty behavior terminates the actor return { @@ -340,7 +340,7 @@ void caf_main(actor_system& system) { struct sigaction act; act.sa_handler = [](int) { shutdown_flag = true; }; auto set_sighandler = [&] { - if (sigaction(SIGINT, &act, 0)) { + if (sigaction(SIGINT, &act, nullptr) != 0) { std::cerr << "fatal: cannot set signal handler" << std::endl; abort(); } diff --git a/examples/dynamic_behavior/dining_philosophers.cpp b/examples/dynamic_behavior/dining_philosophers.cpp index 8f828b8877..f8dd65c981 100644 --- a/examples/dynamic_behavior/dining_philosophers.cpp +++ b/examples/dynamic_behavior/dining_philosophers.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -34,7 +35,8 @@ using think_atom = atom_constant; using chopstick = typed_actor::with, reacts_to>; -chopstick::behavior_type taken_chopstick(chopstick::pointer, strong_actor_ptr); +chopstick::behavior_type taken_chopstick(chopstick::pointer, + const strong_actor_ptr&); // either taken by a philosopher or available chopstick::behavior_type available_chopstick(chopstick::pointer self) { @@ -50,7 +52,7 @@ chopstick::behavior_type available_chopstick(chopstick::pointer self) { } chopstick::behavior_type taken_chopstick(chopstick::pointer self, - strong_actor_ptr user) { + const strong_actor_ptr& user) { return { [](take_atom) -> std::tuple { return std::make_tuple(taken_atom::value, false); @@ -94,13 +96,13 @@ chopstick::behavior_type taken_chopstick(chopstick::pointer self, class philosopher : public event_based_actor { public: philosopher(actor_config& cfg, - const std::string& n, - const chopstick& l, - const chopstick& r) + std::string n, + chopstick l, + chopstick r) : event_based_actor(cfg), - name_(n), - left_(l), - right_(r) { + name_(std::move(n)), + left_(std::move(l)), + right_(std::move(r)) { // we only accept one message per state and skip others in the meantime set_default_handler(skip); // a philosopher that receives {eat} stops thinking and becomes hungry diff --git a/examples/message_passing/delegating.cpp b/examples/message_passing/delegating.cpp index 82d50e7357..e4714710e7 100644 --- a/examples/message_passing/delegating.cpp +++ b/examples/message_passing/delegating.cpp @@ -12,7 +12,7 @@ using namespace caf; using calc = typed_actor::with>; -void actor_a(event_based_actor* self, calc worker) { +void actor_a(event_based_actor* self, const calc& worker) { self->request(worker, std::chrono::seconds(10), add_atom::value, 1, 2).then( [=](int result) { aout(self) << "1 + 2 = " << result << endl; @@ -20,7 +20,7 @@ void actor_a(event_based_actor* self, calc worker) { ); } -calc::behavior_type actor_b(calc::pointer self, calc worker) { +calc::behavior_type actor_b(calc::pointer self, const calc& worker) { return { [=](add_atom add, int x, int y) { return self->delegate(worker, add, x, y); diff --git a/examples/message_passing/dining_philosophers.cpp b/examples/message_passing/dining_philosophers.cpp deleted file mode 100644 index 1a10795601..0000000000 --- a/examples/message_passing/dining_philosophers.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/******************************************************************************\ - * This example is an implementation of the classical Dining Philosophers * - * exercise using only libcaf's event-based actor implementation. * -\ ******************************************************************************/ - -#include -#include -#include -#include -#include -#include - -namespace std { -string to_string(const thread::id& x) { - ostringstream os; - os << x; - return os.str(); -} -} - - - -#include "caf/all.hpp" - -using std::cout; -using std::cerr; -using std::endl; -using std::chrono::seconds; - -using namespace caf; - -namespace { - -// atoms for chopstick interface -using put_atom = atom_constant; -using take_atom = atom_constant; -using taken_atom = atom_constant; - -// atoms for philosopher interface -using eat_atom = atom_constant; -using think_atom = atom_constant; - -// a chopstick -using chopstick = typed_actor::with, - reacts_to>; - -chopstick::behavior_type taken_chopstick(chopstick::pointer self, actor_addr); - -// either taken by a philosopher or available -chopstick::behavior_type available_chopstick(chopstick::pointer self) { - return { - [=](take_atom) -> std::tuple { - self->become(taken_chopstick(self, self->current_sender())); - return std::make_tuple(taken_atom::value, true); - }, - [](put_atom) { - cerr << "chopstick received unexpected 'put'" << endl; - } - }; -} - -chopstick::behavior_type taken_chopstick(chopstick::pointer self, - actor_addr user) { - return { - [](take_atom) -> std::tuple { - return std::make_tuple(taken_atom::value, false); - }, - [=](put_atom) { - if (self->current_sender() == user) - self->become(available_chopstick(self)); - } - }; -} - -/* Based on: http://www.dalnefre.com/wp/2010/08/dining-philosophers-in-humus/ - * - * - * +-------------+ {busy|taken} - * /-------->| thinking |<------------------\ - * | +-------------+ | - * | | | - * | | {eat} | - * | | | - * | V | - * | +-------------+ {busy} +-------------+ - * | | hungry |----------->| denied | - * | +-------------+ +-------------+ - * | | - * | | {taken} - * | | - * | V - * | +-------------+ - * | | granted | - * | +-------------+ - * | | | - * | {busy} | | {taken} - * \-----------/ | - * | V - * | {think} +-------------+ - * \---------| eating | - * +-------------+ - */ - -class philosopher : public event_based_actor { -public: - philosopher(actor_config& cfg, - const std::string& n, - const chopstick& l, - const chopstick& r) - : event_based_actor(cfg), - name(n), - left(l), - right(r) { - // a philosopher that receives {eat} stops thinking and becomes hungry - thinking.assign( - [=](eat_atom) { - become(hungry); - send(left, take_atom::value); - send(right, take_atom::value); - } - ); - // wait for the first answer of a chopstick - hungry.assign( - [=](taken_atom, bool result) { - if (result) - become(granted); - else - become(denied); - } - ); - // philosopher was able to obtain the first chopstick - granted.assign( - [=](taken_atom, bool result) { - if (result) { - aout(this) << name - << " has picked up chopsticks with IDs " - << left->id() << " and " << right->id() - << " and starts to eat\n"; - // eat some time - delayed_send(this, seconds(5), think_atom::value); - become(eating); - } else { - send(current_sender() == left ? right : left, put_atom::value); - send(this, eat_atom::value); - become(thinking); - } - } - ); - // philosopher was *not* able to obtain the first chopstick - denied.assign( - [=](taken_atom, bool result) { - if (result) - send(current_sender() == left ? left : right, put_atom::value); - send(this, eat_atom::value); - become(thinking); - } - ); - // philosopher obtained both chopstick and eats (for five seconds) - eating.assign( - [=](think_atom) { - send(left, put_atom::value); - send(right, put_atom::value); - delayed_send(this, seconds(5), eat_atom::value); - aout(this) << name << " puts down his chopsticks and starts to think\n"; - become(thinking); - } - ); - } - -protected: - behavior make_behavior() override { - // start thinking - send(this, think_atom::value); - // philosophers start to think after receiving {think} - return ( - [=](think_atom) { - aout(this) << name << " starts to think\n"; - delayed_send(this, seconds(5), eat_atom::value); - become(thinking); - } - ); - } - -private: - std::string name; // the name of this philosopher - chopstick left; // left chopstick - chopstick right; // right chopstick - behavior thinking; // initial behavior - behavior hungry; // tries to take chopsticks - behavior granted; // has one chopstick and waits for the second one - behavior denied; // could not get first chopsticks - behavior eating; // wait for some time, then go thinking again -}; - -} // namespace - -int main(int, char**) { - actor_system system; - scoped_actor self{system}; - // create five chopsticks - aout(self) << "chopstick ids are:"; - std::vector chopsticks; - for (size_t i = 0; i < 5; ++i) { - chopsticks.push_back(self->spawn(available_chopstick)); - aout(self) << " " << chopsticks.back()->id(); - } - aout(self) << endl; - // spawn five philosophers - std::vector names {"Plato", "Hume", "Kant", - "Nietzsche", "Descartes"}; - for (size_t i = 0; i < 5; ++i) - self->spawn(names[i], chopsticks[i], chopsticks[(i + 1) % 5]); -} diff --git a/examples/remoting/distributed_calculator.cpp b/examples/remoting/distributed_calculator.cpp index aa73511b5f..b000975224 100644 --- a/examples/remoting/distributed_calculator.cpp +++ b/examples/remoting/distributed_calculator.cpp @@ -9,7 +9,7 @@ // Run client at the same host: // - ./build/bin/distributed_math_actor -c -p 4242 -// Manual refs: 221-233 (ConfiguringActorSystems) +// Manual refs: 222-234 (ConfiguringActorSystems) #include #include @@ -31,7 +31,7 @@ using namespace caf; namespace { -static constexpr auto task_timeout = std::chrono::seconds(10); +constexpr auto task_timeout = std::chrono::seconds(10); using plus_atom = atom_constant; using minus_atom = atom_constant; @@ -97,7 +97,7 @@ void connecting(stateful_actor*, const std::string& host, uint16_t port); // prototype definition for transition to `running` with Calculator -behavior running(stateful_actor*, actor calculator); +behavior running(stateful_actor*, const actor& calculator); // starting point of our FSM behavior init(stateful_actor* self) { @@ -133,14 +133,15 @@ void connecting(stateful_actor* self, // use request().await() to suspend regular behavior until MM responded auto mm = self->system().middleman().actor_handle(); self->request(mm, infinite, connect_atom::value, host, port).await( - [=](const node_id&, strong_actor_ptr serv, const std::set& ifs) { + [=](const node_id&, strong_actor_ptr serv, + const std::set& ifs) { if (!serv) { - aout(self) << "*** no server found at \"" << host << "\":" + aout(self) << R"(*** no server found at ")" << host << R"(":)" << port << endl; return; } if (!ifs.empty()) { - aout(self) << "*** typed actor found at \"" << host << "\":" + aout(self) << R"(*** typed actor found at ")" << host << R"(":)" << port << ", but expected an untyped actor "<< endl; return; } @@ -151,7 +152,7 @@ void connecting(stateful_actor* self, self->become(running(self, hdl)); }, [=](const error& err) { - aout(self) << "*** cannot connect to \"" << host << "\":" + aout(self) << R"(*** cannot connect to ")" << host << R"(":)" << port << " => " << self->system().render(err) << endl; self->become(unconnected(self)); } @@ -159,7 +160,7 @@ void connecting(stateful_actor* self, } // prototype definition for transition to `running` with Calculator -behavior running(stateful_actor* self, actor calculator) { +behavior running(stateful_actor* self, const actor& calculator) { auto send_task = [=](const task& x) { self->request(calculator, task_timeout, x.op, x.lhs, x.rhs).then( [=](int result) { @@ -192,7 +193,7 @@ behavior running(stateful_actor* self, actor calculator) { // removes leading and trailing whitespaces string trim(std::string s) { - auto not_space = [](char c) { return !isspace(c); }; + auto not_space = [](char c) { return isspace(c) == 0; }; // trim left s.erase(s.begin(), find_if(s.begin(), s.end(), not_space)); // trim right @@ -249,7 +250,7 @@ void client_repl(actor_system& system, const config& cfg) { anon_send(client, connect_atom::value, cfg.host, cfg.port); else cout << "*** no server received via config, " - << "please use \"connect \" before using the calculator" + << R"(please use "connect " before using the calculator)" << endl; // defining the handler outside the loop is more efficient as it avoids // re-creating the same object over and over again @@ -265,9 +266,9 @@ void client_repl(actor_system& system, const config& cfg) { char* end = nullptr; auto lport = strtoul(arg2.c_str(), &end, 10); if (end != arg2.c_str() + arg2.size()) - cout << "\"" << arg2 << "\" is not an unsigned integer" << endl; + cout << R"(")" << arg2 << R"(" is not an unsigned integer)" << endl; else if (lport > std::numeric_limits::max()) - cout << "\"" << arg2 << "\" > " + cout << R"(")" << arg2 << R"(" > )" << std::numeric_limits::max() << endl; else anon_send(client, connect_atom::value, move(arg1), diff --git a/examples/remoting/group_chat.cpp b/examples/remoting/group_chat.cpp index aae58800f8..eaaac8275c 100644 --- a/examples/remoting/group_chat.cpp +++ b/examples/remoting/group_chat.cpp @@ -42,7 +42,7 @@ behavior client(event_based_actor* self, const string& name) { } }, [=](join_atom, const group& what) { - for (auto g : self->joined_groups()) { + for (const auto& g : self->joined_groups()) { cout << "*** leave " << to_string(g) << endl; self->send(g, name + " has left the chatroom"); self->leave(g); @@ -108,7 +108,7 @@ void run_client(actor_system& system, const config& cfg) { if (tmp) anon_send(client_actor, join_atom::value, std::move(*tmp)); else - cerr << "*** failed to parse \"" << uri << "\" as group URI: " + cerr << R"(*** failed to parse ")" << uri << R"(" as group URI: )" << system.render(tmp.error()) << endl; } istream_iterator eof; diff --git a/examples/remoting/remote_spawn.cpp b/examples/remoting/remote_spawn.cpp index 9cf94a8bdd..cae5f102d8 100644 --- a/examples/remoting/remote_spawn.cpp +++ b/examples/remoting/remote_spawn.cpp @@ -51,7 +51,7 @@ calculator::behavior_type calculator_fun(calculator::pointer self) { // removes leading and trailing whitespaces string trim(string s) { - auto not_space = [](char c) { return !isspace(c); }; + auto not_space = [](char c) { return isspace(c) == 0; }; // trim left s.erase(s.begin(), find_if(s.begin(), s.end(), not_space)); // trim right diff --git a/libcaf_core/caf/abstract_actor.hpp b/libcaf_core/caf/abstract_actor.hpp index 4cee1c241a..5871781d79 100644 --- a/libcaf_core/caf/abstract_actor.hpp +++ b/libcaf_core/caf/abstract_actor.hpp @@ -61,7 +61,7 @@ class abstract_actor : public abstract_channel { actor_control_block* ctrl() const; - virtual ~abstract_actor(); + ~abstract_actor() override; /// Cleans up any remaining state before the destructor is called. /// This function makes sure it is safe to call virtual functions @@ -71,7 +71,7 @@ class abstract_actor : public abstract_channel { virtual void on_destroy(); void enqueue(strong_actor_ptr sender, message_id mid, - message content, execution_unit* host) override; + message msg, execution_unit* host) override; /// Enqueues a new message wrapped in a `mailbox_element` to the actor. /// This `enqueue` variant allows to define forwarding chains. diff --git a/libcaf_core/caf/abstract_channel.hpp b/libcaf_core/caf/abstract_channel.hpp index 2ea727cfcf..0e1fb9cb76 100644 --- a/libcaf_core/caf/abstract_channel.hpp +++ b/libcaf_core/caf/abstract_channel.hpp @@ -80,7 +80,7 @@ class abstract_channel { private: // can only be called from abstract_actor and abstract_group - abstract_channel(int init_flags); + abstract_channel(int fs); // Accumulates several state and type flags. Subtypes may use only the // first 20 bits, i.e., the bitmask 0xFFF00000 is reserved for diff --git a/libcaf_core/caf/abstract_group.hpp b/libcaf_core/caf/abstract_group.hpp index 33be303ab0..0904bd1dc0 100644 --- a/libcaf_core/caf/abstract_group.hpp +++ b/libcaf_core/caf/abstract_group.hpp @@ -42,7 +42,7 @@ class abstract_group : public ref_counted, public abstract_channel { // -- constructors, destructors, and assignment operators -------------------- - ~abstract_group(); + ~abstract_group() override; // -- pure virtual member functions ------------------------------------------ @@ -78,7 +78,7 @@ class abstract_group : public ref_counted, public abstract_channel { } protected: - abstract_group(group_module& parent, std::string id, node_id origin); + abstract_group(group_module& mod, std::string id, node_id nid); actor_system& system_; group_module& parent_; diff --git a/libcaf_core/caf/actor_companion.hpp b/libcaf_core/caf/actor_companion.hpp index 42f37bfb79..62584177f1 100644 --- a/libcaf_core/caf/actor_companion.hpp +++ b/libcaf_core/caf/actor_companion.hpp @@ -73,14 +73,14 @@ class actor_companion : public extend:: actor_companion(actor_config& cfg); - ~actor_companion(); + ~actor_companion() override; // -- overridden functions --------------------------------------------------- - void enqueue(mailbox_element_ptr what, execution_unit* host) override; + void enqueue(mailbox_element_ptr ptr, execution_unit* host) override; - void enqueue(strong_actor_ptr sender, message_id mid, message content, - execution_unit* host) override; + void enqueue(strong_actor_ptr src, message_id mid, message content, + execution_unit* eu) override; void launch(execution_unit* eu, bool lazy, bool hide) override; diff --git a/libcaf_core/caf/actor_factory.hpp b/libcaf_core/caf/actor_factory.hpp index a715398b91..8c1dfe7159 100644 --- a/libcaf_core/caf/actor_factory.hpp +++ b/libcaf_core/caf/actor_factory.hpp @@ -47,7 +47,7 @@ template class fun_decorator> { public: - fun_decorator(const F& f, T*) : f_(f) { + fun_decorator(F f, T*) : f_(std::move(f)) { // nop } @@ -84,7 +84,7 @@ template class fun_decorator> { public: - fun_decorator(const F& f, T* ptr) : f_(f), ptr_(ptr) { + fun_decorator(F f, T* ptr) : f_(std::move(f)), ptr_(ptr) { // nop } diff --git a/libcaf_core/caf/actor_ostream.hpp b/libcaf_core/caf/actor_ostream.hpp index 35beec3eb9..70890e4b8c 100644 --- a/libcaf_core/caf/actor_ostream.hpp +++ b/libcaf_core/caf/actor_ostream.hpp @@ -60,11 +60,11 @@ class actor_ostream { actor_ostream& flush(); /// Redirects all further output from `self` to `file_name`. - static void redirect(abstract_actor* self, std::string file_name, int flags = 0); + static void redirect(abstract_actor* self, std::string fn, int flags = 0); /// Redirects all further output from any actor that did not /// redirect its output to `fname`. - static void redirect_all(actor_system& sys, std::string fname, int flags = 0); + static void redirect_all(actor_system& sys, std::string fn, int flags = 0); /// Writes `arg` to the buffer allocated for the calling actor. inline actor_ostream& operator<<(const char* arg) { diff --git a/libcaf_core/caf/actor_pool.hpp b/libcaf_core/caf/actor_pool.hpp index e1660aa4cd..8314622303 100644 --- a/libcaf_core/caf/actor_pool.hpp +++ b/libcaf_core/caf/actor_pool.hpp @@ -90,16 +90,16 @@ class actor_pool : public monitorable_actor { return impl{std::move(init), std::move(sf), std::move(jf)}; } - ~actor_pool(); + ~actor_pool() override; /// Returns an actor pool without workers using the dispatch policy `pol`. - static actor make(execution_unit* ptr, policy pol); + static actor make(execution_unit* eu, policy pol); /// Returns an actor pool with `n` workers created by the factory /// function `fac` using the dispatch policy `pol`. - static actor make(execution_unit* ptr, size_t n, factory fac, policy pol); + static actor make(execution_unit* eu, size_t num_workers, const factory& fac, policy pol); - void enqueue(mailbox_element_ptr what, execution_unit* host) override; + void enqueue(mailbox_element_ptr what, execution_unit* eu) override; actor_pool(actor_config& cfg); @@ -109,7 +109,7 @@ class actor_pool : public monitorable_actor { private: bool filter(upgrade_lock&, const strong_actor_ptr& sender, message_id mid, - message_view& content, execution_unit* host); + message_view& mv, execution_unit* eu); // call without workers_mtx_ held void quit(execution_unit* host); diff --git a/libcaf_core/caf/actor_proxy.hpp b/libcaf_core/caf/actor_proxy.hpp index e4194522c6..a5ba9388c9 100644 --- a/libcaf_core/caf/actor_proxy.hpp +++ b/libcaf_core/caf/actor_proxy.hpp @@ -36,7 +36,7 @@ class actor_proxy : public monitorable_actor { public: explicit actor_proxy(actor_config& cfg); - ~actor_proxy(); + ~actor_proxy() override; /// Establishes a local link state that's /// not synchronized back to the remote instance. diff --git a/libcaf_core/caf/actor_registry.hpp b/libcaf_core/caf/actor_registry.hpp index 542163922e..2d1e63b3ca 100644 --- a/libcaf_core/caf/actor_registry.hpp +++ b/libcaf_core/caf/actor_registry.hpp @@ -52,7 +52,7 @@ class actor_registry { strong_actor_ptr get(actor_id key) const; /// Associates a local actor with its ID. - void put(actor_id key, strong_actor_ptr value); + void put(actor_id key, strong_actor_ptr val); /// Removes an actor from this registry, /// leaving `reason` for future reference. diff --git a/libcaf_core/caf/actor_system.hpp b/libcaf_core/caf/actor_system.hpp index 9d50830413..2449ceba3b 100644 --- a/libcaf_core/caf/actor_system.hpp +++ b/libcaf_core/caf/actor_system.hpp @@ -65,7 +65,7 @@ struct mpi_field_access { if (nr != 0) return *types.portable_name(nr, nullptr); auto ptr = types.portable_name(0, &typeid(T)); - if (ptr) + if (ptr != nullptr) return *ptr; std::string result = "; - config_option(const char* category, const char* name, const char* explanation); + config_option(const char* cat, const char* nm, const char* expl); virtual ~config_option(); @@ -141,8 +141,8 @@ class config_option { return true; } - void report_type_error(size_t line, config_value& x, const char* expected, - optional errors); + void report_type_error(size_t ln, config_value& x, const char* expected, + optional out); private: const char* category_; diff --git a/libcaf_core/caf/decorator/sequencer.hpp b/libcaf_core/caf/decorator/sequencer.hpp index cdc7c3a378..948cb7045a 100644 --- a/libcaf_core/caf/decorator/sequencer.hpp +++ b/libcaf_core/caf/decorator/sequencer.hpp @@ -44,7 +44,7 @@ class sequencer : public monitorable_actor { // non-system messages are processed and then forwarded; // system messages are handled and consumed on the spot; // in either case, the processing is done synchronously - void enqueue(mailbox_element_ptr what, execution_unit* host) override; + void enqueue(mailbox_element_ptr what, execution_unit* context) override; message_types_set message_types() const override; diff --git a/libcaf_core/caf/decorator/splitter.hpp b/libcaf_core/caf/decorator/splitter.hpp index 346d7c4353..c23d9a9162 100644 --- a/libcaf_core/caf/decorator/splitter.hpp +++ b/libcaf_core/caf/decorator/splitter.hpp @@ -45,7 +45,7 @@ class splitter : public monitorable_actor { // non-system messages are processed and then forwarded; // system messages are handled and consumed on the spot; // in either case, the processing is done synchronously - void enqueue(mailbox_element_ptr what, execution_unit* host) override; + void enqueue(mailbox_element_ptr what, execution_unit* context) override; message_types_set message_types() const override; diff --git a/libcaf_core/caf/default_attachable.hpp b/libcaf_core/caf/default_attachable.hpp index 1dc8ab85dd..e380486bb6 100644 --- a/libcaf_core/caf/default_attachable.hpp +++ b/libcaf_core/caf/default_attachable.hpp @@ -38,7 +38,7 @@ class default_attachable : public attachable { static constexpr size_t token_type = attachable::token::observer; }; - void actor_exited(const error& fail_state, execution_unit* host) override; + void actor_exited(const error& rsn, execution_unit* host) override; bool matches(const token& what) override; @@ -72,7 +72,7 @@ class default_attachable : public attachable { }; private: - default_attachable(actor_addr observed, actor_addr observer, observe_type ot); + default_attachable(actor_addr observed, actor_addr observer, observe_type type); actor_addr observed_; actor_addr observer_; observe_type type_; diff --git a/libcaf_core/caf/deserializer.hpp b/libcaf_core/caf/deserializer.hpp index 14403b9ddf..76fea37b4b 100644 --- a/libcaf_core/caf/deserializer.hpp +++ b/libcaf_core/caf/deserializer.hpp @@ -40,7 +40,7 @@ namespace caf { /// Technology-independent deserialization interface. class deserializer : public data_processor { public: - ~deserializer(); + ~deserializer() override; using super = data_processor; @@ -51,9 +51,9 @@ class deserializer : public data_processor { using is_saving = std::false_type; using is_loading = std::true_type; - explicit deserializer(actor_system& sys); + explicit deserializer(actor_system& x); - explicit deserializer(execution_unit* ctx = nullptr); + explicit deserializer(execution_unit* x = nullptr); }; #ifndef CAF_NO_EXCEPTIONS diff --git a/libcaf_core/caf/detail/behavior_impl.hpp b/libcaf_core/caf/detail/behavior_impl.hpp index febef6fa70..b1a1a49ce5 100644 --- a/libcaf_core/caf/detail/behavior_impl.hpp +++ b/libcaf_core/caf/detail/behavior_impl.hpp @@ -58,7 +58,7 @@ class behavior_impl : public ref_counted { public: using pointer = intrusive_ptr; - ~behavior_impl(); + ~behavior_impl() override; behavior_impl(duration tout = duration{}); diff --git a/libcaf_core/caf/detail/blocking_behavior.hpp b/libcaf_core/caf/detail/blocking_behavior.hpp index 648517be48..4ec3ef9a7c 100644 --- a/libcaf_core/caf/detail/blocking_behavior.hpp +++ b/libcaf_core/caf/detail/blocking_behavior.hpp @@ -31,7 +31,7 @@ class blocking_behavior { public: behavior& nested; - blocking_behavior(behavior& nested); + blocking_behavior(behavior& x); blocking_behavior(blocking_behavior&&) = default; virtual ~blocking_behavior(); diff --git a/libcaf_core/caf/detail/default_invoke_result_visitor.hpp b/libcaf_core/caf/detail/default_invoke_result_visitor.hpp index 06f8ddd83c..a5986d0596 100644 --- a/libcaf_core/caf/detail/default_invoke_result_visitor.hpp +++ b/libcaf_core/caf/detail/default_invoke_result_visitor.hpp @@ -34,7 +34,7 @@ class default_invoke_result_visitor : public invoke_result_visitor { // nop } - ~default_invoke_result_visitor() { + ~default_invoke_result_visitor() override { // nop } diff --git a/libcaf_core/caf/detail/double_ended_queue.hpp b/libcaf_core/caf/detail/double_ended_queue.hpp index 9c8f444aa0..eeff4e5b40 100644 --- a/libcaf_core/caf/detail/double_ended_queue.hpp +++ b/libcaf_core/caf/detail/double_ended_queue.hpp @@ -126,7 +126,7 @@ class double_ended_queue { // acquires only one lock void append(pointer value) { CAF_ASSERT(value != nullptr); - node* tmp = new node(value); + auto* tmp = new node(value); lock_guard guard(tail_lock_); // publish & swing last forward tail_.load()->next = tmp; @@ -136,7 +136,7 @@ class double_ended_queue { // acquires both locks void prepend(pointer value) { CAF_ASSERT(value != nullptr); - node* tmp = new node(value); + auto* tmp = new node(value); node* first = nullptr; // acquire both locks since we might touch last_ too lock_guard guard1(head_lock_); diff --git a/libcaf_core/caf/detail/dynamic_message_data.hpp b/libcaf_core/caf/detail/dynamic_message_data.hpp index 7e9d6338f9..f59cd44324 100644 --- a/libcaf_core/caf/detail/dynamic_message_data.hpp +++ b/libcaf_core/caf/detail/dynamic_message_data.hpp @@ -43,7 +43,7 @@ class dynamic_message_data : public message_data { dynamic_message_data(const dynamic_message_data& other); - ~dynamic_message_data(); + ~dynamic_message_data() override; // -- overridden observers of message_data ----------------------------------- diff --git a/libcaf_core/caf/detail/limited_vector.hpp b/libcaf_core/caf/detail/limited_vector.hpp index 9b7f234b84..5430ae41b9 100644 --- a/libcaf_core/caf/detail/limited_vector.hpp +++ b/libcaf_core/caf/detail/limited_vector.hpp @@ -86,7 +86,7 @@ class limited_vector { template void assign(InputIterator first, InputIterator last, // dummy SFINAE argument - typename std::iterator_traits::pointer = 0) { + typename std::iterator_traits::pointer = nullptr) { auto dist = std::distance(first, last); CAF_ASSERT(dist >= 0); resize(static_cast(dist)); diff --git a/libcaf_core/caf/detail/memory.hpp b/libcaf_core/caf/detail/memory.hpp index 2eb32236c6..481dd99fbe 100644 --- a/libcaf_core/caf/detail/memory.hpp +++ b/libcaf_core/caf/detail/memory.hpp @@ -108,7 +108,7 @@ class basic_memory_cache : public memory_cache { // nop } - ~storage() { + ~storage() override { // nop } diff --git a/libcaf_core/caf/detail/message_data.hpp b/libcaf_core/caf/detail/message_data.hpp index d815717f35..3aca4472d6 100644 --- a/libcaf_core/caf/detail/message_data.hpp +++ b/libcaf_core/caf/detail/message_data.hpp @@ -47,7 +47,7 @@ class message_data : public ref_counted, public type_erased_tuple { message_data() = default; message_data(const message_data&) = default; - ~message_data(); + ~message_data() override; // -- pure virtual observers ------------------------------------------------- @@ -119,7 +119,7 @@ class message_data::cow_ptr { } inline const message_data& operator*() const noexcept { - return *ptr_.get(); + return *ptr_; } inline explicit operator bool() const noexcept { diff --git a/libcaf_core/caf/detail/parse_ini.hpp b/libcaf_core/caf/detail/parse_ini.hpp index 94c3775c06..6bce025f77 100644 --- a/libcaf_core/caf/detail/parse_ini.hpp +++ b/libcaf_core/caf/detail/parse_ini.hpp @@ -44,8 +44,8 @@ struct parse_ini_t { /// @param raw_data Input stream of INI formatted text. /// @param errors Output stream for parser errors. /// @param consumer Callback consuming generated key-value pairs. - void operator()(std::istream& raw_data, - config_consumer consumer, + void operator()(std::istream& input, + const config_consumer& consumer_fun, opt_err errors = none) const; }; diff --git a/libcaf_core/caf/detail/split_join.hpp b/libcaf_core/caf/detail/split_join.hpp index 47edf14d69..2136b761a5 100644 --- a/libcaf_core/caf/detail/split_join.hpp +++ b/libcaf_core/caf/detail/split_join.hpp @@ -111,8 +111,8 @@ class split_join { return; actor_msg_vec xs; xs.reserve(workers.size()); - for (size_t i = 0; i < workers.size(); ++i) - xs.emplace_back(workers[i], message{}); + for (const auto & worker : workers) + xs.emplace_back(worker, message{}); ulock.unlock(); using collector_t = split_join_collector; auto hdl = sys.spawn(init_, sf_, jf_, std::move(xs)); diff --git a/libcaf_core/caf/detail/try_match.hpp b/libcaf_core/caf/detail/try_match.hpp index 50ac7f1f88..8dacfe7747 100644 --- a/libcaf_core/caf/detail/try_match.hpp +++ b/libcaf_core/caf/detail/try_match.hpp @@ -75,8 +75,8 @@ struct meta_elements> { } }; -bool try_match(const type_erased_tuple& xs, const meta_element* pattern_begin, - size_t pattern_size); +bool try_match(const type_erased_tuple& xs, const meta_element* iter, + size_t ps); } // namespace detail } // namespace caf diff --git a/libcaf_core/caf/detail/type_traits.hpp b/libcaf_core/caf/detail/type_traits.hpp index 64a3a1ff2a..4c890e32e4 100644 --- a/libcaf_core/caf/detail/type_traits.hpp +++ b/libcaf_core/caf/detail/type_traits.hpp @@ -202,13 +202,13 @@ class is_forward_iterator { template static bool sfinae(C& x, C& y, // check for operator* - decay_t* = 0, + decay_t* = nullptr, // check for operator++ returning an iterator - decay_t* = 0, + decay_t* = nullptr, // check for operator== - decay_t* = 0, + decay_t* = nullptr, // check for operator!= - decay_t* = 0); + decay_t* = nullptr); static void sfinae(...); @@ -226,9 +226,9 @@ class is_iterable { template static bool sfinae(C* cc, // check if 'C::begin()' returns a forward iterator - enable_if_ttbegin())>>* = 0, + enable_if_ttbegin())>>* = nullptr, // check if begin() and end() both exist and are comparable - decltype(cc->begin() != cc->end())* = 0); + decltype(cc->begin() != cc->end())* = nullptr); // SFNINAE default static void sfinae(void*); @@ -271,7 +271,7 @@ template ::value> struct has_serialize { template - static auto test_serialize(caf::serializer* sink, U* x, const unsigned int y = 0) + static auto test_serialize(caf::serializer* sink, U* x, unsigned int y = 0) -> decltype(serialize(*sink, *x, y)); template @@ -282,7 +282,7 @@ struct has_serialize { static auto test_serialize(...) -> std::false_type; template - static auto test_deserialize(caf::deserializer* source, U* x, const unsigned int y = 0) + static auto test_deserialize(caf::deserializer* source, U* x, unsigned int y = 0) -> decltype(serialize(*source, *x, y)); template diff --git a/libcaf_core/caf/error.hpp b/libcaf_core/caf/error.hpp index 7c85933451..368cfea859 100644 --- a/libcaf_core/caf/error.hpp +++ b/libcaf_core/caf/error.hpp @@ -111,8 +111,8 @@ class error : detail::comparable { error(const error&); error& operator=(const error&); - error(uint8_t code, atom_value category); - error(uint8_t code, atom_value category, message msg); + error(uint8_t x, atom_value y); + error(uint8_t x, atom_value y, message z); template > error(E error_value) : error(make_error(error_value)) { @@ -154,7 +154,7 @@ class error : detail::comparable { int compare(const error&) const noexcept; - int compare(uint8_t code, atom_value category) const noexcept; + int compare(uint8_t x, atom_value y) const noexcept; // -- modifiers -------------------------------------------------------------- @@ -195,7 +195,7 @@ class error : detail::comparable { private: // -- inspection support ----------------------------------------------------- - error apply(inspect_fun f); + error apply(const inspect_fun& f); // -- nested classes --------------------------------------------------------- diff --git a/libcaf_core/caf/event_based_actor.hpp b/libcaf_core/caf/event_based_actor.hpp index c06563bbbd..dab2fd2abf 100644 --- a/libcaf_core/caf/event_based_actor.hpp +++ b/libcaf_core/caf/event_based_actor.hpp @@ -67,7 +67,7 @@ class event_based_actor : public extend expected(U x, - typename std::enable_if::value>::type* = 0) + typename std::enable_if::value>::type* = nullptr) : engaged_(true) { new (&value_) T(std::move(x)); } @@ -380,10 +380,7 @@ class expected { // nop } - expected& operator=(const expected& other) noexcept { - error_ = other.error_; - return *this; - } + expected& operator=(const expected& other) = default; expected& operator=(expected&& other) noexcept { error_ = std::move(other.error_); diff --git a/libcaf_core/caf/forwarding_actor_proxy.hpp b/libcaf_core/caf/forwarding_actor_proxy.hpp index 55d11a672c..3d40bbaaee 100644 --- a/libcaf_core/caf/forwarding_actor_proxy.hpp +++ b/libcaf_core/caf/forwarding_actor_proxy.hpp @@ -32,9 +32,9 @@ class forwarding_actor_proxy : public actor_proxy { public: using forwarding_stack = std::vector; - forwarding_actor_proxy(actor_config& cfg, actor parent); + forwarding_actor_proxy(actor_config& cfg, actor mgr); - ~forwarding_actor_proxy(); + ~forwarding_actor_proxy() override; void enqueue(mailbox_element_ptr what, execution_unit* host) override; @@ -44,7 +44,7 @@ class forwarding_actor_proxy : public actor_proxy { void local_unlink_from(abstract_actor* other) override; - void kill_proxy(execution_unit* ctx, error reason) override; + void kill_proxy(execution_unit* ctx, error rsn) override; actor manager() const; @@ -52,7 +52,7 @@ class forwarding_actor_proxy : public actor_proxy { private: void forward_msg(strong_actor_ptr sender, message_id mid, message msg, - const forwarding_stack* fwd_stack = nullptr); + const forwarding_stack* fwd = nullptr); mutable detail::shared_spinlock manager_mtx_; actor manager_; diff --git a/libcaf_core/caf/function_view.hpp b/libcaf_core/caf/function_view.hpp index d4193ee8e3..410f450be8 100644 --- a/libcaf_core/caf/function_view.hpp +++ b/libcaf_core/caf/function_view.hpp @@ -22,6 +22,7 @@ #include #include +#include #include "caf/expected.hpp" #include "caf/typed_actor.hpp" @@ -139,9 +140,9 @@ class function_view { // nop } - function_view(const type& impl, duration rel_timeout = infinite) + function_view(type impl, duration rel_timeout = infinite) : timeout(rel_timeout), - impl_(impl) { + impl_(std::move(impl)) { new_self(impl_); } diff --git a/libcaf_core/caf/group.hpp b/libcaf_core/caf/group.hpp index 388625fec6..acc168e9d3 100644 --- a/libcaf_core/caf/group.hpp +++ b/libcaf_core/caf/group.hpp @@ -36,7 +36,7 @@ namespace caf { struct invalid_group_t { - constexpr invalid_group_t() {} + constexpr invalid_group_t() = default; }; /// Identifies an invalid {@link group}. @@ -67,7 +67,7 @@ class group : detail::comparable, group(abstract_group*); - group(intrusive_ptr ptr); + group(intrusive_ptr gptr); inline explicit operator bool() const noexcept { return static_cast(ptr_); diff --git a/libcaf_core/caf/group_manager.hpp b/libcaf_core/caf/group_manager.hpp index 46fea77a30..3964e0c7fb 100644 --- a/libcaf_core/caf/group_manager.hpp +++ b/libcaf_core/caf/group_manager.hpp @@ -65,7 +65,7 @@ class group_manager { /// Get a pointer to the group associated with /// `identifier` from the module `local`. /// @threadsafe - group get_local(const std::string& identifier) const; + group get_local(const std::string& group_identifier) const; /// Returns an anonymous group. /// Each calls to this member function returns a new instance @@ -74,7 +74,7 @@ class group_manager { group anonymous() const; /// Returns the module named `name` if it exists, otherwise `none`. - optional get_module(const std::string& name) const; + optional get_module(const std::string& x) const; private: // -- constructors, destructors, and assignment operators -------------------- diff --git a/libcaf_core/caf/group_module.hpp b/libcaf_core/caf/group_module.hpp index 3fea15ef59..bfcb9c4d1c 100644 --- a/libcaf_core/caf/group_module.hpp +++ b/libcaf_core/caf/group_module.hpp @@ -36,7 +36,7 @@ class group_module { public: // -- constructors, destructors, and assignment operators -------------------- - group_module(actor_system& sys, std::string module_name); + group_module(actor_system& sys, std::string mname); virtual ~group_module(); diff --git a/libcaf_core/caf/local_actor.hpp b/libcaf_core/caf/local_actor.hpp index 2ab4eef2a1..8ef0977c3c 100644 --- a/libcaf_core/caf/local_actor.hpp +++ b/libcaf_core/caf/local_actor.hpp @@ -99,9 +99,9 @@ class local_actor : public monitorable_actor { // -- constructors, destructors, and assignment operators -------------------- - local_actor(actor_config& sys); + local_actor(actor_config& cfg); - ~local_actor(); + ~local_actor() override; void on_destroy() override; @@ -113,7 +113,7 @@ class local_actor : public monitorable_actor { /// Requests a new timeout for `mid`. /// @pre `mid.valid()` - void request_response_timeout(const duration& dr, message_id mid); + void request_response_timeout(const duration& d, message_id mid); // -- spawn functions -------------------------------------------------------- @@ -178,7 +178,7 @@ class local_actor : public monitorable_actor { // -- sending asynchronous messages ------------------------------------------ /// Sends an exit message to `dest`. - void send_exit(const actor_addr& dest, error reason); + void send_exit(const actor_addr& whom, error reason); void send_exit(const strong_actor_ptr& dest, error reason); @@ -209,7 +209,7 @@ class local_actor : public monitorable_actor { /// @cond PRIVATE - void monitor(abstract_actor* whom); + void monitor(abstract_actor* ptr); /// @endcond @@ -283,12 +283,12 @@ class local_actor : public monitorable_actor { /// Serializes the state of this actor to `sink`. This function is /// only called if this actor has set the `is_serializable` flag. /// The default implementation throws a `std::logic_error`. - virtual error save_state(serializer& sink, const unsigned int version); + virtual error save_state(serializer& sink, unsigned int version); /// Deserializes the state of this actor from `source`. This function is /// only called if this actor has set the `is_serializable` flag. /// The default implementation throws a `std::logic_error`. - virtual error load_state(deserializer& source, const unsigned int version); + virtual error load_state(deserializer& source, unsigned int version); /// Returns the currently defined fail state. If this reason is not /// `none` then the actor will terminate with this error after executing @@ -349,7 +349,7 @@ class local_actor : public monitorable_actor { virtual void initialize(); - bool cleanup(error&& reason, execution_unit* host) override; + bool cleanup(error&& fail_state, execution_unit* host) override; message_id new_request_id(message_priority mp); @@ -363,7 +363,7 @@ class local_actor : public monitorable_actor { bool has_next_message(); /// Appends `x` to the cache for later consumption. - void push_to_cache(mailbox_element_ptr x); + void push_to_cache(mailbox_element_ptr ptr); protected: // -- member variables ------------------------------------------------------- diff --git a/libcaf_core/caf/logger.hpp b/libcaf_core/caf/logger.hpp index 7bd35c4277..50a663c7d5 100644 --- a/libcaf_core/caf/logger.hpp +++ b/libcaf_core/caf/logger.hpp @@ -141,10 +141,10 @@ class logger : public ref_counted { /// Writes an entry to the log file. void log(int level, const char* component, const std::string& class_name, - const char* function_name, const char* file_name, + const char* function_name, const char* c_full_file_name, int line_num, const std::string& msg); - ~logger(); + ~logger() override; /** @cond PRIVATE */ @@ -173,7 +173,7 @@ class logger : public ref_counted { void log_prefix(std::ostream& out, int level, const char* component, const std::string& class_name, const char* function_name, - const char* file_name, int line_num, + const char* c_full_file_name, int line_num, const std::thread::id& tid = std::this_thread::get_id()); actor_system& system_; diff --git a/libcaf_core/caf/mailbox_element.hpp b/libcaf_core/caf/mailbox_element.hpp index c76cdbd805..043080b141 100644 --- a/libcaf_core/caf/mailbox_element.hpp +++ b/libcaf_core/caf/mailbox_element.hpp @@ -66,10 +66,10 @@ class mailbox_element : public memory_managed, public message_view { mailbox_element(); - mailbox_element(strong_actor_ptr&& sender, message_id id, - forwarding_stack&& stages); + mailbox_element(strong_actor_ptr&& x, message_id y, + forwarding_stack&& z); - virtual ~mailbox_element(); + ~mailbox_element() override; type_erased_tuple& content() override; @@ -111,11 +111,11 @@ class mailbox_element_vals // nop } - type_erased_tuple& content() { + type_erased_tuple& content() override { return *this; } - message move_content_to_message() { + message move_content_to_message() override { message_factory f; auto& xs = this->data(); return detail::apply_moved_args(f, detail::get_indices(xs), xs); diff --git a/libcaf_core/caf/match_case.hpp b/libcaf_core/caf/match_case.hpp index 691d73c65a..5fbc3a76ea 100644 --- a/libcaf_core/caf/match_case.hpp +++ b/libcaf_core/caf/match_case.hpp @@ -47,7 +47,7 @@ class match_case { skip }; - match_case(uint32_t token); + match_case(uint32_t tt); match_case(match_case&&) = default; match_case(const match_case&) = default; diff --git a/libcaf_core/caf/message.hpp b/libcaf_core/caf/message.hpp index c624152bfe..eb57b09e7a 100644 --- a/libcaf_core/caf/message.hpp +++ b/libcaf_core/caf/message.hpp @@ -73,7 +73,7 @@ class message { message(message&&) noexcept; message& operator=(message&&) noexcept; - explicit message(const data_ptr& vals) noexcept; + explicit message(data_ptr ptr) noexcept; ~message(); @@ -133,7 +133,7 @@ class message { message drop_right(size_t n) const; /// Creates a new message of size `n` starting at the element at position `p`. - message slice(size_t p, size_t n) const; + message slice(size_t pos, size_t n) const; /// Filters this message by applying slices of it to `handler` and returns /// the remaining elements of this operation. Slices are generated in the @@ -206,8 +206,8 @@ class message { /// used arguments, and the generated help text. /// @throws std::invalid_argument if no name or more than one long name is set cli_res extract_opts(std::vector xs, - help_factory help_generator = nullptr, - bool suppress_help = false) const; + const help_factory& f = nullptr, + bool no_help = false) const; // -- inline observers ------------------------------------------------------- @@ -328,7 +328,7 @@ class message { message extract_impl(size_t start, message_handler handler) const; - static message concat_impl(std::initializer_list ptrs); + static message concat_impl(std::initializer_list xs); data_ptr vals_; }; @@ -337,7 +337,7 @@ class message { error inspect(serializer& sink, message& msg); /// @relates message -error inspect(deserializer& sink, message& msg); +error inspect(deserializer& source, message& msg); /// @relates message std::string to_string(const message& msg); @@ -364,23 +364,23 @@ struct message::cli_arg { bool* flag; /// Creates a CLI argument without data. - cli_arg(std::string name, std::string text); + cli_arg(std::string nstr, std::string tstr); /// Creates a CLI flag option. The `flag` is set to `true` if the option /// was set, otherwise it is `false`. - cli_arg(std::string name, std::string text, bool& flag); + cli_arg(std::string nstr, std::string tstr, bool& arg); /// Creates a CLI argument storing its matched argument in `dest`. - cli_arg(std::string name, std::string text, atom_value& dest); + cli_arg(std::string nstr, std::string tstr, atom_value& arg); /// Creates a CLI argument storing its matched argument in `dest`. - cli_arg(std::string name, std::string text, std::string& dest); + cli_arg(std::string nstr, std::string tstr, std::string& arg); /// Creates a CLI argument appending matched arguments to `dest`. - cli_arg(std::string name, std::string text, std::vector& dest); + cli_arg(std::string nstr, std::string tstr, std::vector& arg); /// Creates a CLI argument using the function object `f`. - cli_arg(std::string name, std::string text, consumer f); + cli_arg(std::string nstr, std::string tstr, consumer f); /// Creates a CLI argument for converting from strings, /// storing its matched argument in `dest`. diff --git a/libcaf_core/caf/message_builder.hpp b/libcaf_core/caf/message_builder.hpp index 703a863f7f..fb9aa8501a 100644 --- a/libcaf_core/caf/message_builder.hpp +++ b/libcaf_core/caf/message_builder.hpp @@ -89,7 +89,7 @@ class message_builder { /// @copydoc message::extract inline message extract(message_handler f) const { - return to_message().extract(f); + return to_message().extract(std::move(f)); } /// @copydoc message::extract_opts diff --git a/libcaf_core/caf/message_handler.hpp b/libcaf_core/caf/message_handler.hpp index 2c80a4c774..d39446b95c 100644 --- a/libcaf_core/caf/message_handler.hpp +++ b/libcaf_core/caf/message_handler.hpp @@ -86,7 +86,7 @@ class message_handler { } /// Equal to `*this = other`. - void assign(message_handler other); + void assign(message_handler what); /// Runs this handler and returns its (optional) result. inline optional operator()(message& arg) { diff --git a/libcaf_core/caf/monitorable_actor.hpp b/libcaf_core/caf/monitorable_actor.hpp index 52a3307a4c..8111b61867 100644 --- a/libcaf_core/caf/monitorable_actor.hpp +++ b/libcaf_core/caf/monitorable_actor.hpp @@ -115,15 +115,15 @@ class monitorable_actor : public abstract_actor { * here be dragons: end of public interface * ****************************************************************************/ - bool link_impl(linking_operation op, abstract_actor* x) override; + bool link_impl(linking_operation op, abstract_actor* other) override; - bool establish_link_impl(abstract_actor* other); + bool establish_link_impl(abstract_actor* x); - bool remove_link_impl(abstract_actor* other); + bool remove_link_impl(abstract_actor* x); - bool establish_backlink_impl(abstract_actor* other); + bool establish_backlink_impl(abstract_actor* x); - bool remove_backlink_impl(abstract_actor* other); + bool remove_backlink_impl(abstract_actor* x); // precondition: `mtx_` is acquired inline void attach_impl(attachable_ptr& ptr) { @@ -134,12 +134,12 @@ class monitorable_actor : public abstract_actor { // precondition: `mtx_` is acquired static size_t detach_impl(const attachable::token& what, attachable_ptr& ptr, - bool stop_on_first_hit = false, + bool stop_on_hit = false, bool dry_run = false); // handles only `exit_msg` and `sys_atom` messages; // returns true if the message is handled - bool handle_system_message(mailbox_element& node, execution_unit* context, + bool handle_system_message(mailbox_element& x, execution_unit* ctx, bool trap_exit); // handles `exit_msg`, `sys_atom` messages, and additionally `down_msg` diff --git a/libcaf_core/caf/named_actor_config.hpp b/libcaf_core/caf/named_actor_config.hpp index e4bd687df7..6060852795 100644 --- a/libcaf_core/caf/named_actor_config.hpp +++ b/libcaf_core/caf/named_actor_config.hpp @@ -35,7 +35,7 @@ struct named_actor_config { }; template -void serialize(Processor& proc, named_actor_config& x, const unsigned int) { +void serialize(Processor& proc, named_actor_config& x, unsigned int) { proc & x.strategy; proc & x.low_watermark; proc & x.max_pending; diff --git a/libcaf_core/caf/node_id.hpp b/libcaf_core/caf/node_id.hpp index 8af9aaddce..84005f98f4 100644 --- a/libcaf_core/caf/node_id.hpp +++ b/libcaf_core/caf/node_id.hpp @@ -71,12 +71,12 @@ class node_id { /// Creates a node ID from `process_id` and `hash`. /// @param process_id System-wide unique process identifier. /// @param hash Unique node id as hexadecimal string representation. - node_id(uint32_t process_id, const std::string& hash); + node_id(uint32_t procid, const std::string& hash); /// Creates a node ID from `process_id` and `hash`. /// @param process_id System-wide unique process identifier. /// @param node_id Unique node id. - node_id(uint32_t process_id, const host_id_type& node_id); + node_id(uint32_t procid, const host_id_type& hid); /// Identifies the running process. /// @returns A system-wide unique process identifier. @@ -101,7 +101,7 @@ class node_id { int compare(const node_id& other) const; - ~data(); + ~data() override; data(); diff --git a/libcaf_core/caf/policy/profiled.hpp b/libcaf_core/caf/policy/profiled.hpp index 7e0756cb50..e8a4642a89 100644 --- a/libcaf_core/caf/policy/profiled.hpp +++ b/libcaf_core/caf/policy/profiled.hpp @@ -43,7 +43,7 @@ struct profiled : Policy { static actor_id id_of(resumable* job) { auto ptr = dynamic_cast(job); - return ptr ? ptr->id() : 0; + return ptr != nullptr ? ptr->id() : 0; } template diff --git a/libcaf_core/caf/policy/work_sharing.hpp b/libcaf_core/caf/policy/work_sharing.hpp index 40281b0a28..0bcf3cf13d 100644 --- a/libcaf_core/caf/policy/work_sharing.hpp +++ b/libcaf_core/caf/policy/work_sharing.hpp @@ -38,7 +38,7 @@ class work_sharing : public unprofiled { // A thread-safe queue implementation. using queue_type = std::list; - ~work_sharing(); + ~work_sharing() override; struct coordinator_data { inline explicit coordinator_data(scheduler::abstract_coordinator*) { diff --git a/libcaf_core/caf/policy/work_stealing.hpp b/libcaf_core/caf/policy/work_stealing.hpp index 56dff2332f..2c61eaeedb 100644 --- a/libcaf_core/caf/policy/work_stealing.hpp +++ b/libcaf_core/caf/policy/work_stealing.hpp @@ -40,7 +40,7 @@ namespace policy { /// @extends scheduler_policy class work_stealing : public unprofiled { public: - ~work_stealing(); + ~work_stealing() override; // A thread-safe queue implementation. using queue_type = detail::double_ended_queue; diff --git a/libcaf_core/caf/proxy_registry.hpp b/libcaf_core/caf/proxy_registry.hpp index 54dccf3b27..f60bf4a6d2 100644 --- a/libcaf_core/caf/proxy_registry.hpp +++ b/libcaf_core/caf/proxy_registry.hpp @@ -50,7 +50,7 @@ class proxy_registry { virtual execution_unit* registry_context() = 0; }; - proxy_registry(actor_system& sys, backend& mgm); + proxy_registry(actor_system& sys, backend& be); proxy_registry(const proxy_registry&) = delete; proxy_registry& operator=(const proxy_registry&) = delete; @@ -80,16 +80,16 @@ class proxy_registry { /// Returns the proxy instance identified by `node` and `aid` /// or creates a new (default) proxy instance. - strong_actor_ptr get_or_put(const key_type& node, actor_id aid); + strong_actor_ptr get_or_put(const key_type& nid, actor_id aid); /// Returns all known proxies. std::vector get_all(const key_type& node); /// Deletes all proxies for `node`. - void erase(const key_type& node); + void erase(const key_type& nid); /// Deletes the proxy with id `aid` for `node`. - void erase(const key_type& node, actor_id aid, + void erase(const key_type& inf, actor_id aid, error rsn = exit_reason::remote_link_unreachable); /// Queries whether there are any proxies left. diff --git a/libcaf_core/caf/ref_counted.hpp b/libcaf_core/caf/ref_counted.hpp index 32ee9319d9..2317e48b9f 100644 --- a/libcaf_core/caf/ref_counted.hpp +++ b/libcaf_core/caf/ref_counted.hpp @@ -33,7 +33,7 @@ namespace caf { /// @relates intrusive_ptr class ref_counted : public memory_managed { public: - ~ref_counted(); + ~ref_counted() override; ref_counted(); ref_counted(const ref_counted&); diff --git a/libcaf_core/caf/response_promise.hpp b/libcaf_core/caf/response_promise.hpp index c67ba078da..f362fb2e61 100644 --- a/libcaf_core/caf/response_promise.hpp +++ b/libcaf_core/caf/response_promise.hpp @@ -114,7 +114,7 @@ class response_promise { } private: - response_promise deliver_impl(message response_message); + response_promise deliver_impl(message msg); execution_unit* ctx_; strong_actor_ptr self_; diff --git a/libcaf_core/caf/scheduled_actor.hpp b/libcaf_core/caf/scheduled_actor.hpp index c8502b4565..f3c2af423f 100644 --- a/libcaf_core/caf/scheduled_actor.hpp +++ b/libcaf_core/caf/scheduled_actor.hpp @@ -140,7 +140,7 @@ class scheduled_actor : public local_actor, public resumable { explicit scheduled_actor(actor_config& cfg); - ~scheduled_actor(); + ~scheduled_actor() override; // -- overridden functions of abstract_actor --------------------------------- @@ -191,7 +191,7 @@ class scheduled_actor : public local_actor, public resumable { /// @warning This member function throws immediately in thread-based actors /// that do not use the behavior stack, i.e., actors that use /// blocking API calls such as {@link receive()}. - void quit(error reason = error{}); + void quit(error x = error{}); // -- event handlers --------------------------------------------------------- @@ -296,7 +296,7 @@ class scheduled_actor : public local_actor, public resumable { void reset_timeout(uint32_t timeout_id); /// Returns whether `timeout_id` is currently active. - bool is_active_timeout(uint32_t timeout_id) const; + bool is_active_timeout(uint32_t tid) const; // -- message processing ----------------------------------------------------- diff --git a/libcaf_core/caf/scheduler/profiled_coordinator.hpp b/libcaf_core/caf/scheduler/profiled_coordinator.hpp index 77cec988a9..b2a6e103f8 100644 --- a/libcaf_core/caf/scheduler/profiled_coordinator.hpp +++ b/libcaf_core/caf/scheduler/profiled_coordinator.hpp @@ -183,9 +183,9 @@ class profiled_coordinator : public coordinator { super::init(cfg); file_.open(cfg.scheduler_profiling_output_file); if (!file_) - std::cerr << "[WARNING] could not open file \"" + std::cerr << R"([WARNING] could not open file ")" << cfg.scheduler_profiling_output_file - << "\" (no profiler output will be generated)" + << R"(" (no profiler output will be generated))" << std::endl; resolution_ = msec{cfg.scheduler_profiling_ms_resolution}; } diff --git a/libcaf_core/caf/scheduler/worker.hpp b/libcaf_core/caf/scheduler/worker.hpp index a745ff7d06..3c77514521 100644 --- a/libcaf_core/caf/scheduler/worker.hpp +++ b/libcaf_core/caf/scheduler/worker.hpp @@ -90,9 +90,9 @@ class worker : public execution_unit { } actor_id id_of(resumable* ptr) { - abstract_actor* dptr = ptr ? dynamic_cast(ptr) + abstract_actor* dptr = ptr != nullptr ? dynamic_cast(ptr) : nullptr; - return dptr ? dptr->id() : 0; + return dptr != nullptr ? dptr->id() : 0; } policy_data& data() { diff --git a/libcaf_core/caf/scoped_actor.hpp b/libcaf_core/caf/scoped_actor.hpp index df8f3f6e4a..1c777147f4 100644 --- a/libcaf_core/caf/scoped_actor.hpp +++ b/libcaf_core/caf/scoped_actor.hpp @@ -42,13 +42,13 @@ class scoped_actor { // tell actor_cast which semantic this type uses static constexpr bool has_weak_ptr_semantics = false; - scoped_actor(actor_system& sys, bool hide_actor = false); + scoped_actor(actor_system& sys, bool hide = false); scoped_actor(const scoped_actor&) = delete; scoped_actor& operator=(const scoped_actor&) = delete; - scoped_actor(scoped_actor&&) = default; - scoped_actor& operator=(scoped_actor&&) = default; + scoped_actor(scoped_actor&&) = delete; + scoped_actor& operator=(scoped_actor&&) = delete; ~scoped_actor(); diff --git a/libcaf_core/caf/serializer.hpp b/libcaf_core/caf/serializer.hpp index a701467208..001aa7a487 100644 --- a/libcaf_core/caf/serializer.hpp +++ b/libcaf_core/caf/serializer.hpp @@ -52,7 +52,7 @@ class serializer : public data_processor { explicit serializer(execution_unit* ctx = nullptr); - virtual ~serializer(); + ~serializer() override; }; #ifndef CAF_NO_EXCEPTIONS diff --git a/libcaf_core/caf/stateful_actor.hpp b/libcaf_core/caf/stateful_actor.hpp index d8bcabfcdd..2fc942f369 100644 --- a/libcaf_core/caf/stateful_actor.hpp +++ b/libcaf_core/caf/stateful_actor.hpp @@ -48,7 +48,7 @@ class stateful_actor : public Base { this->setf(Base::is_serializable_flag); } - ~stateful_actor() { + ~stateful_actor() override { // nop } @@ -63,11 +63,11 @@ class stateful_actor : public Base { return get_name(state_); } - error save_state(serializer& sink, const unsigned int version) override { + error save_state(serializer& sink, unsigned int version) override { return serialize_state(&sink, state, version); } - error load_state(deserializer& source, const unsigned int version) override { + error load_state(deserializer& source, unsigned int version) override { return serialize_state(&source, state, version); } @@ -85,13 +85,13 @@ class stateful_actor : public Base { private: template - auto serialize_state(Inspector* f, T& x, const unsigned int) + auto serialize_state(Inspector* f, T& x, unsigned int) -> decltype(inspect(*f, x)) { return inspect(*f, x); } template - error serialize_state(void*, T&, const unsigned int) { + error serialize_state(void*, T&, unsigned int) { return sec::invalid_argument; } diff --git a/libcaf_core/caf/type_erased_tuple.hpp b/libcaf_core/caf/type_erased_tuple.hpp index 73894dd56c..28599f2d93 100644 --- a/libcaf_core/caf/type_erased_tuple.hpp +++ b/libcaf_core/caf/type_erased_tuple.hpp @@ -104,7 +104,7 @@ class type_erased_tuple { /// Checks whether the type of the stored value at position `pos` /// matches type number `n` and run-time type information `p`. - bool matches(size_t pos, uint16_t n, const std::type_info* p) const noexcept; + bool matches(size_t pos, uint16_t nr, const std::type_info* ptr) const noexcept; // -- convenience functions -------------------------------------------------- @@ -236,7 +236,7 @@ class empty_type_erased_tuple : public type_erased_tuple { public: empty_type_erased_tuple() = default; - ~empty_type_erased_tuple(); + ~empty_type_erased_tuple() override; void* get_mutable(size_t pos) override; diff --git a/libcaf_core/caf/type_erased_value.hpp b/libcaf_core/caf/type_erased_value.hpp index a42a8087e7..ee1930bd14 100644 --- a/libcaf_core/caf/type_erased_value.hpp +++ b/libcaf_core/caf/type_erased_value.hpp @@ -70,7 +70,7 @@ class type_erased_value { /// Checks whether the type of the stored value matches /// the type nr and type info object. - bool matches(uint16_t tnr, const std::type_info* tinf) const; + bool matches(uint16_t nr, const std::type_info* ptr) const; // -- convenience functions -------------------------------------------------- diff --git a/libcaf_core/caf/uniform_type_info_map.hpp b/libcaf_core/caf/uniform_type_info_map.hpp index 2feac60c1c..6b2836e742 100644 --- a/libcaf_core/caf/uniform_type_info_map.hpp +++ b/libcaf_core/caf/uniform_type_info_map.hpp @@ -71,9 +71,9 @@ class uniform_type_info_map { type_erased_value_ptr make_value(uint16_t nr) const; - type_erased_value_ptr make_value(const std::string& uniform_name) const; + type_erased_value_ptr make_value(const std::string& x) const; - type_erased_value_ptr make_value(const std::type_info& ti) const; + type_erased_value_ptr make_value(const std::type_info& x) const; /// Returns the portable name for given type information or `nullptr` /// if no mapping was found. diff --git a/libcaf_core/caf/unit.hpp b/libcaf_core/caf/unit.hpp index ea9477ee71..8900ed7d69 100644 --- a/libcaf_core/caf/unit.hpp +++ b/libcaf_core/caf/unit.hpp @@ -57,7 +57,7 @@ static constexpr unit_t unit = unit_t{}; /// @relates unit_t template -void serialize(Processor&, const unit_t&, const unsigned int) { +void serialize(Processor&, const unit_t&, unsigned int) { // nop } diff --git a/libcaf_core/src/abstract_coordinator.cpp b/libcaf_core/src/abstract_coordinator.cpp index 9e6f33d79c..039e12b2e6 100644 --- a/libcaf_core/src/abstract_coordinator.cpp +++ b/libcaf_core/src/abstract_coordinator.cpp @@ -150,7 +150,7 @@ class sink_handle { } sink_handle(sink_cache* fc, iterator iter) : cache_(fc), iter_(iter) { - if (cache_) + if (cache_ != nullptr) ++iter_->second.first; } @@ -162,7 +162,7 @@ class sink_handle { if (cache_ != other.cache_ || iter_ != other.iter_) { clear(); cache_ = other.cache_; - if (cache_) { + if (cache_ != nullptr) { iter_ = other.iter_; ++iter_->second.first; } @@ -185,7 +185,7 @@ class sink_handle { private: void clear() { - if (cache_ && --iter_->second.first == 0) { + if (cache_ != nullptr && --iter_->second.first == 0) { cache_->erase(iter_); cache_ = nullptr; } @@ -255,7 +255,7 @@ class printer_actor : public blocking_actor { return nullptr; }; auto flush = [&](actor_data* what, bool forced) { - if (!what) + if (what == nullptr) return; auto& line = what->current_line; if (line.empty() || (line.back() != '\n' && !forced)) @@ -274,7 +274,7 @@ class printer_actor : public blocking_actor { if (str.empty() || aid == invalid_actor_id) return; auto d = get_data(aid, true); - if (d) { + if (d != nullptr) { d->current_line += str; flush(d, false); } @@ -284,7 +284,7 @@ class printer_actor : public blocking_actor { }, [&](delete_atom, actor_id aid) { auto data_ptr = get_data(aid, false); - if (data_ptr) { + if (data_ptr != nullptr) { flush(data_ptr, true); data.erase(aid); } @@ -294,7 +294,7 @@ class printer_actor : public blocking_actor { }, [&](redirect_atom, actor_id aid, const std::string& fn, int flag) { auto d = get_data(aid, true); - if (d) + if (d != nullptr) d->redirect = get_sink_handle(system(), fcache, fn, flag); }, [&](exit_msg& em) { diff --git a/libcaf_core/src/actor.cpp b/libcaf_core/src/actor.cpp index b1d3ef86af..0c070c1ef5 100644 --- a/libcaf_core/src/actor.cpp +++ b/libcaf_core/src/actor.cpp @@ -19,6 +19,7 @@ #include "caf/actor.hpp" +#include #include #include "caf/actor_addr.hpp" @@ -85,11 +86,11 @@ actor operator*(actor f, actor g) { } actor actor::splice_impl(std::initializer_list xs) { - CAF_ASSERT(xs.size() >= 2); + assert(xs.size() >= 2); actor_system* sys = nullptr; std::vector tmp; for (auto& x : xs) { - if (!sys) + if (sys == nullptr) sys = &(x->home_system()); tmp.push_back(actor_cast(x)); } diff --git a/libcaf_core/src/actor_addr.cpp b/libcaf_core/src/actor_addr.cpp index d1a15603c8..a4f807b90e 100644 --- a/libcaf_core/src/actor_addr.cpp +++ b/libcaf_core/src/actor_addr.cpp @@ -44,9 +44,9 @@ actor_addr::actor_addr(actor_control_block* ptr, bool add_ref) intptr_t actor_addr::compare(const actor_control_block* lhs, const actor_control_block* rhs) { // invalid actors are always "less" than valid actors - if (!lhs) - return rhs ? -1 : 0; - if (!rhs) + if (lhs == nullptr) + return rhs != nullptr ? -1 : 0; + if (rhs == nullptr) return 1; // check for identity if (lhs == rhs) diff --git a/libcaf_core/src/actor_control_block.cpp b/libcaf_core/src/actor_control_block.cpp index b532fd95a0..e4cec7587b 100644 --- a/libcaf_core/src/actor_control_block.cpp +++ b/libcaf_core/src/actor_control_block.cpp @@ -83,7 +83,7 @@ bool operator==(const abstract_actor* x, const strong_actor_ptr& y) { error load_actor(strong_actor_ptr& storage, execution_unit* ctx, actor_id aid, const node_id& nid) { - if (!ctx) + if (ctx == nullptr) return sec::no_context; auto& sys = ctx->system(); if (sys.node() == nid) { @@ -93,7 +93,7 @@ error load_actor(strong_actor_ptr& storage, execution_unit* ctx, return none; } auto prp = ctx->proxy_registry_ptr(); - if (!prp) + if (prp == nullptr) return sec::no_proxy_registry; // deal with (proxies for) remote actors storage = prp->get_or_put(nid, aid); @@ -102,7 +102,7 @@ error load_actor(strong_actor_ptr& storage, execution_unit* ctx, error save_actor(strong_actor_ptr& storage, execution_unit* ctx, actor_id aid, const node_id& nid) { - if (!ctx) + if (ctx == nullptr) return sec::no_context; auto& sys = ctx->system(); // register locally running actors to be able to deserialize them later @@ -114,7 +114,7 @@ error save_actor(strong_actor_ptr& storage, execution_unit* ctx, namespace { void append_to_string_impl(std::string& x, const actor_control_block* y) { - if (y) { + if (y != nullptr) { x += std::to_string(y->aid); x += '@'; append_to_string(x, y->nid); diff --git a/libcaf_core/src/actor_ostream.cpp b/libcaf_core/src/actor_ostream.cpp index 7dba51c44a..acacfa24ff 100644 --- a/libcaf_core/src/actor_ostream.cpp +++ b/libcaf_core/src/actor_ostream.cpp @@ -56,7 +56,7 @@ actor_ostream& actor_ostream::flush() { } void actor_ostream::redirect(abstract_actor* self, std::string fn, int flags) { - if (!self) + if (self == nullptr) return; auto pr = self->home_system().scheduler().printer(); pr->enqueue(make_mailbox_element(nullptr, message_id::make(), {}, diff --git a/libcaf_core/src/actor_pool.cpp b/libcaf_core/src/actor_pool.cpp index 12110c2dde..33b9373880 100644 --- a/libcaf_core/src/actor_pool.cpp +++ b/libcaf_core/src/actor_pool.cpp @@ -104,7 +104,7 @@ actor actor_pool::make(execution_unit* eu, policy pol) { } actor actor_pool::make(execution_unit* eu, size_t num_workers, - factory fac, policy pol) { + const factory& fac, policy pol) { auto res = make(eu, std::move(pol)); auto ptr = static_cast(actor_cast(res)); auto res_addr = ptr->address(); diff --git a/libcaf_core/src/actor_system.cpp b/libcaf_core/src/actor_system.cpp index be8209fba3..ae1ca35b42 100644 --- a/libcaf_core/src/actor_system.cpp +++ b/libcaf_core/src/actor_system.cpp @@ -47,7 +47,7 @@ struct kvstate { std::unordered_map subscribers; static const char* name; template - friend void serialize(Processor& proc, kvstate& x, const unsigned int) { + friend void serialize(Processor& proc, kvstate& x, unsigned int) { proc & x.data; proc & x.subscribers; } @@ -342,7 +342,7 @@ bool actor_system::has_middleman() const { } io::middleman& actor_system::middleman() { - if (!middleman_) + if (middleman_ == nullptr) CAF_RAISE_ERROR("cannot access middleman: module not loaded"); return *middleman_; } @@ -352,7 +352,7 @@ bool actor_system::has_opencl_manager() const { } opencl::manager& actor_system::opencl_manager() const { - if (!opencl_manager_) + if (opencl_manager_ == nullptr) CAF_RAISE_ERROR("cannot access opencl manager: module not loaded"); return *opencl_manager_; } @@ -401,7 +401,7 @@ actor_system::dyn_spawn_impl(const std::string& name, message& args, auto i = fs.find(name); if (i == fs.end()) return sec::unknown_type; - actor_config cfg{ctx ? ctx : &dummy_execution_unit_}; + actor_config cfg{ctx != nullptr ? ctx : &dummy_execution_unit_}; auto res = i->second(cfg, args); if (!res.first) return sec::cannot_spawn_actor_from_arguments; diff --git a/libcaf_core/src/actor_system_config.cpp b/libcaf_core/src/actor_system_config.cpp index 08966e93de..c4a22e1864 100644 --- a/libcaf_core/src/actor_system_config.cpp +++ b/libcaf_core/src/actor_system_config.cpp @@ -49,13 +49,13 @@ class actor_system_config_reader { sinks_.emplace(x->full_name(), x->to_sink()); } - void operator()(size_t ln, std::string name, config_value& cv) { + void operator()(size_t ln, const std::string& name, config_value& cv) { auto i = sinks_.find(name); if (i != sinks_.end()) (i->second)(ln, cv, none); else std::cerr << "error in line " << ln - << ": unrecognized parameter name \"" << name << "\""; + << R"(: unrecognized parameter name ")" << name << R"(")"; } private: @@ -200,7 +200,7 @@ actor_system_config& actor_system_config::parse(int argc, char** argv, if (argc > 1) args = message_builder(argv + 1, argv + argc).move_to_message(); // set default config file name if not set by user - if (!ini_file_cstr) + if (ini_file_cstr == nullptr) ini_file_cstr = "caf-application.ini"; std::string config_file_name; // CLI file name has priority over default file name @@ -258,12 +258,12 @@ actor_system_config& actor_system_config::parse(message& args, std::cerr << res.error << endl; return *this; } - if (res.opts.count("help")) { + if (res.opts.count("help") != 0u) { cli_helptext_printed = true; cout << res.helptext << endl; return *this; } - if (res.opts.count("caf#slave-mode")) { + if (res.opts.count("caf#slave-mode") != 0u) { slave_mode = true; if (slave_name.empty()) std::cerr << "running in slave mode but no name was configured" << endl; @@ -286,7 +286,7 @@ actor_system_config& actor_system_config::parse(message& args, }, middleman_network_backend, "middleman.network-backend"); verify_atom_opt({atom("stealing"), atom("sharing")}, scheduler_policy, "scheduler.policy "); - if (res.opts.count("caf#dump-config")) { + if (res.opts.count("caf#dump-config") != 0u) { cli_helptext_printed = true; std::string category; option_vector* all_options[] = { &options_, &custom_options_ }; @@ -316,16 +316,13 @@ actor_system_config::add_error_category(atom_value x, error_renderer y) { } actor_system_config& actor_system_config::set(const char* cn, config_value cv) { - std::string full_name; - for (auto& x : options_) { - // config_name has format "$category.$name" - full_name = x->category(); - full_name += '.'; - full_name += x->name(); - if (full_name == cn) { - auto f = x->to_sink(); - f(0, cv, none); - } + auto e = options_.end(); + auto i = std::find_if(options_.begin(), e, [cn](const option_ptr& ptr) { + return ptr->full_name() == cn; + }); + if (i != e) { + auto f = (*i)->to_sink(); + f(0, cv, none); } return *this; } diff --git a/libcaf_core/src/behavior_impl.cpp b/libcaf_core/src/behavior_impl.cpp index 3fc1195aa6..6a9a9464db 100644 --- a/libcaf_core/src/behavior_impl.cpp +++ b/libcaf_core/src/behavior_impl.cpp @@ -17,6 +17,8 @@ * http://www.boost.org/LICENSE_1_0.txt. * ******************************************************************************/ +#include + #include "caf/detail/behavior_impl.hpp" #include "caf/message_handler.hpp" @@ -45,9 +47,9 @@ class combinator final : public behavior_impl { return new combinator(first, second->copy(tdef)); } - combinator(const pointer& p0, const pointer& p1) + combinator(pointer p0, const pointer& p1) : behavior_impl(p1->timeout()), - first(p0), + first(std::move(p0)), second(p1) { // nop } diff --git a/libcaf_core/src/blocking_actor.cpp b/libcaf_core/src/blocking_actor.cpp index 6530c58b70..8e07732d37 100644 --- a/libcaf_core/src/blocking_actor.cpp +++ b/libcaf_core/src/blocking_actor.cpp @@ -17,6 +17,8 @@ * http://www.boost.org/LICENSE_1_0.txt. * ******************************************************************************/ +#include + #include "caf/blocking_actor.hpp" #include "caf/logger.hpp" @@ -122,7 +124,7 @@ void blocking_actor::launch(execution_unit*, bool, bool hide) { blocking_actor::receive_while_helper blocking_actor::receive_while(std::function stmt) { - return {this, stmt}; + return {this, std::move(stmt)}; } blocking_actor::receive_while_helper @@ -277,7 +279,7 @@ class message_sequence_combinator : public message_sequence { bool at_end() override { if (ptr_->at_end()) { - if (!fallback_) + if (fallback_ == nullptr) return true; ptr_ = fallback_; fallback_ = nullptr; diff --git a/libcaf_core/src/concatenated_tuple.cpp b/libcaf_core/src/concatenated_tuple.cpp index 18b7166690..cfbecd8d28 100644 --- a/libcaf_core/src/concatenated_tuple.cpp +++ b/libcaf_core/src/concatenated_tuple.cpp @@ -31,7 +31,7 @@ concatenated_tuple::concatenated_tuple(std::initializer_list xs) { for (auto& x : xs) { if (x) { auto dptr = dynamic_cast(x.get()); - if (dptr) { + if (dptr != nullptr) { auto& vec = dptr->data_; data_.insert(data_.end(), vec.begin(), vec.end()); } else { diff --git a/libcaf_core/src/config_option.cpp b/libcaf_core/src/config_option.cpp index 71201efe91..3351ba6027 100644 --- a/libcaf_core/src/config_option.cpp +++ b/libcaf_core/src/config_option.cpp @@ -64,7 +64,7 @@ std::string config_option::full_name() const { res += '.'; auto name_begin = name(); const char* name_end = strchr(name(), ','); - if (name_end) + if (name_end != nullptr) res.insert(res.end(), name_begin, name_end); else res += name(); diff --git a/libcaf_core/src/decorated_tuple.cpp b/libcaf_core/src/decorated_tuple.cpp index 6c50657bed..b5714710a4 100644 --- a/libcaf_core/src/decorated_tuple.cpp +++ b/libcaf_core/src/decorated_tuple.cpp @@ -32,20 +32,19 @@ decorated_tuple::decorated_tuple(cow_ptr&& d, vector_type&& v) || *(std::max_element(mapping_.begin(), mapping_.end())) < static_cast(decorated_)->size()); // calculate type token - for (size_t i = 0; i < mapping_.size(); ++i) { + for (unsigned long i : mapping_) { type_token_ <<= 6; - type_token_ |= decorated_->type_nr(mapping_[i]); + type_token_ |= decorated_->type_nr(i); } } decorated_tuple::cow_ptr decorated_tuple::make(cow_ptr d, vector_type v) { auto ptr = dynamic_cast(d.get()); - if (ptr) { + if (ptr != nullptr) { d = ptr->decorated(); auto& pmap = ptr->mapping(); - for (size_t i = 0; i < v.size(); ++i) { - v[i] = pmap[v[i]]; - } + for (auto& i : v) + i = pmap[i]; } return make_counted(std::move(d), std::move(v)); } diff --git a/libcaf_core/src/error.cpp b/libcaf_core/src/error.cpp index dc5f345841..1be507b0d3 100644 --- a/libcaf_core/src/error.cpp +++ b/libcaf_core/src/error.cpp @@ -46,7 +46,7 @@ error::error(none_t) noexcept : data_(nullptr) { } error::error(error&& x) noexcept : data_(x.data_) { - if (data_) + if (data_ != nullptr) x.data_ = nullptr; } @@ -61,7 +61,7 @@ error::error(const error& x) : data_(x ? new data(*x.data_) : nullptr) { error& error::operator=(const error& x) { if (x) { - if (!data_) + if (data_ == nullptr) data_ = new data(*x.data_); else *data_ = *x.data_; @@ -118,7 +118,7 @@ int error::compare(const error& x) const noexcept { int error::compare(uint8_t x, atom_value y) const noexcept { uint8_t mx; atom_value my; - if (data_) { + if (data_ != nullptr) { mx = data_->code; my = data_->category; } else { @@ -143,7 +143,7 @@ message& error::context() noexcept { } void error::clear() noexcept { - if (data_) { + if (data_ != nullptr) { delete data_; data_ = nullptr; } @@ -151,9 +151,9 @@ void error::clear() noexcept { // -- inspection support ----------------------------------------------------- -error error::apply(inspect_fun f) { +error error::apply(const inspect_fun& f) { data tmp{0, atom(""), message{}}; - data& ref = data_ ? *data_ : tmp; + data& ref = data_ != nullptr ? *data_ : tmp; auto result = f(meta::type_name("error"), ref.code, ref.category, meta::omittable_if_empty(), ref.context); if (ref.code == 0) diff --git a/libcaf_core/src/forwarding_actor_proxy.cpp b/libcaf_core/src/forwarding_actor_proxy.cpp index 4a186fc47e..d848bc28c3 100644 --- a/libcaf_core/src/forwarding_actor_proxy.cpp +++ b/libcaf_core/src/forwarding_actor_proxy.cpp @@ -17,6 +17,8 @@ * http://www.boost.org/LICENSE_1_0.txt. * ******************************************************************************/ +#include + #include "caf/forwarding_actor_proxy.hpp" #include "caf/send.hpp" @@ -28,7 +30,7 @@ namespace caf { forwarding_actor_proxy::forwarding_actor_proxy(actor_config& cfg, actor mgr) : actor_proxy(cfg), - manager_(mgr) { + manager_(std::move(mgr)) { // nop } @@ -57,7 +59,7 @@ void forwarding_actor_proxy::forward_msg(strong_actor_ptr sender, if (manager_) manager_->enqueue(nullptr, invalid_message_id, make_message(forward_atom::value, std::move(sender), - fwd ? *fwd : tmp, + fwd != nullptr ? *fwd : tmp, strong_actor_ptr{ctrl()}, mid, std::move(msg)), nullptr); diff --git a/libcaf_core/src/get_mac_addresses.cpp b/libcaf_core/src/get_mac_addresses.cpp index ba3d36c630..d47dcc20aa 100644 --- a/libcaf_core/src/get_mac_addresses.cpp +++ b/libcaf_core/src/get_mac_addresses.cpp @@ -11,9 +11,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include @@ -66,7 +66,7 @@ std::vector get_mac_addresses() { } auto addr = oss.str(); if (addr != "00:00:00:00:00:00") { - result.push_back({i->if_name, std::move(addr)}); + result.emplace_back(i->if_name, std::move(addr)); } } if_freenameindex(indices); diff --git a/libcaf_core/src/get_root_uuid.cpp b/libcaf_core/src/get_root_uuid.cpp index 793c2a4f8e..21f39f5fd1 100644 --- a/libcaf_core/src/get_root_uuid.cpp +++ b/libcaf_core/src/get_root_uuid.cpp @@ -50,7 +50,7 @@ std::string get_root_uuid() { // fetch hd serial std::string uuid; FILE* get_uuid_cmd = popen(s_get_uuid, "r"); - while (fgets(cbuf, 100, get_uuid_cmd) != 0) { + while (fgets(cbuf, 100, get_uuid_cmd) != nullptr) { uuid += cbuf; } pclose(get_uuid_cmd); diff --git a/libcaf_core/src/group.cpp b/libcaf_core/src/group.cpp index 385df3f91e..78ebcdb49a 100644 --- a/libcaf_core/src/group.cpp +++ b/libcaf_core/src/group.cpp @@ -58,7 +58,7 @@ intptr_t group::compare(const group& other) const noexcept { error inspect(serializer& f, group& x) { std::string mod_name; auto ptr = x.get(); - if (!ptr) + if (ptr == nullptr) return f(mod_name); mod_name = ptr->module().name(); auto e = f(mod_name); @@ -72,7 +72,7 @@ error inspect(deserializer& f, group& x) { x = invalid_group; return none; } - if (!f.context()) + if (f.context() == nullptr) return sec::no_context; auto& sys = f.context()->system(); auto mod = sys.groups().get_module(module_name); diff --git a/libcaf_core/src/group_manager.cpp b/libcaf_core/src/group_manager.cpp index 7f0e64bc1a..98507de3dd 100644 --- a/libcaf_core/src/group_manager.cpp +++ b/libcaf_core/src/group_manager.cpp @@ -100,9 +100,7 @@ class local_group : public abstract_group { bool subscribe(strong_actor_ptr who) override { CAF_LOG_TRACE(CAF_ARG(who)); - if (add_subscriber(std::move(who)).first) - return true; - return false; + return add_subscriber(std::move(who)).first; } void unsubscribe(const actor_control_block* who) override { @@ -122,9 +120,9 @@ class local_group : public abstract_group { } local_group(local_group_module& mod, std::string id, node_id nid, - optional local_broker); + optional lb); - ~local_group(); + ~local_group() override; protected: detail::shared_spinlock mtx_; @@ -224,9 +222,9 @@ class proxy_broker : public event_based_actor { CAF_LOG_TRACE(""); } - behavior make_behavior(); + behavior make_behavior() override; - void on_exit() { + void on_exit() override { group_.reset(); } @@ -487,9 +485,9 @@ expected group_manager::get(const std::string& module_name, auto mod = get_module(module_name); if (mod) return mod->get(group_identifier); - std::string error_msg = "no module named \""; + std::string error_msg = R"(no module named ")"; error_msg += module_name; - error_msg += "\" found"; + error_msg += R"(" found)"; return make_error(sec::no_such_group_module, std::move(error_msg)); } diff --git a/libcaf_core/src/local_actor.cpp b/libcaf_core/src/local_actor.cpp index c4fe6ed445..d0c58bc699 100644 --- a/libcaf_core/src/local_actor.cpp +++ b/libcaf_core/src/local_actor.cpp @@ -71,7 +71,7 @@ void local_actor::request_response_timeout(const duration& d, message_id mid) { } void local_actor::monitor(abstract_actor* ptr) { - if (ptr) + if (ptr != nullptr) ptr->attach(default_attachable::make_monitor(ptr->address(), address())); } @@ -110,7 +110,7 @@ mailbox_element_ptr local_actor::next_message() { auto hp_pos = i; // read whole mailbox at once auto tmp = mailbox().try_pop(); - while (tmp) { + while (tmp != nullptr) { cache.insert(tmp->is_high_priority() ? hp_pos : e, tmp); // adjust high priority insert point on first low prio element insert if (hp_pos == e && !tmp->is_high_priority()) diff --git a/libcaf_core/src/logger.cpp b/libcaf_core/src/logger.cpp index f6fb0ac0c2..ee4d2193aa 100644 --- a/libcaf_core/src/logger.cpp +++ b/libcaf_core/src/logger.cpp @@ -141,7 +141,7 @@ void prettify_type_name(std::string& class_name, const char* c_class_name) { # if defined(CAF_LINUX) || defined(CAF_MACOS) int stat = 0; std::unique_ptr real_class_name{nullptr, free}; - auto tmp = abi::__cxa_demangle(c_class_name, 0, 0, &stat); + auto tmp = abi::__cxa_demangle(c_class_name, nullptr, nullptr, &stat); real_class_name.reset(tmp); class_name = stat == 0 ? real_class_name.get() : c_class_name; # else @@ -288,7 +288,7 @@ void logger::log(int level, const char* component, } void logger::set_current_actor_system(actor_system* x) { - if (x) + if (x != nullptr) set_current_logger(&x->logger()); else set_current_logger(nullptr); @@ -303,7 +303,7 @@ void logger::log_static(int level, const char* component, const char* function_name, const char* file_name, int line_num, const std::string& msg) { auto ptr = get_current_logger(); - if (ptr) + if (ptr != nullptr) ptr->log(level, component, class_name, function_name, file_name, line_num, msg); } diff --git a/libcaf_core/src/mailbox_element.cpp b/libcaf_core/src/mailbox_element.cpp index 3c9ed09ba2..5919c8d9b0 100644 --- a/libcaf_core/src/mailbox_element.cpp +++ b/libcaf_core/src/mailbox_element.cpp @@ -35,7 +35,7 @@ class mailbox_element_wrapper : public mailbox_element { type_erased_tuple& content() override { auto ptr = msg_.vals().raw_ptr(); - if (ptr) + if (ptr != nullptr) return *ptr; return dummy_; } diff --git a/libcaf_core/src/memory.cpp b/libcaf_core/src/memory.cpp index 370153493d..3fd5cca655 100644 --- a/libcaf_core/src/memory.cpp +++ b/libcaf_core/src/memory.cpp @@ -62,7 +62,7 @@ void make_cache_map() { cache_map& get_cache_map() { pthread_once(&s_key_once, make_cache_map); auto cache = reinterpret_cast(pthread_getspecific(s_key)); - if (!cache) { + if (cache == nullptr) { cache = new cache_map; pthread_setspecific(s_key, cache); // insert default types diff --git a/libcaf_core/src/merged_tuple.cpp b/libcaf_core/src/merged_tuple.cpp index 6070862078..d37f614778 100644 --- a/libcaf_core/src/merged_tuple.cpp +++ b/libcaf_core/src/merged_tuple.cpp @@ -48,9 +48,8 @@ merged_tuple::merged_tuple(data_type xs, mapping_type ys) CAF_ASSERT(!data_.empty()); CAF_ASSERT(!mapping_.empty()); // calculate type token - for (size_t i = 0; i < mapping_.size(); ++i) { + for (auto& p : mapping_) { type_token_ <<= 6; - auto& p = mapping_[i]; type_token_ |= data_[p.first]->type_nr(p.second); } } diff --git a/libcaf_core/src/message.cpp b/libcaf_core/src/message.cpp index 1ab0ee0bf4..dd38240241 100644 --- a/libcaf_core/src/message.cpp +++ b/libcaf_core/src/message.cpp @@ -20,6 +20,8 @@ #include "caf/message.hpp" #include +#include +#include #include "caf/serializer.hpp" #include "caf/actor_system.hpp" @@ -42,7 +44,7 @@ message::message(message&& other) noexcept : vals_(std::move(other.vals_)) { // nop } -message::message(const data_ptr& ptr) noexcept : vals_(ptr) { +message::message(data_ptr ptr) noexcept : vals_(std::move(ptr)) { // nop } @@ -144,11 +146,11 @@ message message::extract_impl(size_t start, message_handler handler) const { } message message::extract(message_handler handler) const { - return extract_impl(0, handler); + return extract_impl(0, std::move(handler)); } message::cli_res message::extract_opts(std::vector xs, - help_factory f, bool no_help) const { + const help_factory& f, bool no_help) const { std::string helpstr; auto make_error = [&](std::string err) -> cli_res { return {*this, std::set{}, std::move(helpstr), std::move(err)}; @@ -166,7 +168,7 @@ message::cli_res message::extract_opts(std::vector xs, || std::find_if(s.begin() + 1, s.end(), has_short_help) != s.end(); }; if (!no_help && std::none_of(xs.begin(), xs.end(), pred)) { - xs.push_back(cli_arg{"help,h,?", "print this text"}); + xs.emplace_back("help,h,?", "print this text"); } std::map shorts; std::map longs; @@ -254,9 +256,9 @@ message::cli_res message::extract_opts(std::vector xs, } // no value given, try two-argument form below return skip(); - } else if (i->second->flag) { - *i->second->flag = true; } + if (i->second->flag != nullptr) + *i->second->flag = true; insert_opt_name(i->second); return none; } @@ -274,9 +276,9 @@ message::cli_res message::extract_opts(std::vector xs, } insert_opt_name(j->second); return none; - } else if (j->second->flag) { - *j->second->flag = true; } + if (j->second->flag != nullptr) + *j->second->flag = true; insert_opt_name(j->second); return none; } @@ -383,7 +385,7 @@ message message::concat_impl(std::initializer_list xs) { } error inspect(serializer& sink, message& msg) { - if (!sink.context()) + if (sink.context() == nullptr) return sec::no_context; // build type name uint16_t zero = 0; @@ -396,13 +398,13 @@ error inspect(serializer& sink, message& msg) { for (size_t i = 0; i < n; ++i) { auto rtti = msg.cvals()->type(i); auto ptr = types.portable_name(rtti); - if (!ptr) { + if (ptr == nullptr) { std::cerr << "[ERROR]: cannot serialize message because a type was " "not added to the types list, typeid name: " - << (rtti.second ? rtti.second->name() : "-not-available-") + << (rtti.second != nullptr ? rtti.second->name() : "-not-available-") << std::endl; return make_error(sec::unknown_type, - rtti.second ? rtti.second->name() : "-not-available-"); + rtti.second != nullptr ? rtti.second->name() : "-not-available-"); } tname += '+'; tname += *ptr; @@ -421,7 +423,7 @@ error inspect(serializer& sink, message& msg) { } error inspect(deserializer& source, message& msg) { - if (!source.context()) + if (source.context() == nullptr) return sec::no_context; uint16_t zero; std::string tname; diff --git a/libcaf_core/src/monitorable_actor.cpp b/libcaf_core/src/monitorable_actor.cpp index 9fc119ef3a..3c2e062b86 100644 --- a/libcaf_core/src/monitorable_actor.cpp +++ b/libcaf_core/src/monitorable_actor.cpp @@ -232,7 +232,8 @@ bool monitorable_actor::handle_system_message(mailbox_element& x, if (em.reason) cleanup(std::move(em.reason), ctx); return true; - } else if (msg.size() > 1 && msg.match_element(0)) { + } + if (msg.size() > 1 && msg.match_element(0)) { if (!x.sender) return true; error err; diff --git a/libcaf_core/src/node_id.cpp b/libcaf_core/src/node_id.cpp index 0a72c744cb..520cb56d51 100644 --- a/libcaf_core/src/node_id.cpp +++ b/libcaf_core/src/node_id.cpp @@ -88,10 +88,9 @@ int node_id::compare(const node_id& other) const { auto ipair = std::mismatch(host_id().begin(), last, other.host_id().begin()); if (ipair.first == last) return static_cast(process_id())-static_cast(other.process_id()); - else if (*ipair.first < *ipair.second) + if (*ipair.first < *ipair.second) return -1; - else - return 1; + return 1; } node_id::data::data() : pid_(0) { @@ -110,13 +109,13 @@ node_id::data::data(uint32_t procid, const std::string& hash) : pid_(procid) { return; } auto hex_value = [](char c) -> uint8_t { - if (isalpha(c)) { + if (isalpha(c) != 0) { if (c >= 'a' && c <= 'f') return static_cast((c - 'a') + 10); if (c >= 'A' && c <= 'F') return static_cast((c - 'A') + 10); } - return isdigit(c) ? static_cast(c - '0') : 0; + return isdigit(c) != 0 ? static_cast(c - '0') : 0; }; auto j = hash.c_str(); for (size_t i = 0; i < host_id_size; ++i) { diff --git a/libcaf_core/src/parse_ini.cpp b/libcaf_core/src/parse_ini.cpp index fc80dde69b..9640cdd886 100644 --- a/libcaf_core/src/parse_ini.cpp +++ b/libcaf_core/src/parse_ini.cpp @@ -27,7 +27,7 @@ namespace caf { namespace detail { -void parse_ini_t::operator()(std::istream& input, config_consumer consumer_fun, +void parse_ini_t::operator()(std::istream& input, const config_consumer& consumer_fun, opt_err errors) const { // wraps a temporary into an (lvalue) config_value and calls `consumer_fun` auto consumer = [&](size_t ln, std::string name, config_value x) { @@ -126,11 +126,11 @@ void parse_ini_t::operator()(std::istream& input, config_consumer consumer_fun, // end-of-string iterator auto eos = eol - 1; if (bov == eos) { - print_error("stray '\"'"); + print_error(R"(stray '"')"); continue; } if (*eos != '"') { - print_error("string not terminated by '\"'"); + print_error(R"(string not terminated by '"')"); continue; } // found a string, remove first and last char from string, diff --git a/libcaf_core/src/proxy_registry.cpp b/libcaf_core/src/proxy_registry.cpp index 6cfc511622..fbe82ebe06 100644 --- a/libcaf_core/src/proxy_registry.cpp +++ b/libcaf_core/src/proxy_registry.cpp @@ -98,7 +98,7 @@ void proxy_registry::erase(const key_type& inf, actor_id aid, error rsn) { auto j = submap.find(aid); if (j == submap.end()) return; - kill_proxy(j->second, rsn); + kill_proxy(j->second, std::move(rsn)); submap.erase(j); if (submap.empty()) proxies_.erase(i); @@ -116,7 +116,7 @@ void proxy_registry::kill_proxy(strong_actor_ptr& ptr, error rsn) { if (!ptr) return; auto pptr = static_cast(actor_cast(ptr)); - pptr->kill_proxy(backend_.registry_context(), rsn); + pptr->kill_proxy(backend_.registry_context(), std::move(rsn)); } } // namespace caf diff --git a/libcaf_core/src/ripemd_160.cpp b/libcaf_core/src/ripemd_160.cpp index ac116d47da..150e5edcea 100644 --- a/libcaf_core/src/ripemd_160.cpp +++ b/libcaf_core/src/ripemd_160.cpp @@ -394,8 +394,8 @@ void ripemd_160(std::array& storage, const std::string& data) { length = static_cast(data.size()); // process message in 16-word chunks for (dword nbytes = length; nbytes > 63; nbytes -= 64) { - for (dword i = 0; i < 16; ++i) { - X[i] = BYTES_TO_DWORD(message); + for (auto& i : X) { + i = BYTES_TO_DWORD(message); message += 4; } compress(MDbuf, X); diff --git a/libcaf_core/src/scheduled_actor.cpp b/libcaf_core/src/scheduled_actor.cpp index 18803bac2e..d55a79adc9 100644 --- a/libcaf_core/src/scheduled_actor.cpp +++ b/libcaf_core/src/scheduled_actor.cpp @@ -112,7 +112,7 @@ scheduled_actor::scheduled_actor(actor_config& cfg) scheduled_actor::~scheduled_actor() { // signalize to the private thread object that it is // unrachable and can be destroyed as well - if (private_thread_) + if (private_thread_ != nullptr) private_thread_->notify_self_destroyed(); } @@ -134,7 +134,7 @@ void scheduled_actor::enqueue(mailbox_element_ptr ptr, execution_unit* eu) { CAF_ASSERT(private_thread_ != nullptr); private_thread_->resume(); } else { - if (eu) + if (eu != nullptr) eu->exec_later(this); else home_system().scheduler().enqueue(this); @@ -520,9 +520,8 @@ bool scheduled_actor::activate(execution_unit* ctx) { if (finalize()) { CAF_LOG_DEBUG("actor_done() returned true right after make_behavior()"); return false; - } else { - CAF_LOG_DEBUG("initialized actor:" << CAF_ARG(name())); } + CAF_LOG_DEBUG("initialized actor:" << CAF_ARG(name())); } # ifndef CAF_NO_EXCEPTIONS } diff --git a/libcaf_core/src/stringification_inspector.cpp b/libcaf_core/src/stringification_inspector.cpp index d7b61a2008..6b294501ae 100644 --- a/libcaf_core/src/stringification_inspector.cpp +++ b/libcaf_core/src/stringification_inspector.cpp @@ -41,8 +41,8 @@ void stringification_inspector::consume(atom_value& x) { } void stringification_inspector::consume(const char* cstr) { - if (!cstr || *cstr == '\0') { - result_ += "\"\""; + if (cstr == nullptr || *cstr == '\0') { + result_ += R"("")"; return; } if (*cstr == '"') { @@ -58,10 +58,10 @@ void stringification_inspector::consume(const char* cstr) { result_ += c; break; case '\\': - result_ += "\\\\"; + result_ += R"(\\)"; break; case '"': - result_ += "\\\""; + result_ += R"(\")"; break; case '\0': goto end_of_string; diff --git a/libcaf_core/src/try_match.cpp b/libcaf_core/src/try_match.cpp index 5b70b84ef1..74fc8991af 100644 --- a/libcaf_core/src/try_match.cpp +++ b/libcaf_core/src/try_match.cpp @@ -38,9 +38,7 @@ bool match_atom_constant(const meta_element& me, const type_erased_tuple& xs, if (!xs.matches(pos, type_nr::value, nullptr)) return false; auto ptr = xs.get(pos); - if (me.v != *reinterpret_cast(ptr)) - return false; - return true; + return me.v == *reinterpret_cast(ptr); } bool try_match(const type_erased_tuple& xs, diff --git a/libcaf_core/src/type_erased_tuple.cpp b/libcaf_core/src/type_erased_tuple.cpp index aee019edbb..f31af52127 100644 --- a/libcaf_core/src/type_erased_tuple.cpp +++ b/libcaf_core/src/type_erased_tuple.cpp @@ -76,7 +76,7 @@ bool type_erased_tuple::matches(size_t pos, uint16_t nr, if (tp.first != nr) return false; if (nr == 0) - return ptr ? *tp.second == *ptr : false; + return ptr != nullptr ? *tp.second == *ptr : false; return true; } diff --git a/libcaf_core/src/type_erased_value.cpp b/libcaf_core/src/type_erased_value.cpp index b4733c304b..6392f29a4c 100644 --- a/libcaf_core/src/type_erased_value.cpp +++ b/libcaf_core/src/type_erased_value.cpp @@ -30,7 +30,7 @@ bool type_erased_value::matches(uint16_t nr, const std::type_info* ptr) const { if (tp.first != nr) return false; if (nr == 0) - return ptr ? *tp.second == *ptr : false; + return ptr != nullptr ? *tp.second == *ptr : false; return true; } diff --git a/libcaf_core/src/uniform_type_info_map.cpp b/libcaf_core/src/uniform_type_info_map.cpp index f13f315902..e1a2754c31 100644 --- a/libcaf_core/src/uniform_type_info_map.cpp +++ b/libcaf_core/src/uniform_type_info_map.cpp @@ -147,7 +147,7 @@ uniform_type_info_map::portable_name(uint16_t nr, const std::type_info* ti) const { if (nr != 0) return &builtin_names_[nr - 1]; - if (!ti) + if (ti == nullptr) return nullptr; auto& custom_names = system().config().type_names_by_rtti; auto i = custom_names.find(std::type_index(*ti)); diff --git a/libcaf_core/test/actor_lifetime.cpp b/libcaf_core/test/actor_lifetime.cpp index 4feec08544..254196b121 100644 --- a/libcaf_core/test/actor_lifetime.cpp +++ b/libcaf_core/test/actor_lifetime.cpp @@ -42,7 +42,7 @@ class testee : public event_based_actor { ++s_pending_on_exits; } - ~testee() { + ~testee() override { --s_testees; } diff --git a/libcaf_core/test/actor_pool.cpp b/libcaf_core/test/actor_pool.cpp index 6dfe2e1805..a2a1e088cd 100644 --- a/libcaf_core/test/actor_pool.cpp +++ b/libcaf_core/test/actor_pool.cpp @@ -37,7 +37,7 @@ class worker : public event_based_actor { ++s_ctors; } - ~worker() { + ~worker() override { ++s_dtors; } diff --git a/libcaf_core/test/constructor_attach.cpp b/libcaf_core/test/constructor_attach.cpp index e50a682457..f3e60c2688 100644 --- a/libcaf_core/test/constructor_attach.cpp +++ b/libcaf_core/test/constructor_attach.cpp @@ -39,7 +39,7 @@ class testee : public event_based_actor { }); } - behavior make_behavior() { + behavior make_behavior() override { return { [=](die_atom) { quit(exit_reason::user_shutdown); @@ -62,7 +62,7 @@ class spawner : public event_based_actor { }); } - behavior make_behavior() { + behavior make_behavior() override { return { [=](done_atom, const error& reason) { CAF_CHECK_EQUAL(reason, exit_reason::user_shutdown); @@ -76,7 +76,7 @@ class spawner : public event_based_actor { }; } - void on_exit() { + void on_exit() override { destroy(testee_); } diff --git a/libcaf_core/test/custom_exception_handler.cpp b/libcaf_core/test/custom_exception_handler.cpp index 36e8d2b4e8..224e74fc29 100644 --- a/libcaf_core/test/custom_exception_handler.cpp +++ b/libcaf_core/test/custom_exception_handler.cpp @@ -30,7 +30,7 @@ using namespace caf; class exception_testee : public event_based_actor { public: - ~exception_testee(); + ~exception_testee() override; exception_testee(actor_config& cfg) : event_based_actor(cfg) { set_exception_handler([](std::exception_ptr&) -> error { return exit_reason::remote_link_unreachable; diff --git a/libcaf_core/test/dynamic_spawn.cpp b/libcaf_core/test/dynamic_spawn.cpp index 1b2f6346ec..fa82d31f51 100644 --- a/libcaf_core/test/dynamic_spawn.cpp +++ b/libcaf_core/test/dynamic_spawn.cpp @@ -86,7 +86,7 @@ class event_testee : public event_based_actor { ); } - ~event_testee() { + ~event_testee() override { dec_actor_instances(); } @@ -108,7 +108,7 @@ actor spawn_event_testee2(scoped_actor& parent) { parent(std::move(parent_actor)) { inc_actor_instances(); } - ~impl() { + ~impl() override { dec_actor_instances(); } behavior wait4timeout(int remaining) { @@ -136,7 +136,7 @@ class testee_actor : public blocking_actor { inc_actor_instances(); } - ~testee_actor() { + ~testee_actor() override { dec_actor_instances(); } @@ -194,7 +194,7 @@ class testee1 : public event_based_actor { inc_actor_instances(); } - ~testee1() { + ~testee1() override { dec_actor_instances(); } @@ -213,7 +213,7 @@ class echo_actor : public event_based_actor { inc_actor_instances(); } - ~echo_actor() { + ~echo_actor() override { dec_actor_instances(); } @@ -233,7 +233,7 @@ class simple_mirror : public event_based_actor { inc_actor_instances(); } - ~simple_mirror() { + ~simple_mirror() override { dec_actor_instances(); } @@ -277,7 +277,7 @@ behavior master(event_based_actor* self) { ); } -behavior slave(event_based_actor* self, actor master) { +behavior slave(event_based_actor* self, const actor& master) { self->link_to(master); self->set_exit_handler([=](exit_msg& msg) { CAF_MESSAGE("slave: received exit message"); @@ -296,7 +296,7 @@ class counting_actor : public event_based_actor { inc_actor_instances(); } - ~counting_actor() { + ~counting_actor() override { dec_actor_instances(); } @@ -506,7 +506,7 @@ CAF_TEST(constructor_attach) { }); } - behavior make_behavior() { + behavior make_behavior() override { return { [] { // nop @@ -514,7 +514,7 @@ CAF_TEST(constructor_attach) { }; } - void on_exit() { + void on_exit() override { destroy(buddy_); } @@ -537,7 +537,7 @@ CAF_TEST(constructor_attach) { }); } - behavior make_behavior() { + behavior make_behavior() override { return { [=](ok_atom, const error& reason) { CAF_CHECK_EQUAL(reason, exit_reason::user_shutdown); @@ -547,7 +547,7 @@ CAF_TEST(constructor_attach) { }; } - void on_exit() { + void on_exit() override { CAF_MESSAGE("spawner::on_exit()"); destroy(testee_); } diff --git a/libcaf_core/test/intrusive_ptr.cpp b/libcaf_core/test/intrusive_ptr.cpp index e94856e661..412db4d91d 100644 --- a/libcaf_core/test/intrusive_ptr.cpp +++ b/libcaf_core/test/intrusive_ptr.cpp @@ -53,7 +53,7 @@ class class0 : public ref_counted { } } - ~class0() { + ~class0() override { if (!subtype_) { --class0_instances; } @@ -77,7 +77,7 @@ class class1 : public class0 { ++class1_instances; } - ~class1() { + ~class1() override { --class1_instances; } diff --git a/libcaf_core/test/match.cpp b/libcaf_core/test/match.cpp index 83625790c2..1324678f2a 100644 --- a/libcaf_core/test/match.cpp +++ b/libcaf_core/test/match.cpp @@ -42,7 +42,7 @@ std::string to_string(const rtti_pair& x) { std::string result = "("; result += std::to_string(x.first); result += ", "; - result += x.second ? x.second->name() : ""; + result += x.second != nullptr ? x.second->name() : ""; result += ")"; return result; } diff --git a/libcaf_core/test/message.cpp b/libcaf_core/test/message.cpp index dff779e92e..e047c23eee 100644 --- a/libcaf_core/test/message.cpp +++ b/libcaf_core/test/message.cpp @@ -233,7 +233,7 @@ CAF_TEST(strings_to_string) { svec{"five", "six", "seven"}); CAF_CHECK(to_string(msg3) == R"__((["one", "two"], "three", "four", ["five", "six", "seven"]))__"); - auto msg4 = make_message("this is a \"test\""); + auto msg4 = make_message(R"(this is a "test")"); CAF_CHECK_EQUAL(to_string(msg4), "(\"this is a \\\"test\\\"\")"); } diff --git a/libcaf_core/test/message_lifetime.cpp b/libcaf_core/test/message_lifetime.cpp index 5118e280d4..1d3b8d3cde 100644 --- a/libcaf_core/test/message_lifetime.cpp +++ b/libcaf_core/test/message_lifetime.cpp @@ -37,7 +37,7 @@ class testee : public event_based_actor { // nop } - ~testee() { + ~testee() override { // nop } diff --git a/libcaf_core/test/or_else.cpp b/libcaf_core/test/or_else.cpp index 486bd6f4f2..b051060ff7 100644 --- a/libcaf_core/test/or_else.cpp +++ b/libcaf_core/test/or_else.cpp @@ -55,7 +55,7 @@ struct fixture { actor_system_config cfg; actor_system system; - void run_testee(actor testee) { + void run_testee(const actor& testee) { scoped_actor self{system}; self->request(testee, infinite, a_atom::value).receive( [](int i) { diff --git a/libcaf_core/test/request_response.cpp b/libcaf_core/test/request_response.cpp index 976e089d9e..cec788ce00 100644 --- a/libcaf_core/test/request_response.cpp +++ b/libcaf_core/test/request_response.cpp @@ -17,6 +17,8 @@ * http://www.boost.org/LICENSE_1_0.txt. * ******************************************************************************/ +#include + #include "caf/config.hpp" #define CAF_SUITE request_response @@ -81,9 +83,9 @@ struct float_or_int : event_based_actor { class popular_actor : public event_based_actor { // popular actors have a buddy public: - explicit popular_actor(actor_config& cfg, const actor& buddy_arg) + explicit popular_actor(actor_config& cfg, actor buddy_arg) : event_based_actor(cfg), - buddy_(buddy_arg) { + buddy_(std::move(buddy_arg)) { // don't pollute unit test output with (provoked) warnings set_default_handler(drop); } diff --git a/libcaf_core/test/serialization.cpp b/libcaf_core/test/serialization.cpp index 0bed1cd68e..90868f24ad 100644 --- a/libcaf_core/test/serialization.cpp +++ b/libcaf_core/test/serialization.cpp @@ -396,7 +396,7 @@ CAF_TEST(type_erased_tuple) { auto tview = make_type_erased_tuple_view(str, i32); CAF_CHECK_EQUAL(to_string(tview), deep_to_string(std::make_tuple(str, i32))); auto buf = serialize(tview); - CAF_REQUIRE(buf.size() > 0); + CAF_REQUIRE(!buf.empty()); std::string tmp1; int32_t tmp2; deserialize(buf, tmp1, tmp2); diff --git a/libcaf_core/test/typed_spawn.cpp b/libcaf_core/test/typed_spawn.cpp index 7350b82bda..ad2d554185 100644 --- a/libcaf_core/test/typed_spawn.cpp +++ b/libcaf_core/test/typed_spawn.cpp @@ -115,7 +115,7 @@ class typed_server3 : public server_type::base { } }; -void client(event_based_actor* self, actor parent, server_type serv) { +void client(event_based_actor* self, const actor& parent, const server_type& serv) { self->request(serv, infinite, my_request{0, 0}).then( [=](bool val1) { CAF_CHECK_EQUAL(val1, true); @@ -245,7 +245,7 @@ maybe_string_actor::behavior_type maybe_string_reverter() { } maybe_string_actor::behavior_type -maybe_string_delegator(maybe_string_actor::pointer self, maybe_string_actor x) { +maybe_string_delegator(maybe_string_actor::pointer self, const maybe_string_actor& x) { self->link_to(x); return { [=](string& s) -> delegated { diff --git a/libcaf_io/caf/io/abstract_broker.hpp b/libcaf_io/caf/io/abstract_broker.hpp index 4b4087f1e8..7a2365aca8 100644 --- a/libcaf_io/caf/io/abstract_broker.hpp +++ b/libcaf_io/caf/io/abstract_broker.hpp @@ -77,7 +77,7 @@ class middleman; class abstract_broker : public scheduled_actor, public prohibit_top_level_spawn_marker { public: - virtual ~abstract_broker(); + ~abstract_broker() override; // even brokers need friends friend class scribe; @@ -139,7 +139,7 @@ class abstract_broker : public scheduled_actor, /// Modifies the receive policy for given connection. /// @param hdl Identifies the affected connection. /// @param config Contains the new receive policy. - void configure_read(connection_handle hdl, receive_policy::config config); + void configure_read(connection_handle hdl, receive_policy::config cfg); /// Enables or disables write notifications for given connection. void ack_writes(connection_handle hdl, bool enable); @@ -148,7 +148,7 @@ class abstract_broker : public scheduled_actor, std::vector& wr_buf(connection_handle hdl); /// Writes `data` into the buffer for given connection. - void write(connection_handle hdl, size_t data_size, const void* data); + void write(connection_handle hdl, size_t bs, const void* buf); /// Sends the content of the buffer for given connection. void flush(connection_handle hdl); @@ -164,7 +164,7 @@ class abstract_broker : public scheduled_actor, /// Tries to connect to `host` on given `port` and creates /// a new scribe describing the connection afterwards. /// @returns The handle of the new `scribe` on success. - expected add_tcp_scribe(const std::string& host, uint16_t port); + expected add_tcp_scribe(const std::string& hostname, uint16_t port); /// Assigns a detached `scribe` instance identified by `hdl` /// from the `multiplexer` to this broker. diff --git a/libcaf_io/caf/io/basp/instance.hpp b/libcaf_io/caf/io/basp/instance.hpp index de5da391b4..d9424ff750 100644 --- a/libcaf_io/caf/io/basp/instance.hpp +++ b/libcaf_io/caf/io/basp/instance.hpp @@ -43,7 +43,7 @@ class instance { /// Provides a callback-based interface for certain BASP events. class callee { public: - explicit callee(actor_system& sys, proxy_registry::backend& mgm); + explicit callee(actor_system& sys, proxy_registry::backend& backend); virtual ~callee(); @@ -181,15 +181,15 @@ class instance { } /// Writes a header followed by its payload to `storage`. - void write(execution_unit* ctx, buffer_type& storage, header& hdr, - payload_writer* writer = nullptr); + void write(execution_unit* ctx, buffer_type& buf, header& hdr, + payload_writer* pw = nullptr); /// Writes the server handshake containing the information of the /// actor published at `port` to `buf`. If `port == none` or /// if no actor is published at this port then a standard handshake is /// written (e.g. used when establishing direct connections on-the-fly). void write_server_handshake(execution_unit* ctx, - buffer_type& buf, optional port); + buffer_type& out_buf, optional port); /// Writes the client handshake to `buf`. void write_client_handshake(execution_unit* ctx, @@ -202,7 +202,7 @@ class instance { /// Writes a `kill_proxy` to `buf`. void write_kill_proxy(execution_unit* ctx, buffer_type& buf, const node_id& dest_node, actor_id aid, - const error& fail_state); + const error& rsn); /// Writes a `heartbeat` to `buf`. void write_heartbeat(execution_unit* ctx, diff --git a/libcaf_io/caf/io/basp/routing_table.hpp b/libcaf_io/caf/io/basp/routing_table.hpp index db43d8c8a7..e5b34dd73b 100644 --- a/libcaf_io/caf/io/basp/routing_table.hpp +++ b/libcaf_io/caf/io/basp/routing_table.hpp @@ -75,7 +75,7 @@ class routing_table { /// Adds a new direct route to the table. /// @pre `hdl != invalid_connection_handle && nid != none` - void add_direct(const connection_handle& hdl, const node_id& dest); + void add_direct(const connection_handle& hdl, const node_id& nid); /// Adds a new indirect route to the table. bool add_indirect(const node_id& hop, const node_id& dest); diff --git a/libcaf_io/caf/io/basp_broker.hpp b/libcaf_io/caf/io/basp_broker.hpp index d90b2659d0..69563ea578 100644 --- a/libcaf_io/caf/io/basp_broker.hpp +++ b/libcaf_io/caf/io/basp_broker.hpp @@ -42,9 +42,9 @@ namespace caf { namespace io { struct basp_broker_state : proxy_registry::backend, basp::instance::callee { - basp_broker_state(broker* self); + basp_broker_state(broker* selfptr); - ~basp_broker_state(); + ~basp_broker_state() override; // inherited from proxy_registry::backend strong_actor_ptr make_proxy(node_id nid, actor_id aid) override; @@ -57,7 +57,7 @@ struct basp_broker_state : proxy_registry::backend, basp::instance::callee { std::set& sigs) override; // inherited from basp::instance::listener - void purge_state(const node_id& id) override; + void purge_state(const node_id& nid) override; // inherited from basp::instance::listener void proxy_announced(const node_id& nid, actor_id aid) override; @@ -66,17 +66,17 @@ struct basp_broker_state : proxy_registry::backend, basp::instance::callee { void kill_proxy(const node_id& nid, actor_id aid, const error& rsn) override; // inherited from basp::instance::listener - void deliver(const node_id& source_node, actor_id source_actor, - actor_id dest_actor, message_id mid, + void deliver(const node_id& src_nid, actor_id src_aid, + actor_id dest_aid, message_id mid, std::vector& stages, message& msg) override; // inherited from basp::instance::listener - void deliver(const node_id& source_node, actor_id source_actor, - atom_value dest_actor, message_id mid, + void deliver(const node_id& src_nid, actor_id src_aid, + atom_value dest_name, message_id mid, std::vector& stages, message& msg) override; // called from both overriden functions - void deliver(const node_id& source_node, actor_id source_actor, + void deliver(const node_id& src_nid, actor_id src_aid, strong_actor_ptr dest, message_id mid, std::vector& stages, message& msg); @@ -85,7 +85,7 @@ struct basp_broker_state : proxy_registry::backend, basp::instance::callee { // inherited from basp::instance::listener void learned_new_node_directly(const node_id& nid, - bool was_known_indirectly_before) override; + bool was_indirectly_before) override; // inherited from basp::instance::listener void learned_new_node_indirectly(const node_id& nid) override; diff --git a/libcaf_io/caf/io/doorman.hpp b/libcaf_io/caf/io/doorman.hpp index 4418f9d75f..70a3f7c20e 100644 --- a/libcaf_io/caf/io/doorman.hpp +++ b/libcaf_io/caf/io/doorman.hpp @@ -40,15 +40,15 @@ using doorman_base = broker_servant; - ~middleman(); + ~middleman() override; /// Tries to open a port for other CAF instances to connect to. /// @experimental - expected open(uint16_t port, const char* in = nullptr, + expected open(uint16_t port, const char* cstr = nullptr, bool ru = false); /// Closes port `port` regardless of whether an actor is published to it. @@ -82,7 +82,7 @@ class middleman : public actor_system::module { /// @returns The actual port the OS uses after `bind()`. If `port == 0` /// the OS chooses a random high-level port. expected publish_local_groups(uint16_t port, - const char* addr = nullptr); + const char* in = nullptr); /// Unpublishes `whom` by closing `port` or all assigned ports if `port == 0`. /// @param whom Actor that should be unpublished at `port`. @@ -274,7 +274,7 @@ class middleman : public actor_system::module { } protected: - middleman(actor_system& ref); + middleman(actor_system& sys); private: template @@ -314,12 +314,12 @@ class middleman : public actor_system::module { expected remote_spawn_impl(const node_id& nid, std::string& name, message& args, - std::set ifs, + std::set s, duration timeout); expected publish(const strong_actor_ptr& whom, std::set sigs, - uint16_t port, const char* in, bool ru); + uint16_t port, const char* cstr, bool ru); expected unpublish(const actor_addr& whom, uint16_t port); diff --git a/libcaf_io/caf/io/middleman_actor.hpp b/libcaf_io/caf/io/middleman_actor.hpp index bb5c7f1e7d..ec09f328ea 100644 --- a/libcaf_io/caf/io/middleman_actor.hpp +++ b/libcaf_io/caf/io/middleman_actor.hpp @@ -108,7 +108,7 @@ using middleman_actor = replies_to::with>; /// @relates middleman_actor -middleman_actor make_middleman_actor(actor_system& sys, actor default_broker); +middleman_actor make_middleman_actor(actor_system& sys, actor db); } // namespace io } // namespace caf diff --git a/libcaf_io/caf/io/network/acceptor_manager.hpp b/libcaf_io/caf/io/network/acceptor_manager.hpp index 3ec9fb8c03..70ad3a6799 100644 --- a/libcaf_io/caf/io/network/acceptor_manager.hpp +++ b/libcaf_io/caf/io/network/acceptor_manager.hpp @@ -32,7 +32,7 @@ class acceptor_manager : public manager { public: acceptor_manager(abstract_broker* ptr); - ~acceptor_manager(); + ~acceptor_manager() override; /// Called by the underlying I/O device to indicate that /// a new connection is awaiting acceptance. diff --git a/libcaf_io/caf/io/network/default_multiplexer.hpp b/libcaf_io/caf/io/network/default_multiplexer.hpp index fc486a0afa..9abcdd74b5 100644 --- a/libcaf_io/caf/io/network/default_multiplexer.hpp +++ b/libcaf_io/caf/io/network/default_multiplexer.hpp @@ -63,7 +63,7 @@ # include #else # include -# include +# include # include #endif @@ -157,7 +157,7 @@ expected nonblocking(native_socket fd, bool new_value); expected tcp_nodelay(native_socket fd, bool new_value); /// Enables or disables `SIGPIPE` events from `fd`. -expected allow_sigpipe(native_socket fs, bool new_value); +expected allow_sigpipe(native_socket fd, bool new_value); /// Reads up to `len` bytes from `fd,` writing the received data /// to `buf`. Returns `true` as long as `fd` is readable and `false` @@ -181,7 +181,7 @@ class default_multiplexer; /// A socket I/O event handler. class event_handler { public: - event_handler(default_multiplexer& dm, native_socket fd); + event_handler(default_multiplexer& dm, native_socket sockfd); virtual ~event_handler(); @@ -243,7 +243,7 @@ class pipe_reader : public event_handler { pipe_reader(default_multiplexer& dm); void removed_from_loop(operation op) override; void handle_event(operation op) override; - void init(native_socket fd); + void init(native_socket sock_fd); resumable* try_read_next(); }; @@ -273,18 +273,18 @@ class default_multiplexer : public multiplexer { expected new_tcp_scribe(const std::string &, uint16_t) override; - expected assign_tcp_scribe(abstract_broker *ptr, + expected assign_tcp_scribe(abstract_broker *self, connection_handle hdl) override; connection_handle add_tcp_scribe(abstract_broker *, native_socket fd) override; expected add_tcp_scribe(abstract_broker *, - const std::string &h, + const std::string &host, uint16_t port) override; expected> - new_tcp_doorman(uint16_t p, const char *in, bool rflag) override; + new_tcp_doorman(uint16_t port, const char *in, bool reuse_addr) override; expected assign_tcp_doorman(abstract_broker *ptr, accept_handle hdl) override; @@ -298,7 +298,7 @@ class default_multiplexer : public multiplexer { explicit default_multiplexer(actor_system* sys); - ~default_multiplexer(); + ~default_multiplexer() override; supervisor_ptr make_supervisor() override; @@ -351,7 +351,7 @@ class default_multiplexer : public multiplexer { } } - void handle(const event& event); + void handle(const event& e); void handle_socket_event(native_socket fd, int mask, event_handler* ptr); diff --git a/libcaf_io/caf/io/network/manager.hpp b/libcaf_io/caf/io/network/manager.hpp index c6f4ec1510..c8468bd8ba 100644 --- a/libcaf_io/caf/io/network/manager.hpp +++ b/libcaf_io/caf/io/network/manager.hpp @@ -35,9 +35,9 @@ namespace network { /// for various I/O operations. class manager : public ref_counted { public: - manager(abstract_broker* parent_ptr); + manager(abstract_broker* ptr); - ~manager(); + ~manager() override; /// Sets the parent for this manager. /// @pre `parent() == nullptr` @@ -53,7 +53,7 @@ class manager : public ref_counted { /// Detach this manager from its parent and invoke `detach_message()`` /// if `invoke_detach_message == true`. - void detach(execution_unit* ctx, bool invoke_detach_message); + void detach(execution_unit* ctx, bool invoke_disconnect_message); /// Causes the manager to stop read operations on its I/O device. /// Unwritten bytes are still send before the socket will be closed. diff --git a/libcaf_io/caf/io/network/stream_manager.hpp b/libcaf_io/caf/io/network/stream_manager.hpp index dea2226c43..c9129d4c56 100644 --- a/libcaf_io/caf/io/network/stream_manager.hpp +++ b/libcaf_io/caf/io/network/stream_manager.hpp @@ -34,7 +34,7 @@ class stream_manager : public manager { public: stream_manager(abstract_broker* ptr); - ~stream_manager(); + ~stream_manager() override; /// Called by the underlying I/O device whenever it received data. /// @returns `true` if the manager accepts further reads, otherwise `false`. diff --git a/libcaf_io/caf/io/network/test_multiplexer.hpp b/libcaf_io/caf/io/network/test_multiplexer.hpp index cec9ec1641..38c5e33577 100644 --- a/libcaf_io/caf/io/network/test_multiplexer.hpp +++ b/libcaf_io/caf/io/network/test_multiplexer.hpp @@ -33,10 +33,10 @@ class test_multiplexer : public multiplexer { public: explicit test_multiplexer(actor_system* sys); - ~test_multiplexer(); + ~test_multiplexer() override; expected new_tcp_scribe(const std::string& host, - uint16_t port) override; + uint16_t port_hint) override; expected assign_tcp_scribe(abstract_broker* ptr, connection_handle hdl) override; @@ -45,10 +45,10 @@ class test_multiplexer : public multiplexer { expected add_tcp_scribe(abstract_broker* ptr, const std::string& host, - uint16_t port) override; + uint16_t desired_port) override; expected> - new_tcp_doorman(uint16_t port, const char*, bool) override; + new_tcp_doorman(uint16_t desired_port, const char*, bool) override; expected assign_tcp_doorman(abstract_broker* ptr, accept_handle hdl) override; @@ -63,9 +63,9 @@ class test_multiplexer : public multiplexer { void run() override; - void provide_scribe(std::string host, uint16_t port, connection_handle hdl); + void provide_scribe(std::string host, uint16_t desired_port, connection_handle hdl); - void provide_acceptor(uint16_t port, accept_handle hdl); + void provide_acceptor(uint16_t desired_port, accept_handle hdl); /// A buffer storing bytes. using buffer_type = std::vector; @@ -117,7 +117,7 @@ class test_multiplexer : public multiplexer { using pending_scribes_map = std::map, connection_handle>; - bool has_pending_scribe(std::string host, uint16_t port); + bool has_pending_scribe(std::string x, uint16_t y); /// Accepts a pending connect on `hdl`. bool accept_connection(accept_handle hdl); diff --git a/libcaf_io/caf/io/scribe.hpp b/libcaf_io/caf/io/scribe.hpp index d253dfb0ca..f48e0d3346 100644 --- a/libcaf_io/caf/io/scribe.hpp +++ b/libcaf_io/caf/io/scribe.hpp @@ -39,9 +39,9 @@ using scribe_base = broker_servant(1); + const auto& ptr = msg.get_as(1); if (!ptr) { CAF_LOG_DEBUG("received unlink message with invalid target"); return; @@ -545,7 +545,7 @@ behavior basp_broker::make_behavior() { [=](forward_atom, const node_id& dest_node, atom_value dest_name, const message& msg) -> result { auto cme = current_mailbox_element(); - if (!cme) + if (cme == nullptr) return sec::invalid_argument; auto& src = cme->sender; CAF_LOG_TRACE(CAF_ARG(src) diff --git a/libcaf_io/src/default_multiplexer.cpp b/libcaf_io/src/default_multiplexer.cpp index 9affaebbd6..5b761d364f 100644 --- a/libcaf_io/src/default_multiplexer.cpp +++ b/libcaf_io/src/default_multiplexer.cpp @@ -38,7 +38,7 @@ # include # include #else -# include +# include # include # include # include @@ -46,6 +46,8 @@ # include # include # include + +#include #endif using std::string; @@ -530,7 +532,7 @@ expected remote_port_of_fd(native_socket fd); new_element.events = static_cast(e.mask); new_element.revents = 0; int old_mask = 0; - if (e.ptr) { + if (e.ptr != nullptr) { old_mask = e.ptr->eventbf(); e.ptr->eventbf(e.mask); } @@ -558,9 +560,9 @@ expected remote_port_of_fd(native_socket fd); CAF_ASSERT(*j == e.ptr); i->events = static_cast(e.mask); } - if (e.ptr) { + if (e.ptr != nullptr) { auto remove_from_loop_if_needed = [&](int flag, operation flag_op) { - if ((old_mask & flag) && !(e.mask & flag)) { + if (((old_mask & flag) != 0) && ((e.mask & flag) == 0)) { e.ptr->removed_from_loop(flag_op); } }; @@ -647,7 +649,7 @@ multiplexer::supervisor_ptr default_multiplexer::make_supervisor() { explicit impl(default_multiplexer* thisptr) : this_(thisptr) { // nop } - ~impl() { + ~impl() override { auto ptr = this_; ptr->dispatch([=] { ptr->close_pipe(); }); } @@ -667,18 +669,18 @@ void default_multiplexer::handle_socket_event(native_socket fd, int mask, CAF_LOG_TRACE(CAF_ARG(fd) << CAF_ARG(mask)); CAF_ASSERT(ptr != nullptr); bool checkerror = true; - if (mask & input_mask) { + if ((mask & input_mask) != 0) { checkerror = false; // ignore read events if a previous event caused // this socket to be shut down for reading if (!ptr->read_channel_closed()) ptr->handle_event(operation::read); } - if (mask & output_mask) { + if ((mask & output_mask) != 0) { checkerror = false; ptr->handle_event(operation::write); } - if (checkerror && (mask & error_mask)) { + if (checkerror && ((mask & error_mask) != 0)) { CAF_LOG_DEBUG("error occured on socket:" << CAF_ARG(fd) << CAF_ARG(last_socket_error()) << CAF_ARG(last_socket_error_as_string())); @@ -705,7 +707,7 @@ default_multiplexer::~default_multiplexer() { // flush pipe before closing it nonblocking(pipe_.first, true); auto ptr = pipe_reader_.try_read_next(); - while (ptr) { + while (ptr != nullptr) { scheduler::abstract_coordinator::cleanup_and_release(ptr); ptr = pipe_reader_.try_read_next(); } @@ -1354,7 +1356,7 @@ expected new_tcp_connection(const std::string& host, optional preferred) { CAF_LOG_TRACE(CAF_ARG(host) << CAF_ARG(port) << CAF_ARG(preferred)); CAF_LOG_INFO("try to connect to:" << CAF_ARG(host) << CAF_ARG(port)); - auto res = interfaces::native_address(host, preferred); + auto res = interfaces::native_address(host, std::move(preferred)); if (!res) { CAF_LOG_INFO("no such host"); return make_error(sec::cannot_connect_to_node, "no such host", host, port); @@ -1438,7 +1440,7 @@ expected> new_tcp_acceptor_impl(uint16_t port, const char* addr, bool reuse_addr) { CAF_LOG_TRACE(CAF_ARG(port) << ", addr = " << (addr ? addr : "nullptr")); protocol proto = ipv6; - if (addr) { + if (addr != nullptr) { auto addrs = interfaces::native_address(addr); if (!addrs) return make_error(sec::cannot_open_port, "Invalid ADDR", addr); diff --git a/libcaf_io/src/instance.cpp b/libcaf_io/src/instance.cpp index 170f13db81..657e1d232d 100644 --- a/libcaf_io/src/instance.cpp +++ b/libcaf_io/src/instance.cpp @@ -88,7 +88,7 @@ connection_state instance::handle(execution_unit* ctx, auto e = bs(hdr); if (e) return err(); - if (payload) + if (payload != nullptr) bs.apply_raw(payload->size(), payload->data()); tbl_.flush(*path); notify(hdr, payload); @@ -307,7 +307,7 @@ size_t instance::remove_published_actor(uint16_t port, auto i = published_actors_.find(port); if (i == published_actors_.end()) return 0; - if (cb) + if (cb != nullptr) (*cb)(i->second.first, i->first); published_actors_.erase(i); return 1; @@ -321,7 +321,7 @@ size_t instance::remove_published_actor(const actor_addr& whom, if (port != 0) { auto i = published_actors_.find(port); if (i != published_actors_.end() && i->second.first == whom) { - if (cb) + if (cb != nullptr) (*cb)(i->second.first, port); published_actors_.erase(i); result = 1; @@ -330,7 +330,7 @@ size_t instance::remove_published_actor(const actor_addr& whom, auto i = published_actors_.begin(); while (i != published_actors_.end()) { if (i->second.first == whom) { - if (cb) + if (cb != nullptr) (*cb)(i->second.first, i->first); i = published_actors_.erase(i); ++result; @@ -371,7 +371,7 @@ void instance::write(execution_unit* ctx, buffer_type& buf, header& hdr, payload_writer* pw) { CAF_LOG_TRACE(CAF_ARG(hdr)); error err; - if (pw) { + if (pw != nullptr) { auto pos = buf.size(); // write payload first (skip first 72 bytes and write header later) char placeholder[basp::header_size]; @@ -408,18 +408,17 @@ void instance::write_server_handshake(execution_unit* ctx, auto e = sink(const_cast(ref)); if (e) return e; - if (pa) { + if (pa != nullptr) { auto i = pa->first ? pa->first->id() : invalid_actor_id; return sink(i, pa->second); - } else { - auto aid = invalid_actor_id; - std::set tmp; - return sink(aid, tmp); } + auto aid = invalid_actor_id; + std::set tmp; + return sink(aid, tmp); }); header hdr{message_type::server_handshake, 0, 0, version, this_node_, none, - pa && pa->first ? pa->first->id() : invalid_actor_id, + (pa != nullptr) && pa->first ? pa->first->id() : invalid_actor_id, invalid_actor_id}; write(ctx, out_buf, hdr, &writer); } diff --git a/libcaf_io/src/interfaces.cpp b/libcaf_io/src/interfaces.cpp index 6340a8510b..ed23eb4b77 100644 --- a/libcaf_io/src/interfaces.cpp +++ b/libcaf_io/src/interfaces.cpp @@ -46,6 +46,7 @@ #endif #include +#include #include "caf/detail/get_mac_addresses.hpp" @@ -72,7 +73,7 @@ void* fetch_in_addr(int family, sockaddr* addr) { int fetch_addr_str(bool get_ipv4, bool get_ipv6, char (&buf)[INET6_ADDRSTRLEN], sockaddr* addr) { - if (!addr) + if (addr == nullptr) return AF_UNSPEC; auto family = addr->sa_family; auto in_addr = fetch_in_addr(family, addr); @@ -172,11 +173,11 @@ void traverse_impl(std::initializer_list ps, F f) { } // namespace void interfaces::traverse(std::initializer_list ps, consumer f) { - traverse_impl(ps, f); + traverse_impl(ps, std::move(f)); } void interfaces::traverse(consumer f) { - traverse_impl({protocol::ethernet, protocol::ipv4, protocol::ipv6}, f); + traverse_impl({protocol::ethernet, protocol::ipv4, protocol::ipv6}, std::move(f)); } interfaces_map interfaces::list_all(bool include_localhost) { @@ -184,7 +185,7 @@ interfaces_map interfaces::list_all(bool include_localhost) { traverse_impl({protocol::ethernet, protocol::ipv4, protocol::ipv6}, [&](const char* name, protocol p, bool lo, const char* addr) { if (include_localhost || !lo) - result[name][p].push_back(addr); + result[name][p].emplace_back(addr); }); return result; } @@ -195,7 +196,7 @@ interfaces::list_addresses(bool include_localhost) { traverse_impl({protocol::ethernet, protocol::ipv4, protocol::ipv6}, [&](const char*, protocol p, bool lo, const char* addr) { if (include_localhost || !lo) - result[p].push_back(addr); + result[p].emplace_back(addr); }); return result; } @@ -206,7 +207,7 @@ interfaces::list_addresses(std::initializer_list procs, std::vector result; traverse_impl(procs, [&](const char*, protocol, bool lo, const char* addr) { if (include_localhost || !lo) - result.push_back(addr); + result.emplace_back(addr); }); return result; } @@ -225,7 +226,7 @@ interfaces::native_address(const std::string& host, if (preferred) hint.ai_family = *preferred == protocol::ipv4 ? AF_INET : AF_INET6; addrinfo* tmp = nullptr; - if (getaddrinfo(host.c_str(), nullptr, &hint, &tmp)) + if (getaddrinfo(host.c_str(), nullptr, &hint, &tmp) != 0) return none; std::unique_ptr addrs{tmp, freeaddrinfo}; char buffer[INET6_ADDRSTRLEN]; diff --git a/libcaf_io/src/manager.cpp b/libcaf_io/src/manager.cpp index 8c082e7f18..db80e13934 100644 --- a/libcaf_io/src/manager.cpp +++ b/libcaf_io/src/manager.cpp @@ -37,7 +37,7 @@ manager::~manager() { void manager::set_parent(abstract_broker* ptr) { if (!detached()) - parent_ = ptr ? ptr->ctrl() : nullptr; + parent_ = ptr != nullptr ? ptr->ctrl() : nullptr; } abstract_broker* manager::parent() { diff --git a/libcaf_io/src/middleman.cpp b/libcaf_io/src/middleman.cpp index 4fde00ae56..5021d5f74e 100644 --- a/libcaf_io/src/middleman.cpp +++ b/libcaf_io/src/middleman.cpp @@ -143,7 +143,7 @@ expected middleman::publish(const strong_actor_ptr& whom, if (!whom) return sec::cannot_publish_invalid_actor; std::string in; - if (cstr) + if (cstr != nullptr) in = cstr; auto f = make_function_view(actor_handle()); return f(publish_atom::value, port, std::move(whom), std::move(sigs), in, ru); @@ -310,15 +310,15 @@ void middleman::init(actor_system_config& cfg) { // nop } - void stop() { + void stop() override { // nop } - expected get(const std::string& group_name) { + expected get(const std::string& group_name) override { return parent_.remote_group(group_name); } - error load(deserializer&, group&) { + error load(deserializer&, group&) override { // never called, because we hand out group instances of the local module return sec::no_such_group_module; } diff --git a/libcaf_io/src/middleman_actor.cpp b/libcaf_io/src/middleman_actor.cpp index 886b999eaf..bf5f825b00 100644 --- a/libcaf_io/src/middleman_actor.cpp +++ b/libcaf_io/src/middleman_actor.cpp @@ -21,6 +21,7 @@ #include #include +#include #include "caf/sec.hpp" #include "caf/send.hpp" @@ -45,7 +46,7 @@ class middleman_actor_impl : public middleman_actor::base { public: middleman_actor_impl(actor_config& cfg, actor default_broker) : middleman_actor::base(cfg), - broker_(default_broker) { + broker_(std::move(default_broker)) { set_down_handler([=](down_msg& dm) { auto i = cached_.begin(); auto e = cached_.end(); diff --git a/libcaf_io/src/routing_table.cpp b/libcaf_io/src/routing_table.cpp index d83a5cffff..4b88184d11 100644 --- a/libcaf_io/src/routing_table.cpp +++ b/libcaf_io/src/routing_table.cpp @@ -46,8 +46,7 @@ optional routing_table::lookup(const node_id& target) { hdl = lookup_direct(hop); if (hdl != invalid_connection_handle) return route{parent_->wr_buf(hdl), hop, hdl}; - else - hops.erase(hops.begin()); + hops.erase(hops.begin()); } } return none; diff --git a/libcaf_io/test/basp.cpp b/libcaf_io/test/basp.cpp index f01287d361..fe654bfbc1 100644 --- a/libcaf_io/test/basp.cpp +++ b/libcaf_io/test/basp.cpp @@ -99,7 +99,7 @@ using namespace caf::io; namespace { -static constexpr uint32_t num_remote_nodes = 2; +constexpr uint32_t num_remote_nodes = 2; using buffer = std::vector; @@ -274,7 +274,7 @@ class fixture { void connect_node(node& n, optional ax = none, actor_id published_actor_id = invalid_actor_id, - set published_actor_ifs = std::set{}) { + const set& published_actor_ifs = std::set{}) { auto src = ax ? *ax : ahdl_; CAF_MESSAGE("connect remote node " << n.name << ", connection ID = " << n.connection.id() @@ -808,7 +808,7 @@ CAF_TEST(automatic_connection) { // create a dummy config server and respond to the name lookup CAF_MESSAGE("receive ConfigServ of jupiter"); network::address_listing res; - res[network::protocol::ipv4].push_back("jupiter"); + res[network::protocol::ipv4].emplace_back("jupiter"); mock(mars().connection, {basp::message_type::dispatch_message, 0, 0, 0, this_node(), this_node(), @@ -820,7 +820,7 @@ CAF_TEST(automatic_connection) { // send the scribe handle over to the BASP broker while (mpx()->has_pending_scribe("jupiter", 8080)) mpx()->flush_runnables(); - CAF_REQUIRE(mpx()->output_buffer(mars().connection).size() == 0); + CAF_REQUIRE(mpx()->output_buffer(mars().connection).empty()); // send handshake from jupiter mock(jupiter().connection, {basp::message_type::server_handshake, 0, 0, basp::version, diff --git a/libcaf_io/test/remote_actor.cpp b/libcaf_io/test/remote_actor.cpp index 684578af62..ce573de704 100644 --- a/libcaf_io/test/remote_actor.cpp +++ b/libcaf_io/test/remote_actor.cpp @@ -64,7 +64,7 @@ behavior make_pong_behavior() { }; } -behavior make_ping_behavior(event_based_actor* self, actor pong) { +behavior make_ping_behavior(event_based_actor* self, const actor& pong) { CAF_MESSAGE("ping with " << 0); self->send(pong, 0); return { @@ -101,7 +101,7 @@ behavior make_sort_behavior() { }; } -behavior make_sort_requester_behavior(event_based_actor* self, actor sorter) { +behavior make_sort_requester_behavior(event_based_actor* self, const actor& sorter) { self->send(sorter, std::vector{5, 4, 3, 2, 1}); return { [=](const std::vector& vec) { @@ -123,7 +123,7 @@ behavior fragile_mirror(event_based_actor* self) { }; } -behavior linking_actor(event_based_actor* self, actor buddy) { +behavior linking_actor(event_based_actor* self, const actor& buddy) { CAF_MESSAGE("link to mirror and send dummy message"); self->link_to(buddy); self->send(buddy, 42); diff --git a/libcaf_io/test/remote_group.cpp b/libcaf_io/test/remote_group.cpp index 919ac2f2c8..6cac9fe56f 100644 --- a/libcaf_io/test/remote_group.cpp +++ b/libcaf_io/test/remote_group.cpp @@ -79,7 +79,7 @@ struct await_reflector_reply_behavior { CAF_CHECK_EQUAL(str, "Hello reflector!"); CAF_CHECK_EQUAL(val, 5.0); if (++cnt == 7) { - for (auto actor : vec) + for (const auto& actor : vec) self->monitor(actor); self->set_down_handler([=](down_msg&) { if (++downs == 5) @@ -91,7 +91,7 @@ struct await_reflector_reply_behavior { // `grp` may be either local or remote void make_client_behavior(event_based_actor* self, - actor server, group grp) { + const actor& server, group grp) { self->set_default_handler(skip); self->spawn_in_group(grp, make_reflector_behavior); self->spawn_in_group(grp, make_reflector_behavior); diff --git a/libcaf_io/test/unpublish.cpp b/libcaf_io/test/unpublish.cpp index 99d4e94369..ec5a11a9f0 100644 --- a/libcaf_io/test/unpublish.cpp +++ b/libcaf_io/test/unpublish.cpp @@ -41,7 +41,7 @@ class dummy : public event_based_actor { // nop } - ~dummy() { + ~dummy() override { ++s_dtor_called; } diff --git a/libcaf_test/caf/test/dsl.hpp b/libcaf_test/caf/test/dsl.hpp index 4100c8f484..3878980ab7 100644 --- a/libcaf_test/caf/test/dsl.hpp +++ b/libcaf_test/caf/test/dsl.hpp @@ -49,7 +49,7 @@ T get(const U&); struct wildcard { }; -static constexpr wildcard _ = wildcard{}; +constexpr wildcard _ = wildcard{}; template class elementwise_compare_inspector { diff --git a/libcaf_test/caf/test/unit_test.hpp b/libcaf_test/caf/test/unit_test.hpp index 02e0c9cf4e..897eaeffbe 100644 --- a/libcaf_test/caf/test/unit_test.hpp +++ b/libcaf_test/caf/test/unit_test.hpp @@ -75,15 +75,15 @@ int main(int argc, char** argv); /// A sequence of *checks*. class test { public: - test(std::string name); + test(std::string test_name); virtual ~test(); size_t expected_failures() const; - void pass(std::string msg); + void pass(const std::string& msg); - void fail(std::string msg, bool expected); + void fail(const std::string& msg, bool expected); const std::string& name() const; @@ -113,7 +113,7 @@ class test_impl : public test { // nop } - virtual void run() override { + void run() override { T impl; impl.run(); } @@ -169,7 +169,7 @@ class logger { stream& operator<<(const char* cstr); - stream& operator<<(const std::string& str); + stream& operator<<(const std::string& x); std::string str() const; @@ -248,7 +248,7 @@ class engine { /// Adds a test to the engine. /// @param name The name of the suite. /// @param ptr The test to register. - static void add(const char* name, std::unique_ptr ptr); + static void add(const char* cstr_name, std::unique_ptr ptr); /// Invokes tests in all suites. /// @param colorize Whether to colorize the output. @@ -263,10 +263,10 @@ class engine { const std::string& log_file, int verbosity_console, int verbosity_file, - const std::string& suites, - const std::string& not_suites, - const std::string& tests, - const std::string& not_tests); + const std::string& suites_str, + const std::string& not_suites_str, + const std::string& tests_str, + const std::string& not_tests_str); /// Retrieves a UNIX terminal color code or an empty string based on the /// color configuration of the engine. diff --git a/libcaf_test/caf/test/unit_test_impl.hpp b/libcaf_test/caf/test/unit_test_impl.hpp index 9a1d794aa6..24e957a38b 100644 --- a/libcaf_test/caf/test/unit_test_impl.hpp +++ b/libcaf_test/caf/test/unit_test_impl.hpp @@ -108,12 +108,12 @@ size_t test::expected_failures() const { return expected_failures_; } -void test::pass(std::string msg) { +void test::pass(const std::string& msg) { ++good_; ::caf::test::logger::instance().massive() << " " << msg << '\n'; } -void test::fail(std::string msg, bool expected) { +void test::fail(const std::string& msg, bool expected) { ++bad_; ::caf::test::logger::instance().massive() << " " << msg << '\n'; if (expected) { @@ -142,12 +142,11 @@ namespace detail { const char* fill(size_t line) { if (line < 10) return " "; - else if (line < 100) + if (line < 100) return " "; - else if (line < 1000) + if (line < 1000) return " "; - else - return " "; + return " "; } void remove_trailing_spaces(std::string& x) { @@ -293,7 +292,7 @@ void engine::max_runtime(int value) { } void engine::add(const char* cstr_name, std::unique_ptr ptr) { - std::string name = cstr_name ? cstr_name : ""; + std::string name = cstr_name != nullptr ? cstr_name : ""; auto& suite = instance().suites_[name]; for (auto& x : suite) { if (x->name() == ptr->name()) { @@ -588,7 +587,7 @@ int main(int argc, char** argv) { constexpr bool colorize = false; # else auto color_support = []() -> bool { - if (!isatty(0)) + if (isatty(0) == 0) return false; char ttybuf[50]; if (ttyname_r(0, ttybuf, sizeof(ttybuf)) != 0) diff --git a/tools/caf-run.cpp b/tools/caf-run.cpp index b96299ea85..ee02be7b6e 100644 --- a/tools/caf-run.cpp +++ b/tools/caf-run.cpp @@ -134,18 +134,18 @@ bool run_ssh(actor_system& system, const string& wdir, auto packed = encode_base64(full_cmd); std::ostringstream oss; oss << "ssh -Y -o ServerAliveInterval=60 " << host - << " \"echo " << packed << " | base64 --decode | /bin/sh\""; + << R"( "echo )" << packed << R"( | base64 --decode | /bin/sh")"; //return system(oss.str().c_str()); string line; std::cout << "popen: " << oss.str() << std::endl; auto fp = popen(oss.str().c_str(), "r"); - if (!fp) + if (fp == nullptr) return false; char buf[512]; auto eob = buf + sizeof(buf); // end-of-buf auto pred = [](char c) { return c == 0 || c == '\n'; }; scoped_actor self{system}; - while (fgets(buf, sizeof(buf), fp)) { + while (fgets(buf, sizeof(buf), fp) != nullptr) { auto i = buf; auto e = std::find_if(i, eob, pred); line.insert(line.end(), i, e); diff --git a/tools/caf-vec.cpp b/tools/caf-vec.cpp index 89cf334ffa..4613b0e61c 100644 --- a/tools/caf-vec.cpp +++ b/tools/caf-vec.cpp @@ -22,7 +22,7 @@ using vector_timestamp = std::vector; // removes leading and trailing whitespaces void trim(string& s) { - auto not_space = [](char c) { return !isspace(c); }; + auto not_space = [](char c) { return isspace(c) == 0; }; // trim left s.erase(s.begin(), find_if(s.begin(), s.end(), not_space)); // trim right @@ -46,7 +46,7 @@ std::istream& skip_to_next_line(std::istream& in) { std::istream& skip_word(std::istream& in) { skip_whitespaces(in); - auto nonspace = [](char x) { return isprint(x) && !isspace(x); }; + auto nonspace = [](char x) { return (isprint(x) != 0) && (isspace(x) == 0); }; while (nonspace(static_cast(in.peek()))) in.get(); return in; @@ -450,7 +450,7 @@ bool field_key_compare(const std::pair& x, static_cast(0) #define CHECK_NO_FIELDS() \ - if (y.fields.size() > 0) \ + if (!y.fields.empty()) \ return sec::invalid_argument; expected parse_event(const enhanced_log_entry& x) { @@ -622,7 +622,7 @@ void second_pass(blocking_actor* self, const group& grp, if (vl >= verbosity_level::noisy) aout(self) << "broadcast event from " << nid << ": " << deep_to_string(x) << endl; - if (self) + if (self != nullptr) self->send(grp, x); }; // fetch message from another node via the group @@ -869,9 +869,9 @@ void caf_main(actor_system& sys, const config& cfg) { } // do a second pass for all log files // first line is the regex to parse the remainder of the file - out << "(?\\S+) (?\\d+) (?\\S+) " - << "(?\\S+) (?\\S+) (?\\S+) (?\\S+) " - << "(?\\S+):(?\\d+) (?.+)" + out << R"((?\S+) (?\d+) (?\S+) )" + << R"((?\S+) (?\S+) (?\S+) (?\S+) )" + << R"((?\S+):(?\d+) (?.+))" << endl; // second line is the separator for multiple runs out << endl;