diff --git a/include/thingset++/ThingSetGroup.hpp b/include/thingset++/ThingSetGroup.hpp index 83d63fd..11a37b6 100644 --- a/include/thingset++/ThingSetGroup.hpp +++ b/include/thingset++/ThingSetGroup.hpp @@ -24,9 +24,11 @@ class ThingSetGroup : public IdentifiableThingSetParentNode, std::function _callback; public: - ThingSetGroup() : ThingSetGroup(defaultCallback){}; + ThingSetGroup() : ThingSetGroup(defaultCallback) + {} ThingSetGroup(std::function callback) - : IdentifiableThingSetParentNode(), _callback(callback){}; + : IdentifiableThingSetParentNode(), _callback(callback) + {} constexpr const std::string getType() const override { diff --git a/include/thingset++/ThingSetRecordMember.hpp b/include/thingset++/ThingSetRecordMember.hpp index d1e44c0..b16d454 100644 --- a/include/thingset++/ThingSetRecordMember.hpp +++ b/include/thingset++/ThingSetRecordMember.hpp @@ -414,13 +414,13 @@ class ThingSetRecordMember return Access; } - bool findByName(const std::string &name, ThingSetNode **node, size_t *index) override + bool findByName(const std::string &childName, ThingSetNode **node, size_t *index) override { - bool foundChild = ThingSetParentNode::findByName(name, node, index); + bool foundChild = ThingSetParentNode::findByName(childName, node, index); // atoi is useless - it returns 0 on failure - so we check that the string actually // contains a number before trying to parse it - if (name.c_str()[0] >= '0' && name.c_str()[0] <= '9') { - *index = std::atoi(name.c_str()); + if (childName.c_str()[0] >= '0' && childName.c_str()[0] <= '9') { + *index = std::atoi(childName.c_str()); return true; } diff --git a/include/thingset++/ThingSetServer.hpp b/include/thingset++/ThingSetServer.hpp index cc7f860..a99c6a3 100644 --- a/include/thingset++/ThingSetServer.hpp +++ b/include/thingset++/ThingSetServer.hpp @@ -86,11 +86,12 @@ class ThingSetServer : public _ThingSetServer ThingSetServerTransport &_transport; public: - ThingSetServer(ThingSetServerTransport &transport) : ThingSetServer(transport, nullptr) + ThingSetServer(ThingSetServerTransport &serverTransport) + : ThingSetServer(serverTransport, nullptr) {} - ThingSetServer(ThingSetServerTransport &transport, ThingSetForwarder *forwarder) - : _ThingSetServer(forwarder), _transport(transport) + ThingSetServer(ThingSetServerTransport &serverTransport, ThingSetForwarder *forwarder) + : _ThingSetServer(forwarder), _transport(serverTransport) {} bool listen() override diff --git a/include/thingset++/ThingSetValue.hpp b/include/thingset++/ThingSetValue.hpp index 1022da5..e551456 100644 --- a/include/thingset++/ThingSetValue.hpp +++ b/include/thingset++/ThingSetValue.hpp @@ -96,7 +96,7 @@ class ThingSetValue : public ThingSetEncodable, template , bool>::type = true> auto &operator=(const U &value) { - _value = value; + _value = static_cast(value); return *this; } }; diff --git a/include/thingset++/can/zephyr/ThingSetZephyrCanClientTransport.hpp b/include/thingset++/can/zephyr/ThingSetZephyrCanClientTransport.hpp index 4ffadec..fb7e2c9 100644 --- a/include/thingset++/can/zephyr/ThingSetZephyrCanClientTransport.hpp +++ b/include/thingset++/can/zephyr/ThingSetZephyrCanClientTransport.hpp @@ -27,9 +27,10 @@ class ThingSetZephyrCanClientTransport : public ThingSetCanClientTransport ThingSetZephyrCanClientTransport(ThingSetZephyrCanClientTransport &&) = delete; ThingSetZephyrCanClientTransport(const ThingSetZephyrCanClientTransport &) = delete; template - ThingSetZephyrCanClientTransport(ThingSetZephyrCanInterface &canInterface, uint8_t targetNodeAddress, - std::array &rxBuffer, std::array &txBuffer) : ThingSetCanClientTransport(targetNodeAddress), - _requestResponseContext(canInterface, rxBuffer, txBuffer) + ThingSetZephyrCanClientTransport(ThingSetZephyrCanInterface &zephyrCanInterface, uint8_t targetNodeAddress, + std::array &rxStorage, std::array &txStorage) + : ThingSetCanClientTransport(targetNodeAddress), + _requestResponseContext(zephyrCanInterface, rxStorage, txStorage) { k_msgq_init(&_responseQueue, _responseQueueBuffer.data(), sizeof(ResponseMessage), 1); } diff --git a/include/thingset++/can/zephyr/ThingSetZephyrCanInterface.hpp b/include/thingset++/can/zephyr/ThingSetZephyrCanInterface.hpp index 1871693..c85b53f 100644 --- a/include/thingset++/can/zephyr/ThingSetZephyrCanInterface.hpp +++ b/include/thingset++/can/zephyr/ThingSetZephyrCanInterface.hpp @@ -20,7 +20,7 @@ class _ThingSetZephyrCanInterface : public ThingSetCanInterface _ThingSetZephyrCanInterface(const device *const canDevice); public: - const device *const getDevice(); + const device *getDevice(); }; class ThingSetZephyrCanStubInterface : public _ThingSetZephyrCanInterface diff --git a/include/thingset++/can/zephyr/ThingSetZephyrCanRequestResponseContext.hpp b/include/thingset++/can/zephyr/ThingSetZephyrCanRequestResponseContext.hpp index a2578a5..378ad4a 100644 --- a/include/thingset++/can/zephyr/ThingSetZephyrCanRequestResponseContext.hpp +++ b/include/thingset++/can/zephyr/ThingSetZephyrCanRequestResponseContext.hpp @@ -30,10 +30,12 @@ class ThingSetZephyrCanRequestResponseContext { std::function _inboundRequestCallback; public: - template - ThingSetZephyrCanRequestResponseContext(ThingSetZephyrCanInterface &canInterface, std::array &rxBuffer, - std::array &txBuffer) : _canInterface(canInterface), _rxBuffer(rxBuffer.data()), _rxBufferSize(RxSize), - _txBuffer(txBuffer.data()), _txBufferSize(TxSize) + template + ThingSetZephyrCanRequestResponseContext(ThingSetZephyrCanInterface &zephyrCanInterface, + std::array &rxStorage, + std::array &txStorage) + : _canInterface(zephyrCanInterface), _rxBuffer(rxStorage.data()), _rxBufferSize(RxSize), + _txBuffer(txStorage.data()), _txBufferSize(TxSize) { _requestResponseContext.filter_id = THINGSET_PLUS_PLUS_ZEPHYR_CAN_FILTER_ID_NONE; k_sem_init(&_lock, 1, 1); diff --git a/include/thingset++/can/zephyr/ThingSetZephyrCanServerTransport.hpp b/include/thingset++/can/zephyr/ThingSetZephyrCanServerTransport.hpp index d6a1a81..349688c 100644 --- a/include/thingset++/can/zephyr/ThingSetZephyrCanServerTransport.hpp +++ b/include/thingset++/can/zephyr/ThingSetZephyrCanServerTransport.hpp @@ -21,9 +21,9 @@ class ThingSetZephyrCanServerTransport : public Can::ThingSetCanServerTransport ThingSetZephyrCanServerTransport(const ThingSetZephyrCanServerTransport &) = delete; template - ThingSetZephyrCanServerTransport(ThingSetZephyrCanInterface &canInterface, std::array &rxBuffer, - std::array &txBuffer) : ThingSetCanServerTransport(), - _requestResponseContext(canInterface, rxBuffer, txBuffer) + ThingSetZephyrCanServerTransport(ThingSetZephyrCanInterface &zephyrCanInterface, + std::array &rxStorage, std::array &txStorage) + : ThingSetCanServerTransport(), _requestResponseContext(zephyrCanInterface, rxStorage, txStorage) {} ~ThingSetZephyrCanServerTransport(); diff --git a/include/thingset++/internal/IntrusiveLinkedList.hpp b/include/thingset++/internal/IntrusiveLinkedList.hpp index 9d7066a..2e8731a 100644 --- a/include/thingset++/internal/IntrusiveLinkedList.hpp +++ b/include/thingset++/internal/IntrusiveLinkedList.hpp @@ -77,7 +77,7 @@ class IntrusiveLinkedList Element *operator*() const { // https://github.com/boostorg/intrusive/blob/master/include/boost/intrusive/detail/parent_from_member.hpp - Element *const container = 0; + Element *const container = nullptr; const char *const member = static_cast(static_cast(&(container->*Member))); std::ptrdiff_t offset = member - static_cast(static_cast(container)); return std::launder(reinterpret_cast(reinterpret_cast(_node) - static_cast(offset))); diff --git a/include/thingset++/ip/sockets/SocketEndpoint.hpp b/include/thingset++/ip/sockets/SocketEndpoint.hpp index 40088e6..f46080a 100644 --- a/include/thingset++/ip/sockets/SocketEndpoint.hpp +++ b/include/thingset++/ip/sockets/SocketEndpoint.hpp @@ -6,8 +6,15 @@ #pragma once #ifdef __ZEPHYR__ +/* Zephyr's C headers declare functions named after the structs they take (fs_statvfs, + * net_if_mcast_monitor). In C++ that hides the struct's implicit constructor, which + * -Wshadow reports in every file that includes this header. Nothing here uses those + * constructors, so the check is suspended for these includes only. */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" #include #include +#pragma GCC diagnostic pop #else #include #include diff --git a/src/can/zephyr/ThingSetZephyrCanInterface.cpp b/src/can/zephyr/ThingSetZephyrCanInterface.cpp index e320716..74142b4 100644 --- a/src/can/zephyr/ThingSetZephyrCanInterface.cpp +++ b/src/can/zephyr/ThingSetZephyrCanInterface.cpp @@ -22,7 +22,7 @@ _ThingSetZephyrCanInterface::_ThingSetZephyrCanInterface(const device *const can _isBound = false; } -const device *const _ThingSetZephyrCanInterface::getDevice() +const device *_ThingSetZephyrCanInterface::getDevice() { return _canDevice; } diff --git a/src/can/zephyr/ThingSetZephyrCanRequestResponseContext.cpp b/src/can/zephyr/ThingSetZephyrCanRequestResponseContext.cpp index 76d70af..eec9967 100644 --- a/src/can/zephyr/ThingSetZephyrCanRequestResponseContext.cpp +++ b/src/can/zephyr/ThingSetZephyrCanRequestResponseContext.cpp @@ -18,10 +18,10 @@ struct IsoTpFastAddress : public isotp_fast_addr { IsoTpFastAddress &setId(const CanID &id) { -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wnarrowing" - ext_id = id.getId(); -#pragma GCC diagnostic pop + /* ext_id is a 29-bit field and a CAN identifier is at most 29 bits, so the mask + * is lossless; it exists to make that explicit to the compiler + */ + ext_id = id.getId() & CAN_EXT_ID_MASK; return *this; } }; diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index df8f531..d56bafb 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -1,3 +1,9 @@ +# Nothing to build when the module is disabled; creating the library anyway makes +# Zephyr warn about a library with no sources. +if(NOT CONFIG_THINGSET_PLUS_PLUS) + return() +endif() + zephyr_library_named("thingset++") set(CMAKE_CXX_STANDARD 20)