From 72b246e52c9412fd4fc974c6446b8d66212f80cf Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Sat, 5 Mar 2016 09:48:54 -0300 Subject: [PATCH] AP_HAL_Linux: fix use of 0-length array 0-length arrays are supported in C but forbidden in C++. GCC allows it but clang is more strict: ../../libraries/AP_HAL_Linux/SPIDriver.cpp:75:35: fatal error: no matching constructor for initialization of 'Linux::SPIDeviceDriver [0]' SPIDeviceDriver SPIDeviceManager::_device[0]; ^ ../../libraries/AP_HAL_Linux/SPIDriver.h:20:7: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 0 were provided class SPIDeviceDriver : public AP_HAL::SPIDeviceDriver { ^ ../../libraries/AP_HAL_Linux/SPIDriver.h:20:7: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 0 were provided ../../libraries/AP_HAL_Linux/SPIDriver.h:25:5: note: candidate constructor not viable: requires 9 arguments, but 0 were provided SPIDeviceDriver(const char *name, uint16_t bus, uint16_t subdev, enum AP_HAL::SPIDeviceType type, uint8_t mode, uint8_t bitsPerWord, int16_t cs_pin, uint32_t lowspeed, uint32_t highspeed); ^ 1 error generated. --- libraries/AP_HAL_Linux/SPIDriver.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/AP_HAL_Linux/SPIDriver.cpp b/libraries/AP_HAL_Linux/SPIDriver.cpp index c1abd32bc7..3aff15e8fc 100644 --- a/libraries/AP_HAL_Linux/SPIDriver.cpp +++ b/libraries/AP_HAL_Linux/SPIDriver.cpp @@ -72,10 +72,14 @@ SPIDeviceDriver SPIDeviceManager::_device[] = { }; #else // empty device table -SPIDeviceDriver SPIDeviceManager::_device[0]; +SPIDeviceDriver SPIDeviceManager::_device[] = { }; +#define LINUX_SPI_DEVICE_NUM_DEVICES 0 #endif +#ifndef LINUX_SPI_DEVICE_NUM_DEVICES #define LINUX_SPI_DEVICE_NUM_DEVICES ARRAY_SIZE(SPIDeviceManager::_device) +#endif + const uint8_t SPIDeviceManager::_n_device_desc = LINUX_SPI_DEVICE_NUM_DEVICES; SPIDeviceDriver::SPIDeviceDriver(const char *name, uint16_t bus, uint16_t subdev, enum AP_HAL::SPIDeviceType type, uint8_t mode, uint8_t bitsPerWord, int16_t cs_pin, uint32_t lowspeed, uint32_t highspeed):