Skip to content

Commit

Permalink
feat: Enforce compiler warnings (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
DownerCase authored Dec 3, 2024
1 parent ee8148e commit 05af680
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- uses: actions/checkout@v4

- name: Configure
run: cmake -S . -B build -G Ninja -Werror=dev -DCMAKE_COMPILE_WARNING_AS_ERROR=ON
run: cmake -S . -B build -G Ninja -Werror=dev -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DCMAKE_TOOLCHAIN_FILE=project/gcc.cmake

- name: Build
run: cmake --build ./build
Expand Down
6 changes: 1 addition & 5 deletions ecal/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ version GetVersion() {
return version_;
}

int Initialize(
struct config *config,
const char *unit_name,
unsigned int components
) {
int Initialize(config *config, const char *unit_name, unsigned int components) {
auto cfg = convertConfig(*config);
// TODO: Initialize should take by const ref
return eCAL::Initialize(cfg, unit_name, components);
Expand Down
8 changes: 4 additions & 4 deletions ecal/monitoring/monitoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ namespace {
// Makes uses of copy elision
CTopicMon toCType(const eCAL::Monitoring::STopicMon &topic) {
return {
topic.rclock,
topic.uname.c_str(),
topic.tid.c_str(),
topic.tname.c_str(),
topic.direction.c_str(),
toCDataType(topic.tdatatype),
topic.dclock,
topic.dfreq,
topic.rclock,
topic.tsize,
topic.connections_loc,
topic.connections_ext,
topic.message_drops,
topic.dclock,
topic.dfreq
topic.message_drops
};
}

Expand Down
6 changes: 3 additions & 3 deletions ecal/monitoring/monitoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ enum eCAL_Monitoring_eEntity {
};

struct CTopicMon {
int32_t registration_clock;
const char *unit_name;
const char *topic_id;
const char *topic_name;
const char *direction;
struct CDatatype datatype;
int64_t data_clock;
int64_t data_freq;
int32_t registration_clock;
int32_t topic_size;
int32_t connections_local;
int32_t connections_external;
int32_t message_drops;
int64_t data_clock;
int64_t data_freq;
};

struct CProcessMon {
Expand Down
2 changes: 1 addition & 1 deletion ecal/publisher/publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "internal/handle_map.hpp"

namespace {
handle_map<eCAL::CPublisher> publishers;
handle_map<eCAL::CPublisher> publishers{};
} // namespace

bool NewPublisher(uintptr_t handle) {
Expand Down
24 changes: 1 addition & 23 deletions ecal/registration/registration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,9 @@
#include <ecal/ecal_registration.h>

extern "C" {
extern void
goTopicEventCallback(uintptr_t handle, struct CTopicId id, uint8_t event);
extern void goTopicEventCallback(uintptr_t handle, CTopicId id, uint8_t event);
}

namespace {
int safe_len(size_t str_len) {
if (str_len > INT_MAX) {
return INT_MAX;
}
return str_len;
}

struct CQualityInfo
toCQualityInfo(const eCAL::Registration::SQualityTopicInfo &quality) {
return {
{quality.info.name.c_str(),
quality.info.encoding.c_str(),
quality.info.descriptor.c_str(),
safe_len(quality.info.descriptor.size())},
static_cast<uint8_t>(quality.quality),
};
}

} // namespace

size_t AddPublisherEventCallback(uintptr_t handle) {
const auto callback_adapter = [handle](
const eCAL::Registration::STopicId &id,
Expand Down
6 changes: 3 additions & 3 deletions ecal/registration/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ func toQualityTopicInfo(quality *C.struct_CQualityInfo) QualityTopicInfo {
func toTopicId(id *C.struct_CTopicId) TopicId {
return TopicId{
Topic_id: EntityId{
Entity_id: C.GoStringN(id.topic_id.entity_id, id.topic_id.entity_id_len),
Entity_id: C.GoString(id.topic_id.entity_id),
Process_id: int32(id.topic_id.process_id),
Host_name: C.GoStringN(id.topic_id.host_name, id.topic_id.host_name_len),
Host_name: C.GoString(id.topic_id.host_name),
},
Topic_name: C.GoStringN(id.topic_name, id.topic_name_len),
Topic_name: C.GoString(id.topic_name),
}
}

Expand Down
12 changes: 6 additions & 6 deletions ecal/subscriber/subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ handle_map<eCAL::CSubscriber> subscribers;

void receive_callback(
const uintptr_t handle,
const eCAL::Registration::STopicId &topic,
const eCAL::SDataTypeInformation &datatype,
const eCAL::Registration::STopicId & /*topic*/,
const eCAL::SDataTypeInformation & /*datatype*/,
const eCAL::SReceiveCallbackData &data
) {
goReceiveCallback(handle, data.buf, data.size);
Expand Down Expand Up @@ -51,11 +51,11 @@ bool SubscriberCreate(
std::string(datatype_descriptor, datatype_descriptor_len)}
);
const auto bound_callback = [handle](
const eCAL::Registration::STopicId &topic,
const eCAL::SDataTypeInformation &datatype,
const eCAL::SReceiveCallbackData &data
const eCAL::Registration::STopicId &_topic,
const eCAL::SDataTypeInformation &_datatype,
const eCAL::SReceiveCallbackData &_data
) {
receive_callback(handle, topic, datatype, data);
receive_callback(handle, _topic, _datatype, _data);
};
subscriber->AddReceiveCallback(bound_callback);
return created;
Expand Down
17 changes: 8 additions & 9 deletions ecal/types/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace {
int safe_len(size_t str_len) {
if (str_len > INT_MAX) {
if (str_len > size_t{INT_MAX}) {
return INT_MAX;
}
return str_len;
return static_cast<int>(str_len);
}
} // namespace

Expand All @@ -20,12 +20,11 @@ CDatatype toCDataType(const eCAL::SDataTypeInformation &datatype) {

CTopicId toCTopicId(const eCAL::Registration::STopicId &id) {
return {
{id.topic_id.entity_id.data(),
safe_len(id.topic_id.entity_id.size()),
id.topic_id.process_id,
id.topic_id.host_name.data(),
safe_len(id.topic_id.host_name.size())},
id.topic_name.data(),
safe_len(id.topic_name.size())
{
id.topic_id.entity_id.data(),
id.topic_id.host_name.data(),
id.topic_id.process_id,
},
id.topic_name.data()
};
}
5 changes: 1 addition & 4 deletions ecal/types/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ extern "C" {

struct CEntityId {
const char *entity_id;
int entity_id_len;
int32_t process_id;
const char *host_name;
int host_name_len;
int32_t process_id;
};

struct CTopicId {
struct CEntityId topic_id;
const char *topic_name;
int topic_name_len;
};

struct CDatatype {
Expand Down
2 changes: 1 addition & 1 deletion internal/handle_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

template <class T> class handle_map {
private:
std::unordered_map<uintptr_t, T> handles;
std::unordered_map<uintptr_t, T> handles{};

public:
using iterator = typename decltype(handles)::iterator;
Expand Down
72 changes: 72 additions & 0 deletions project/gcc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
set(CMAKE_C_COMPILER gcc)
set(CMAKE_CXX_COMPILER g++)

set(gcc_warnings
-Wpedantic # Forbid extensions
-pedantic-errors # Warnings from Wpedantic (and default warnings) are errors
-Wall # Enable warnings
-Wextra # Enable more warnings
-Wdouble-promotion # Accidental float -> double promotion
-Wformat=2 # Check arguments to printf etc.
-Wformat-overflow=2 # Check for potential sprintf etc. destination overflows
-Wformat-signedness # Checking format string signedness
-Wformat-truncation=2 # Check for output truncation
-Wnull-dereference # Dereference of null
-Wnrvo # Warn when NRVO fails
-Wimplicit-fallthrough=5 # Fallthrough can only be allowed by [[fallthrough]]
-Wmissing-include-dirs # Include directories that don't exist
-Wswitch-default # Require default for switch
-Wswitch-enum # Require all named cases for switch on an enum
-Wunused
-Wuse-after-free=3
-Wuseless-cast # Casting to your own type
-Wmaybe-uninitialized # Potential unitialized uses
-Wstrict-overflow=5
-Wstringop-overflow=4
-Warith-conversion # WARN: Noisy warning
-Warray-bounds=2
-Wbidi-chars=any # Misleading bidirectional UTF-8 control characters
-Wduplicated-branches # Duplicated conditional branches
-Wduplicated-cond # Duplicated conditions
-Wtrampolines # No trampolines
-Wfloat-equal # Comparing floats is hard
-Wshadow # Don't shadow varibles
-Wunsafe-loop-optimizations
-Wundef
-Wcast-qual
-Wcast-align=strict
-Wconversion # Catch implicit conversions
-Wdate-time # Date/time prevents reproducible builds
-Wsign-conversion # Implicit conversions that change the sign
-Wlogical-op # Suspicious use of logical operators
-Wmissing-declarations
-Wpadded
-Wno-error=padded # WARN: Wpadded is extremely noisy
-Wredundant-decls
-Winline
-Wdisabled-optimization
-Wstack-protector

-Wctad-maybe-unsupported
-Wctor-dtor-privacy
-Wnoexcept
-Wnon-virtual-dtor # Virtual classes need virtual destructors
-Wredundant-tags
-Weffc++
-Wstrict-null-sentinel
-Wold-style-cast
-Woverloaded-virtual
-Wsign-promo
-Wcatch-value=3
-Wextra-semi

-Wsuggest-final-types
-Wsuggest-final-methods
-Wsuggest-override
)

string(REPLACE ";" " " gcc_warnings "${gcc_warnings}")

set(CMAKE_CXX_FLAGS_INIT "${gcc_warnings}")

set(CMAKE_COMPILE_WARNING_AS_ERROR ON)

0 comments on commit 05af680

Please sign in to comment.