diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 788e3a91..d7d096d7 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -30,6 +30,16 @@ function(add_example file mode lib) target_link_libraries(${target} PUBLIC ${lib}) set_property(TARGET ${target} PROPERTY LANGUAGE CXX) set_property(TARGET ${target} PROPERTY CXX_STANDARD 17) + + # Enable all warnings and treat warnings as errors only when building examples. + # Supposedly this is a good compromise between continous checking the code and not + # breaking dependent projects. + if(MSVC) + target_compile_options(${target} PRIVATE /W4 /WX) + else() + target_compile_options(${target} PRIVATE -Wall -Wextra -Wpedantic -Werror) + endif() + endfunction() function(add_examples glob mode lib) diff --git a/examples/simple/zenohc/zc_simple.cxx b/examples/simple/zenohc/zc_simple.cxx index 7f8d0962..11410c48 100644 --- a/examples/simple/zenohc/zc_simple.cxx +++ b/examples/simple/zenohc/zc_simple.cxx @@ -19,7 +19,7 @@ #include "zenohc.hxx" using namespace zenohc; -int main(int argc, char **argv) { +int main(int, char **) { Config config; auto session = expect(open(std::move(config))); session.put("demo/example/simple", "Simple!"); diff --git a/examples/universal/z_pong.cxx b/examples/universal/z_pong.cxx index db221d97..9717c691 100644 --- a/examples/universal/z_pong.cxx +++ b/examples/universal/z_pong.cxx @@ -18,7 +18,7 @@ #include "zenoh.hxx" using namespace zenoh; -int _main(int argc, char **argv) { +int _main(int, char **) { Config config; std::cout << "Opening session...\n"; diff --git a/examples/universal/z_pull.cxx b/examples/universal/z_pull.cxx index ae786e79..64f892bb 100644 --- a/examples/universal/z_pull.cxx +++ b/examples/universal/z_pull.cxx @@ -64,7 +64,7 @@ int _main(int argc, char **argv) { auto subscriber = expect(session.declare_pull_subscriber(keyexpr, data_handler)); printf("Press to pull data...\n"); - char c = 0; + int c = 0; while (c != 'q') { c = getchar(); if (c == -1) { diff --git a/examples/universal/z_queryable.cxx b/examples/universal/z_queryable.cxx index cf04b3a2..4550fd95 100644 --- a/examples/universal/z_queryable.cxx +++ b/examples/universal/z_queryable.cxx @@ -84,7 +84,7 @@ int _main(int argc, char **argv) { auto queryable = expect(session.declare_queryable(keyexpr, {on_query, on_drop_queryable})); printf("Enter 'q' to quit...\n"); - char c = 0; + int c = 0; while (c != 'q') { c = getchar(); if (c == -1) { diff --git a/examples/universal/z_sub.cxx b/examples/universal/z_sub.cxx index 38a5ec32..0d39389b 100644 --- a/examples/universal/z_sub.cxx +++ b/examples/universal/z_sub.cxx @@ -63,7 +63,7 @@ int _main(int argc, char **argv) { auto subscriber = expect(session.declare_subscriber(keyexpr, data_handler)); printf("Enter 'q' to quit...\n"); - char c = 0; + int c = 0; while (c != 'q') { c = getchar(); if (c == -1) { diff --git a/include/zenohcxx/api.hxx b/include/zenohcxx/api.hxx index 3394f886..296037f7 100644 --- a/include/zenohcxx/api.hxx +++ b/include/zenohcxx/api.hxx @@ -499,7 +499,7 @@ struct KeyExprView : public Copyable<::z_keyexpr_t> { /// In debug mode falis on assert if passed string is not a valid key expression /// @param name the null-terminated string representing a key expression /// @param _unchecked the empty type used to distinguish checked and unchecked construncting of KeyExprView - KeyExprView(const char* name, z::KeyExprUnchecked _unchecked) : Copyable(::z_keyexpr_unchecked(name)) { + KeyExprView(const char* name, z::KeyExprUnchecked) : Copyable(::z_keyexpr_unchecked(name)) { assert(keyexpr_is_canon(name)); } /// @brief Constructs an instance from a ``std::string`` representing a key expression. @@ -1399,7 +1399,7 @@ struct PublisherDeleteOptions : public Copyable<::z_publisher_delete_options_t> /// @brief Equality operator /// @param v the other ``PublisherDeleteOptions`` to compare with /// @return true if the two values are equal - bool operator==(const z::PublisherOptions& v) const { return true; } + bool operator==(const z::PublisherOptions&) const { return true; } /// @brief Inequality operator /// @param v the other ``PublisherDeleteOptions`` to compare with diff --git a/include/zenohcxx/base.hxx b/include/zenohcxx/base.hxx index 029253fb..c8306ab2 100644 --- a/include/zenohcxx/base.hxx +++ b/include/zenohcxx/base.hxx @@ -43,7 +43,7 @@ struct Copyable : public ZC_COPYABLE_TYPE { /// Default constructor is deleted Copyable() = delete; // May be overloaded in derived structs with corresponding z_XXX_default function /// Copying is allowed - Copyable(const Copyable& v) { *this = v; } + Copyable(const Copyable&) = default; /// Construct from wrapped zenoh-c / zenoh-pico structure Copyable(ZC_COPYABLE_TYPE v) : ZC_COPYABLE_TYPE(v) {} }; diff --git a/include/zenohcxx/impl.hxx b/include/zenohcxx/impl.hxx index 20d3054e..d9517a4f 100644 --- a/include/zenohcxx/impl.hxx +++ b/include/zenohcxx/impl.hxx @@ -194,7 +194,7 @@ inline bool z::Query::reply_impl(z::KeyExprView key, const z::BytesView& payload inline std::variant config_from_file(const char* path) { z::Config config(::zc_config_from_file(path)); if (config.check()) { - return std::move(config); + return config; } else { return "Failed to create config from file"; } @@ -203,7 +203,7 @@ inline std::variant config_from_file(const char* path) inline std::variant config_from_str(const char* s) { z::Config config(::zc_config_from_str(s)); if (config.check()) { - return std::move(config); + return config; } else { return "Failed to create config from string"; } @@ -212,7 +212,7 @@ inline std::variant config_from_str(const char* s) { inline std::variant config_client(const z::StrArrayView& peers) { z::Config config(::z_config_client(peers.val, peers.len)); if (config.check()) { - return std::move(config); + return config; } else { return "Failed to create config from list of peers"; } @@ -230,13 +230,13 @@ inline std::variant shm_manager_new(const z::Ses uintptr_t size) { z::ShmManager shm_manager(session, id, size); if (!shm_manager.check()) return "Failed to create shm manager"; - return std::move(shm_manager); + return shm_manager; } inline std::variant z::ShmManager::alloc(uintptr_t capacity) const { auto shmbuf = z::Shmbuf(std::move(::zc_shm_alloc(&_0, capacity))); if (!shmbuf.check()) return "Failed to allocate shared memor buffer"; - return std::move(shmbuf); + return shmbuf; } #endif @@ -502,7 +502,7 @@ inline std::variant z::Session::declare_queryable_im auto c = callback.take(); z::Queryable queryable(::z_declare_queryable(loan(), keyexpr, z_move(c), options)); if (queryable.check()) { - return std::move(queryable); + return queryable; } else { return "Unable to create queryable"; } @@ -514,7 +514,7 @@ inline std::variant z::Session::declare_subscriber_ auto c = callback.take(); z::Subscriber subscriber(::z_declare_subscriber(loan(), keyexpr, z_move(c), options)); if (subscriber.check()) { - return std::move(subscriber); + return subscriber; } else { return "Unable to create subscriber"; } @@ -525,7 +525,7 @@ inline std::variant z::Session::declare_pull_su auto c = callback.take(); z::PullSubscriber pull_subscriber(::z_declare_pull_subscriber(loan(), keyexpr, z_move(c), options)); if (pull_subscriber.check()) { - return std::move(pull_subscriber); + return pull_subscriber; } else { return "Unable to create pull subscriber"; } @@ -535,7 +535,7 @@ inline std::variant z::Session::declare_publisher_im const PublisherOptions* options) { z::Publisher publisher(::z_declare_publisher(loan(), keyexpr, options)); if (publisher.check()) { - return std::move(publisher); + return publisher; } else { return "Unable to create publisher"; } @@ -546,7 +546,11 @@ inline ::z_owned_session_t z::Session::_z_open(z::Config&& v) { return ::z_open(z_move(config)); } -inline std::variant open(z::Config&& config, bool start_background_tasks) { +inline std::variant open(z::Config&& config, bool +#ifdef __ZENOHCXX_ZENOHPICO + start_background_tasks +#endif +) { z::Session session(std::move(config)); if (!session.check()) { return "Unable to open session";