Skip to content

Commit

Permalink
Merge pull request #73 from eclipse-zenoh/warning_fixed
Browse files Browse the repository at this point in the history
old style type cast warning fixed
  • Loading branch information
milyin authored Sep 25, 2023
2 parents 9fec0f4 + eb84172 commit d3f927d
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 17 deletions.
11 changes: 0 additions & 11 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,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)
Expand Down
1 change: 0 additions & 1 deletion examples/simple/universal/build/_deps/cpp_wrapper-src
Submodule cpp_wrapper-src deleted from d93144
1 change: 0 additions & 1 deletion examples/simple/universal/build/_deps/zenohc_backend-src
Submodule zenohc_backend-src deleted from 590bea
Submodule zenohpico_backend-src deleted from 3e366a
2 changes: 1 addition & 1 deletion include/zenohcxx/impl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(id.id[i]);
return os;
}

Expand Down
2 changes: 0 additions & 2 deletions include/zenohpico.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#define __ZENOHCXX_ZENOHPICO
#undef __ZENOHCXX_ZENOHC

typedef bool _Bool;

#include "zenoh-pico.h"
#include "zenohcxx/base.hxx"

Expand Down
21 changes: 21 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
30 changes: 30 additions & 0 deletions tests/build/warnings.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// 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, <[email protected]>
//

// Disable 'old-style-cast` warning for C headers only
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
#ifdef ZENOHCXX_ZENOHPICO
#include "zenoh-pico.h"
#endif
#ifdef ZENOHCXX_ZENOHC
#include "zenoh.h"
#endif
#pragma GCC diagnostic pop

#include "zenoh.hxx"

using namespace zenoh;

int main() { return 0; }

0 comments on commit d3f927d

Please sign in to comment.