Skip to content

Commit

Permalink
[#555] Introduce TREAT_WARNING_AS_ERROR cmake flag; fix C++ warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
elfenpiff committed Dec 20, 2024
1 parent 29c0179 commit 9234805
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ jobs:
- name: Build language bindings
run: |
cmake -S . -B target/ffi/build -DBUILD_EXAMPLES=ON -DBUILD_TESTING=ON ${{ matrix.mode.cmake-build-type }} ${{ matrix.mode.cmake-cxx-flags }} ${{ matrix.cmake-build-system-generator }} -DCMAKE_INSTALL_PREFIX=target/ffi/install -DCMAKE_PREFIX_PATH="${{ github.workspace }}/target/iceoryx/install"
cmake -S . -B target/ffi/build -DBUILD_EXAMPLES=ON -DBUILD_TESTING=ON -DTREAT_WARNING_AS_ERROR=ON ${{ matrix.mode.cmake-build-type }} ${{ matrix.mode.cmake-cxx-flags }} ${{ matrix.cmake-build-system-generator }} -DCMAKE_INSTALL_PREFIX=target/ffi/install -DCMAKE_PREFIX_PATH="${{ github.workspace }}/target/iceoryx/install"
cmake --build target/ffi/build ${{ matrix.mode.cmake-build-config }}
cmake --install target/ffi/build ${{ matrix.mode.cmake-build-config }}
Expand Down
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ add_option(
DEFAULT_VALUE OFF
)

add_option(
NAME TREAT_WARNING_AS_ERROR
DESCRIPTION "Fails if the compiler emits a warning"
DEFAULT_VALUE OFF
)

add_param(
NAME RUST_TARGET_TRIPLET
DESCRIPTION "The target triplet for cross compilation, e.g. 'aarch64-unknown-linux-gnu'"
Expand Down Expand Up @@ -104,6 +110,11 @@ add_rust_feature(
RUST_FEATURE "iceoryx2/logger_tracing"
)

if(TREAT_WARNING_AS_ERROR)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wall -Wextra -Wpedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -Wpedantic")
endif()

if(SANITIZERS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize=undefined")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=undefined")
Expand Down
2 changes: 2 additions & 0 deletions iceoryx2-ffi/cxx/src/messaging_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ auto operator<<(std::ostream& stream, const iox2::MessagingPattern& value) -> st
switch (value) {
case iox2::MessagingPattern::PublishSubscribe:
stream << "iox2::MessagingPattern::PublishSubscribe";
break;
case iox2::MessagingPattern::Event:
stream << "iox2::MessagingPattern::Event";
break;
}
return stream;
}
1 change: 1 addition & 0 deletions iceoryx2-ffi/cxx/src/port_factory_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ auto PortFactoryEvent<S>::dynamic_config() const -> const DynamicConfigEvent& {
template <ServiceType S>
auto PortFactoryEvent<S>::nodes(const iox::function<CallbackProgression(NodeState<S>)>& callback) const
-> iox::expected<void, NodeListFailure> {
static_cast<void>(callback);
IOX_TODO();
}

Expand Down
3 changes: 3 additions & 0 deletions iceoryx2-ffi/cxx/src/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ auto Service<S>::details(const ServiceName& service_name,
const ConfigView config,
const MessagingPattern messaging_pattern)
-> iox::expected<iox::optional<ServiceDetails<S>>, ServiceDetailsError> {
static_cast<void>(service_name);
static_cast<void>(config);
static_cast<void>(messaging_pattern);
IOX_TODO();
}

Expand Down
2 changes: 1 addition & 1 deletion iceoryx2-ffi/cxx/tests/src/node_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ TYPED_TEST(NodeTest, created_nodes_can_be_listed) {
}

uint64_t counter = 0;
auto result = Node<SERVICE_TYPE>::list(Config::global_config(), [&](const auto& node_state) {
auto result = Node<SERVICE_TYPE>::list(Config::global_config(), [&](const auto&) {
counter++;
return CallbackProgression::Continue;
});
Expand Down
2 changes: 0 additions & 2 deletions iceoryx2-ffi/cxx/tests/src/service_event_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@ TYPED_TEST(ServiceEventTest, service_can_be_opened_when_there_is_a_listener) {

TYPED_TEST(ServiceEventTest, create_with_attributes_sets_attributes) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;
constexpr uint64_t NUMBER_OF_SUBSCRIBERS = 12;

auto key = Attribute::Key("want to make your machine run faster:");
auto value = Attribute::Value("sudo rm -rf /");
Expand Down Expand Up @@ -443,7 +442,6 @@ TYPED_TEST(ServiceEventTest, create_with_attributes_sets_attributes) {

TYPED_TEST(ServiceEventTest, open_fails_when_attributes_are_incompatible) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;
constexpr uint64_t NUMBER_OF_SUBSCRIBERS = 12;

auto key = Attribute::Key("whats hypnotoad doing these days?");
auto value = Attribute::Value("eating hypnoflies?");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,6 @@ TYPED_TEST(ServicePublishSubscribeTest, publisher_does_not_reallocate_when_alloc

TYPED_TEST(ServicePublishSubscribeTest, create_with_attributes_sets_attributes) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;
constexpr uint64_t NUMBER_OF_SUBSCRIBERS = 12;

auto key = Attribute::Key("want to make your machine run faster:");
auto value = Attribute::Value("sudo rm -rf /");
Expand Down Expand Up @@ -848,7 +847,6 @@ TYPED_TEST(ServicePublishSubscribeTest, create_with_attributes_sets_attributes)

TYPED_TEST(ServicePublishSubscribeTest, open_fails_when_attributes_are_incompatible) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;
constexpr uint64_t NUMBER_OF_SUBSCRIBERS = 12;

auto key = Attribute::Key("whats hypnotoad doing these days?");
auto value = Attribute::Value("eating hypnoflies?");
Expand Down
4 changes: 2 additions & 2 deletions iceoryx2-ffi/cxx/tests/src/waitset_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ TYPED_TEST(WaitSetTest, does_not_block_longer_than_provided_timeout) {

auto callback_called = false;
auto result = sut.wait_and_process_once_with_timeout(
[&](auto attachment_id) -> CallbackProgression {
[&](auto) -> CallbackProgression {
callback_called = true;
return CallbackProgression::Stop;
},
Expand All @@ -217,7 +217,7 @@ TYPED_TEST(WaitSetTest, blocks_until_interval_when_user_timeout_is_larger) {
auto guard = sut.attach_interval(TIMEOUT).expect("");

auto callback_called = false;
auto result = sut.wait_and_process_once([&](auto attachment_id) -> CallbackProgression {
auto result = sut.wait_and_process_once([&](auto) -> CallbackProgression {
callback_called = true;
return CallbackProgression::Stop;
});
Expand Down

0 comments on commit 9234805

Please sign in to comment.