diff --git a/core/include/kernel_defines.h b/core/include/kernel_defines.h index 4ade63792e..12f3ea410b 100644 --- a/core/include/kernel_defines.h +++ b/core/include/kernel_defines.h @@ -132,18 +132,6 @@ extern "C" { #define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0])) #endif -/** - * @def BUILD_BUG_ON(condition) - * @brief Forces a compilation error if condition is true. - * This trick is only needed if the condition can't be evaluated - * before compile time (i.e. sizeof(sometype_t) < 42 ) - * For more details on this see for example: - * https://git.kernel.org/pub/scm/linux/kernel/git/stable/ - * linux-stable.git/tree/include/linux/bug.h - * @param[in] condition A condition that will be evaluated at compile time - */ -#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * !!(condition)])) - /** * @def IS_ACTIVE(macro) * @brief Allows to verify a macro definition outside the preprocessor. diff --git a/drivers/sps30/sps30.c b/drivers/sps30/sps30.c index a3813b1603..f6934f0a43 100644 --- a/drivers/sps30/sps30.c +++ b/drivers/sps30/sps30.c @@ -104,7 +104,7 @@ static inline void _cpy_add_crc(uint8_t *data, size_t len, uint8_t *crcd_data) * @return true if all CRCs are valid * @return false if at least one CRC is invalid */ -static inline bool _cpy_check_crc(uint8_t *data, size_t len, uint8_t *crcd_data) +static inline bool _cpy_check_crc(uint8_t *data, size_t len, const uint8_t *crcd_data) { for (size_t elem = 0; elem < len / 2; elem++) { int idx = (elem << 1); @@ -223,7 +223,8 @@ int sps30_read_measurement(const sps30_t *dev, sps30_data_t *data) { /* This compile time check is needed to ensure the below method used for endianness conversion will work as expected */ - BUILD_BUG_ON(sizeof(sps30_data_t) != (sizeof(float) * 10)); + static_assert(sizeof(sps30_data_t) == (sizeof(float) * 10), + "sps30_data_t must be sized 10 floats"); assert(dev && data); /* The target buffer is also used for storing the raw data temporarily */ diff --git a/pkg/fatfs/fatfs_vfs/fatfs_vfs.c b/pkg/fatfs/fatfs_vfs/fatfs_vfs.c index 55224c1e05..2ce45fd84e 100644 --- a/pkg/fatfs/fatfs_vfs/fatfs_vfs.c +++ b/pkg/fatfs/fatfs_vfs/fatfs_vfs.c @@ -18,6 +18,7 @@ * @} */ +#include #include #include #include @@ -26,7 +27,6 @@ #include "fs/fatfs.h" -#include "kernel_defines.h" /* needed for BUILD_BUG_ON */ #include "time.h" #define ENABLE_DEBUG 0 @@ -50,8 +50,10 @@ static int _mount(vfs_mount_t *mountp) { /* if one of the lines below fail to compile you probably need to adjust vfs buffer sizes ;) */ - BUILD_BUG_ON(VFS_DIR_BUFFER_SIZE < sizeof(DIR)); - BUILD_BUG_ON(VFS_FILE_BUFFER_SIZE < sizeof(fatfs_file_desc_t)); + static_assert(VFS_DIR_BUFFER_SIZE >= sizeof(DIR), + "DIR must fit into VFS_DIR_BUFFER_SIZE"); + static_assert(VFS_FILE_BUFFER_SIZE >= sizeof(fatfs_file_desc_t), + "fatfs_file_desc_t must fit into VFS_FILE_BUFFER_SIZE"); fatfs_desc_t *fs_desc = (fatfs_desc_t *)mountp->private_data; diff --git a/pkg/littlefs/fs/littlefs_fs.c b/pkg/littlefs/fs/littlefs_fs.c index daf616bdc1..6e5ca07e8a 100644 --- a/pkg/littlefs/fs/littlefs_fs.c +++ b/pkg/littlefs/fs/littlefs_fs.c @@ -18,6 +18,7 @@ * @} */ +#include #include #include #include @@ -25,8 +26,6 @@ #include "fs/littlefs_fs.h" -#include "kernel_defines.h" - #define ENABLE_DEBUG 0 #include @@ -170,8 +169,10 @@ static int _mount(vfs_mount_t *mountp) { /* if one of the lines below fail to compile you probably need to adjust vfs buffer sizes ;) */ - BUILD_BUG_ON(VFS_DIR_BUFFER_SIZE < sizeof(lfs_dir_t)); - BUILD_BUG_ON(VFS_FILE_BUFFER_SIZE < sizeof(lfs_file_t)); + static_assert(VFS_DIR_BUFFER_SIZE >= sizeof(lfs_dir_t), + "lfs_dir_t must fit in VFS_DIR_BUFFER_SIZE"); + static_assert(VFS_FILE_BUFFER_SIZE >= sizeof(lfs_file_t), + "lfs_file_t must fit in VFS_FILE_BUFFER_SIZE"); littlefs_desc_t *fs = mountp->private_data; diff --git a/pkg/littlefs2/fs/littlefs2_fs.c b/pkg/littlefs2/fs/littlefs2_fs.c index eca79576a9..7e7a5605af 100644 --- a/pkg/littlefs2/fs/littlefs2_fs.c +++ b/pkg/littlefs2/fs/littlefs2_fs.c @@ -18,6 +18,7 @@ * @} */ +#include #include #include #include @@ -25,8 +26,6 @@ #include "fs/littlefs2_fs.h" -#include "kernel_defines.h" - #define ENABLE_DEBUG 0 #include @@ -176,8 +175,10 @@ static int _mount(vfs_mount_t *mountp) { /* if one of the lines below fail to compile you probably need to adjust vfs buffer sizes ;) */ - BUILD_BUG_ON(VFS_DIR_BUFFER_SIZE < sizeof(lfs_dir_t)); - BUILD_BUG_ON(VFS_FILE_BUFFER_SIZE < sizeof(lfs_file_t)); + static_assert(VFS_DIR_BUFFER_SIZE >= sizeof(lfs_dir_t), + "lfs_dir_t must fit in VFS_DIR_BUFFER_SIZE"); + static_assert(VFS_FILE_BUFFER_SIZE >= sizeof(lfs_file_t), + "lfs_file_t must fit in VFS_FILE_BUFFER_SIZE"); littlefs2_desc_t *fs = mountp->private_data; diff --git a/sys/arduino/SPI.cpp b/sys/arduino/SPI.cpp index fd67aa83cb..d4f263c060 100644 --- a/sys/arduino/SPI.cpp +++ b/sys/arduino/SPI.cpp @@ -66,8 +66,10 @@ SPISettings::SPISettings(uint32_t clock_hz, uint8_t bitOrder, uint8_t dataMode) SPIClass::SPIClass(spi_t spi_dev) { - /* Check if default SPI interface is valid */ - BUILD_BUG_ON(ARDUINO_SPI_INTERFACE >= SPI_NUMOF); + /* Check if default SPI interface is valid. Casting to int to avoid + * bogus type-limits warning here. */ + static_assert((int)ARDUINO_SPI_INTERFACE <= (int)SPI_NUMOF, + "spi_dev out of bounds"); this->spi_dev = spi_dev; this->settings = SPISettings(); this->is_transaction = false;