From 0eceafc54fac90c299dbba670d3e9d18a3d05969 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Sat, 28 Oct 2023 18:59:55 -0500 Subject: [PATCH] AP_HAL_ChibiOS/CAN*Iface: fix C++ One Definition Rule violations Switch to const extern hal reference, then cast const-ness away to modify it and store the CAN driver reference during driver init. This does just replace one undefined behavior with another, but the latter is not warned about and is used in other parts of the code for the same purpose. --- libraries/AP_HAL_ChibiOS/CANFDIface.cpp | 4 ++-- libraries/AP_HAL_ChibiOS/CanIface.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/AP_HAL_ChibiOS/CANFDIface.cpp b/libraries/AP_HAL_ChibiOS/CANFDIface.cpp index 2d261f7242084c..a0f8e28192a7fe 100644 --- a/libraries/AP_HAL_ChibiOS/CANFDIface.cpp +++ b/libraries/AP_HAL_ChibiOS/CANFDIface.cpp @@ -85,7 +85,7 @@ #error "Unsupported MCU for FDCAN" #endif -extern AP_HAL::HAL& hal; +extern const AP_HAL::HAL& hal; #define STR(x) #x #define XSTR(x) STR(x) @@ -568,7 +568,7 @@ bool CANIface::init(const uint32_t bitrate, const uint32_t fdbitrate, const Oper if (can_ifaces[self_index_] == nullptr) { can_ifaces[self_index_] = this; #if !defined(HAL_BOOTLOADER_BUILD) - hal.can[self_index_] = this; + const_cast (hal).can[self_index_] = this; #endif } diff --git a/libraries/AP_HAL_ChibiOS/CanIface.cpp b/libraries/AP_HAL_ChibiOS/CanIface.cpp index 677f484804943e..2ad28509ccac1c 100644 --- a/libraries/AP_HAL_ChibiOS/CanIface.cpp +++ b/libraries/AP_HAL_ChibiOS/CanIface.cpp @@ -84,7 +84,7 @@ #endif -extern AP_HAL::HAL& hal; +extern const AP_HAL::HAL& hal; using namespace ChibiOS; @@ -846,7 +846,7 @@ bool CANIface::init(const uint32_t bitrate, const CANIface::OperatingMode mode) if (can_ifaces[self_index_] == nullptr) { can_ifaces[self_index_] = this; #if !defined(HAL_BOOTLOADER_BUILD) - hal.can[self_index_] = this; + const_cast (hal).can[self_index_] = this; #endif }