From 820033539ae301bf0d872e96e73d3f8291ac0780 Mon Sep 17 00:00:00 2001 From: Michael Ilyin Date: Tue, 19 Sep 2023 14:20:06 +0200 Subject: [PATCH 1/5] followup to --- examples/CMakeLists.txt | 7 ++++++- include/zenohcxx/impl.hxx | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index f081cd77..48867314 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -38,7 +38,12 @@ function(add_example file mode lib) if(MSVC) target_compile_options(${target} PRIVATE /W4 /WX) else() - target_compile_options(${target} PRIVATE -Wall -Wextra -Wpedantic -Werror) + target_compile_options(${target} PRIVATE + -Wall + -Wextra + -Wpedantic + -Wold-style-cast + -Werror) endif() endfunction() diff --git a/include/zenohcxx/impl.hxx b/include/zenohcxx/impl.hxx index 46a8fad8..243099cc 100644 --- a/include/zenohcxx/impl.hxx +++ b/include/zenohcxx/impl.hxx @@ -39,7 +39,7 @@ inline ::z_bytes_t z::BytesView::init(const uint8_t* start, size_t len) { inline std::ostream& operator<<(std::ostream& os, const z::Id& id) { for (size_t i = 0; id.id[i] != 0 && i < 16; i++) - os << std::hex << std::setfill('0') << std::setw(2) << (int)id.id[i]; + os << std::hex << std::setfill('0') << std::setw(2) << static_cast(id.id[i]); return os; } From 34fc2cbcde9469d95a1ee595e54c732256cc79f2 Mon Sep 17 00:00:00 2001 From: Michael Ilyin Date: Tue, 19 Sep 2023 15:27:02 +0200 Subject: [PATCH 2/5] incorrectly added build dirs removed --- examples/simple/universal/build/_deps/cpp_wrapper-src | 1 - examples/simple/universal/build/_deps/zenohc_backend-src | 1 - examples/simple/universal/build/_deps/zenohpico_backend-src | 1 - 3 files changed, 3 deletions(-) delete mode 160000 examples/simple/universal/build/_deps/cpp_wrapper-src delete mode 160000 examples/simple/universal/build/_deps/zenohc_backend-src delete mode 160000 examples/simple/universal/build/_deps/zenohpico_backend-src diff --git a/examples/simple/universal/build/_deps/cpp_wrapper-src b/examples/simple/universal/build/_deps/cpp_wrapper-src deleted file mode 160000 index d93144d4..00000000 --- a/examples/simple/universal/build/_deps/cpp_wrapper-src +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d93144d49ad2b700c86c1f8fb640581576f56c73 diff --git a/examples/simple/universal/build/_deps/zenohc_backend-src b/examples/simple/universal/build/_deps/zenohc_backend-src deleted file mode 160000 index 590bea93..00000000 --- a/examples/simple/universal/build/_deps/zenohc_backend-src +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 590bea934f7642261405ae8cbfa8bf4834d0bfe5 diff --git a/examples/simple/universal/build/_deps/zenohpico_backend-src b/examples/simple/universal/build/_deps/zenohpico_backend-src deleted file mode 160000 index 3e366a57..00000000 --- a/examples/simple/universal/build/_deps/zenohpico_backend-src +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3e366a575e472e4f28b5a97007b2a5c1ed9e17b9 From 900a3b7460aab22df6f9d86f129903d5c39bccf6 Mon Sep 17 00:00:00 2001 From: Michael Ilyin Date: Tue, 19 Sep 2023 16:34:40 +0200 Subject: [PATCH 3/5] builld warnings test in tests --- examples/CMakeLists.txt | 1 - tests/CMakeLists.txt | 21 +++++++++++++++++++++ tests/build/warnings.cxx | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 tests/build/warnings.cxx diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 48867314..762b2d80 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -42,7 +42,6 @@ function(add_example file mode lib) -Wall -Wextra -Wpedantic - -Wold-style-cast -Werror) endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6dc58d08..a829e4a0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -34,3 +34,24 @@ foreach(file ${files}) add_test_instance(${file} zenohpico zenohcxx::zenohpico) endforeach() +function(set_strict_warnings file mode) + get_filename_component(filename ${file} NAME_WE) + set(target ${filename}_${mode}) + # Enable all warnings and treat warnings as errors + # to check that library can be built in maximally strict mode + if(MSVC) + target_compile_options(${target} PRIVATE /W4 /WX) + else() + target_compile_options(${target} PRIVATE + -Wall + -Wextra + -Wpedantic + -Wold-style-cast + -Werror) + endif() +endfunction() + +add_test_instance(${CMAKE_CURRENT_SOURCE_DIR}/build/warnings.cxx zenohc zenohcxx::zenohc::static) +add_test_instance(${CMAKE_CURRENT_SOURCE_DIR}/build/warnings.cxx zenohpico zenohcxx::zenohpico) +set_strict_warnings(${CMAKE_CURRENT_SOURCE_DIR}/build/warnings.hxx zenohc) +set_strict_warnings(${CMAKE_CURRENT_SOURCE_DIR}/build/warnings.hxx zenohpico) diff --git a/tests/build/warnings.cxx b/tests/build/warnings.cxx new file mode 100644 index 00000000..c22c28ef --- /dev/null +++ b/tests/build/warnings.cxx @@ -0,0 +1,33 @@ +// +// Copyright (c) 2023 ZettaScale Technology +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, +// + +// Disable 'old-style-cast` warning for C headers only +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" +#ifdef ZENOHCXX_ZENOHPICO +typedef bool _Bool; +#include "zenoh-pico.h" +#endif +#ifdef ZENOHCXX_ZENOHC +#include "zenoh.h" +#endif +#pragma GCC diagnostic pop + +#include "zenoh.hxx" + +int main() { + std::string foo = "foo"; + zenoh::KeyExprView kfoo(foo); + return 0; +} \ No newline at end of file From 29bcef4f342d4e6ee748e4c32cd2b97c9520622c Mon Sep 17 00:00:00 2001 From: Michael Ilyin Date: Fri, 22 Sep 2023 16:15:28 +0200 Subject: [PATCH 4/5] typedef _Bool removed --- include/zenohpico.hxx | 2 -- tests/build/warnings.cxx | 9 +++------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/include/zenohpico.hxx b/include/zenohpico.hxx index e7f69888..15817258 100644 --- a/include/zenohpico.hxx +++ b/include/zenohpico.hxx @@ -16,8 +16,6 @@ #define __ZENOHCXX_ZENOHPICO #undef __ZENOHCXX_ZENOHC -typedef bool _Bool; - #include "zenoh-pico.h" #include "zenohcxx/base.hxx" diff --git a/tests/build/warnings.cxx b/tests/build/warnings.cxx index c22c28ef..0697130a 100644 --- a/tests/build/warnings.cxx +++ b/tests/build/warnings.cxx @@ -16,7 +16,6 @@ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wold-style-cast" #ifdef ZENOHCXX_ZENOHPICO -typedef bool _Bool; #include "zenoh-pico.h" #endif #ifdef ZENOHCXX_ZENOHC @@ -26,8 +25,6 @@ typedef bool _Bool; #include "zenoh.hxx" -int main() { - std::string foo = "foo"; - zenoh::KeyExprView kfoo(foo); - return 0; -} \ No newline at end of file +using namespace zenoh; + +int main() { return 0; } \ No newline at end of file From eb841723759348906eae1100b260ecd98431c040 Mon Sep 17 00:00:00 2001 From: Michael Ilyin Date: Fri, 22 Sep 2023 16:37:43 +0200 Subject: [PATCH 5/5] remove strinct warnings check from examples --- examples/CMakeLists.txt | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 762b2d80..788e3a91 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -30,21 +30,6 @@ 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, enabling it for examples only, but not for the library target itself - # is a good compromise. It guarantees the continuous checking the code and do not - # breaks dependent projects if warnings are mistakenly introduced in the library. - 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)