Skip to content

Commit

Permalink
some warnings removed
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Sep 15, 2023
1 parent c71dd15 commit 283d753
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 18 deletions.
10 changes: 10 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/zenohc/zc_simple.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Session>(open(std::move(config)));
session.put("demo/example/simple", "Simple!");
Expand Down
2 changes: 1 addition & 1 deletion examples/universal/z_pong.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion examples/universal/z_pull.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int _main(int argc, char **argv) {
auto subscriber = expect<PullSubscriber>(session.declare_pull_subscriber(keyexpr, data_handler));

printf("Press <enter> to pull data...\n");
char c = 0;
int c = 0;
while (c != 'q') {
c = getchar();
if (c == -1) {
Expand Down
2 changes: 1 addition & 1 deletion examples/universal/z_queryable.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ int _main(int argc, char **argv) {
auto queryable = expect<Queryable>(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) {
Expand Down
2 changes: 1 addition & 1 deletion examples/universal/z_sub.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int _main(int argc, char **argv) {
auto subscriber = expect<Subscriber>(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) {
Expand Down
4 changes: 2 additions & 2 deletions include/zenohcxx/api.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/zenohcxx/base.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
};
Expand Down
24 changes: 14 additions & 10 deletions include/zenohcxx/impl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ inline bool z::Query::reply_impl(z::KeyExprView key, const z::BytesView& payload
inline std::variant<z::Config, ErrorMessage> 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";
}
Expand All @@ -203,7 +203,7 @@ inline std::variant<z::Config, ErrorMessage> config_from_file(const char* path)
inline std::variant<z::Config, ErrorMessage> 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";
}
Expand All @@ -212,7 +212,7 @@ inline std::variant<z::Config, ErrorMessage> config_from_str(const char* s) {
inline std::variant<z::Config, ErrorMessage> 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";
}
Expand All @@ -230,13 +230,13 @@ inline std::variant<z::ShmManager, z::ErrorMessage> 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::Shmbuf, z::ErrorMessage> 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
Expand Down Expand Up @@ -502,7 +502,7 @@ inline std::variant<z::Queryable, ErrorMessage> 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";
}
Expand All @@ -514,7 +514,7 @@ inline std::variant<z::Subscriber, ErrorMessage> 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";
}
Expand All @@ -525,7 +525,7 @@ inline std::variant<z::PullSubscriber, ErrorMessage> 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";
}
Expand All @@ -535,7 +535,7 @@ inline std::variant<z::Publisher, ErrorMessage> 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";
}
Expand All @@ -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<z::Session, z::ErrorMessage> open(z::Config&& config, bool start_background_tasks) {
inline std::variant<z::Session, z::ErrorMessage> 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";
Expand Down

0 comments on commit 283d753

Please sign in to comment.