modm-io / modm

modm: a C++23 library generator for AVR and ARM Cortex-M devices
https://modm.io
Mozilla Public License 2.0
720 stars 128 forks source link

GCC 13 memcpy warning in can_message.hpp #1180

Closed calebchalmers closed 2 weeks ago

calebchalmers commented 3 weeks ago

When compiling modm for an STM32F427 using arm-none-eabi-gcc 13.2.rel1-2, I get the following warnings:

src/modm/platform/can/can_1.cpp: In static member function 'static bool modm::platform::Can1::getMessage(modm::can::Message&, uint8_t*)':
src/modm/platform/can/can_1.cpp:301:23: warning: 'void* memcpy(void*, const void*, size_t)' writing to an object of type 'struct modm::can::Message' with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
  301 |                 memcpy(&message, &rxMessage.message, sizeof(message));
      |                 ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/modm/architecture/interface/can.hpp:18,
                 from src/modm/platform/can/can_1.hpp:19,
                 from src/modm/platform/can/can_1.cpp:25:
src/modm/architecture/interface/can_message.hpp:27:8: note: 'struct modm::can::Message' declared here
   27 | struct Message
      |        ^~~~~~~
src/modm/platform/can/can_2.cpp: In static member function 'static bool modm::platform::Can2::getMessage(modm::can::Message&, uint8_t*)':
src/modm/platform/can/can_2.cpp:303:23: warning: 'void* memcpy(void*, const void*, size_t)' writing to an object of type 'struct modm::can::Message' with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
  303 |                 memcpy(&message, &rxMessage.message, sizeof(message));
      |                 ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/modm/architecture/interface/can.hpp:18,
                 from src/modm/platform/can/can_2.hpp:19,
                 from src/modm/platform/can/can_2.cpp:25:
src/modm/architecture/interface/can_message.hpp:27:8: note: 'struct modm::can::Message' declared here
   27 | struct Message
      |        ^~~~~~~
salkinium commented 3 weeks ago

writing to an object of type 'struct modm::can::Message' with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]

The struct modm::can::Message is missing a copy-assignment or copy-constructor.