From 507181d2625096306d3cefb7ed617bec97b483ec Mon Sep 17 00:00:00 2001 From: pea-pod Date: Mon, 8 Jun 2020 22:52:36 -0500 Subject: [PATCH] Change MBED_STATIC_ASSERTs version for built-in --- .../FEATURE_BLE/include/ble/common/Duration.h | 2 +- .../netsocket/source/NetworkStack.cpp | 4 +- drivers/source/MbedCRC.cpp | 4 +- events/source/equeue_mbed.cpp | 10 ++-- .../utest/utest/utest_specification.h | 14 ++--- hal/source/mbed_pinmap_default.cpp | 4 +- hal/source/mpu/mbed_mpu_v7m.c | 2 +- hal/source/mpu/mbed_mpu_v8m.c | 4 +- platform/cxxsupport/mstd_atomic | 3 +- platform/include/platform/CircularBuffer.h | 4 +- platform/include/platform/Span.h | 16 +++--- platform/include/platform/mbed_assert.h | 5 ++ platform/include/platform/mbed_version.h | 2 +- platform/source/CThunkBase.cpp | 4 +- platform/source/SysTimer.cpp | 2 +- platform/source/mbed_atomic_impl.c | 4 +- platform/source/mbed_retarget.cpp | 2 +- .../TESTS/mbed_micro/static_assert/test_c.c | 40 +++++++------- .../mbed_micro/static_assert/test_cpp.cpp | 52 +++++++++---------- rtos/include/rtos/MemoryPool.h | 2 +- rtos/source/Thread.cpp | 8 +-- .../COMPONENT_SD/source/SDBlockDevice.cpp | 8 +-- .../TARGET_M2351/device/system_M2351.c | 4 +- .../TARGET_M2351/gpio_irq_api.c | 2 +- .../TARGET_NUVOTON/TARGET_M251/gpio_irq_api.c | 2 +- .../TARGET_NUVOTON/TARGET_M261/gpio_irq_api.c | 2 +- .../TARGET_NUVOTON/TARGET_M451/gpio_irq_api.c | 2 +- .../TARGET_NUVOTON/TARGET_M480/gpio_irq_api.c | 2 +- .../TARGET_NANO100/gpio_irq_api.c | 2 +- .../TARGET_NUC472/gpio_irq_api.c | 2 +- 30 files changed, 109 insertions(+), 105 deletions(-) diff --git a/connectivity/FEATURE_BLE/include/ble/common/Duration.h b/connectivity/FEATURE_BLE/include/ble/common/Duration.h index 30a962e5230..d57ebe85ce3 100644 --- a/connectivity/FEATURE_BLE/include/ble/common/Duration.h +++ b/connectivity/FEATURE_BLE/include/ble/common/Duration.h @@ -141,7 +141,7 @@ struct Duration { Duration(Duration other) : duration(clamp(other.value() * (OtherTB / TB))) { - MBED_STATIC_ASSERT(OtherTB >= TB && (OtherTB % TB) == 0, "Incompatible units"); + static_assert(OtherTB >= TB && (OtherTB % TB) == 0, "Incompatible units"); } /** diff --git a/connectivity/netsocket/source/NetworkStack.cpp b/connectivity/netsocket/source/NetworkStack.cpp index 24c028b0331..99b17cff13a 100644 --- a/connectivity/netsocket/source/NetworkStack.cpp +++ b/connectivity/netsocket/source/NetworkStack.cpp @@ -431,7 +431,7 @@ class NetworkStackWrapper : public NetworkStack { // Conversion function for network stacks NetworkStack *nsapi_create_stack(nsapi_stack_t *stack) { - MBED_STATIC_ASSERT(sizeof stack->_stack_buffer >= sizeof(NetworkStackWrapper), - "The nsapi_stack_t stack buffer must fit a NetworkStackWrapper"); + static_assert(sizeof stack->_stack_buffer >= sizeof(NetworkStackWrapper), + "The nsapi_stack_t stack buffer must fit a NetworkStackWrapper"); return new (stack->_stack_buffer) NetworkStackWrapper; } diff --git a/drivers/source/MbedCRC.cpp b/drivers/source/MbedCRC.cpp index 24160acbda7..9e56de24f0b 100644 --- a/drivers/source/MbedCRC.cpp +++ b/drivers/source/MbedCRC.cpp @@ -23,8 +23,8 @@ namespace mbed { SingletonPtr mbed_crc_mutex; -MBED_STATIC_ASSERT(MBED_CRC_TABLE_SIZE == 0 || MBED_CRC_TABLE_SIZE == 16 || MBED_CRC_TABLE_SIZE == 256, - "Configuration setting drivers.crc-table-size must be set to 0, 16 or 256"); +static_assert(MBED_CRC_TABLE_SIZE == 0 || MBED_CRC_TABLE_SIZE == 16 || MBED_CRC_TABLE_SIZE == 256, + "Configuration setting drivers.crc-table-size must be set to 0, 16 or 256"); #if MBED_CRC_TABLE_SIZE > 0 diff --git a/events/source/equeue_mbed.cpp b/events/source/equeue_mbed.cpp index c05362126e8..980e5d17ff5 100644 --- a/events/source/equeue_mbed.cpp +++ b/events/source/equeue_mbed.cpp @@ -106,10 +106,10 @@ static void equeue_tick_update() void equeue_tick_init() { - MBED_STATIC_ASSERT(sizeof(equeue_timer) >= sizeof(ALIAS_TIMER), - "The equeue_timer buffer must fit the class Timer"); - MBED_STATIC_ASSERT(sizeof(equeue_ticker) >= sizeof(ALIAS_TICKER), - "The equeue_ticker buffer must fit the class Ticker"); + static_assert(sizeof(equeue_timer) >= sizeof(ALIAS_TIMER), + "The equeue_timer buffer must fit the class Timer"); + static_assert(sizeof(equeue_ticker) >= sizeof(ALIAS_TICKER), + "The equeue_ticker buffer must fit the class Ticker"); ALIAS_TIMER *timer = new (equeue_timer) ALIAS_TIMER; ALIAS_TICKER *ticker = new (equeue_ticker) ALIAS_TICKER; @@ -156,7 +156,7 @@ void equeue_mutex_unlock(equeue_mutex_t *m) #include "rtos/EventFlags.h" -MBED_STATIC_ASSERT(sizeof(equeue_sema_t) == sizeof(rtos::EventFlags), "equeue_sema_t / rtos::EventFlags mismatch"); +static_assert(sizeof(equeue_sema_t) == sizeof(rtos::EventFlags), "equeue_sema_t / rtos::EventFlags mismatch"); int equeue_sema_create(equeue_sema_t *s) { diff --git a/features/frameworks/utest/utest/utest_specification.h b/features/frameworks/utest/utest/utest_specification.h index 70ccb1ff028..92588ea7a13 100644 --- a/features/frameworks/utest/utest/utest_specification.h +++ b/features/frameworks/utest/utest/utest_specification.h @@ -55,7 +55,7 @@ namespace v1 { cases(static_cast(static_cast(cases))), length(N), defaults(defaults) { - MBED_STATIC_ASSERT( + static_assert( sizeof(CaseType) == sizeof(Case), "CaseType and Case should have the same size" ); @@ -69,7 +69,7 @@ namespace v1 { cases(static_cast(static_cast(cases))), length(N), defaults(defaults) { - MBED_STATIC_ASSERT( + static_assert( sizeof(CaseType) == sizeof(Case), "CaseType and Case should have the same size" ); @@ -83,7 +83,7 @@ namespace v1 { cases(static_cast(static_cast(cases))), length(N), defaults(defaults) { - MBED_STATIC_ASSERT( + static_assert( sizeof(CaseType) == sizeof(Case), "CaseType and Case should have the same size" ); @@ -98,7 +98,7 @@ namespace v1 { cases(static_cast(static_cast(cases))), length(N), defaults(defaults) { - MBED_STATIC_ASSERT( + static_assert( sizeof(CaseType) == sizeof(Case), "CaseType and Case should have the same size" ); @@ -122,7 +122,7 @@ namespace v1 { cases(static_cast(static_cast(cases))), length(N), defaults(defaults) { - MBED_STATIC_ASSERT( + static_assert( sizeof(CaseType) == sizeof(Case), "CaseType and Case should have the same size" ); @@ -137,7 +137,7 @@ namespace v1 { cases(static_cast(static_cast(cases))), length(N), defaults(defaults) { - MBED_STATIC_ASSERT( + static_assert( sizeof(CaseType) == sizeof(Case), "CaseType and Case should have the same size" ); @@ -153,7 +153,7 @@ namespace v1 { cases(static_cast(static_cast(cases))), length(N), defaults(defaults) { - MBED_STATIC_ASSERT( + static_assert( sizeof(CaseType) == sizeof(Case), "CaseType and Case should have the same size" ); diff --git a/hal/source/mbed_pinmap_default.cpp b/hal/source/mbed_pinmap_default.cpp index 45ac316691f..c980501e97b 100644 --- a/hal/source/mbed_pinmap_default.cpp +++ b/hal/source/mbed_pinmap_default.cpp @@ -42,8 +42,8 @@ static const PinList ff_arduino_list = { ff_arduino_pins }; -MBED_STATIC_ASSERT(sizeof(ff_arduino_pins) / sizeof(ff_arduino_pins[0]) == sizeof(ff_arduino_names) / sizeof(ff_arduino_names[0]), - "Arrays must have the same length"); +static_assert(sizeof(ff_arduino_pins) / sizeof(ff_arduino_pins[0]) == sizeof(ff_arduino_names) / sizeof(ff_arduino_names[0]), + "Arrays must have the same length"); const PinList *pinmap_ff_arduino_pins() { diff --git a/hal/source/mpu/mbed_mpu_v7m.c b/hal/source/mpu/mbed_mpu_v7m.c index d80406340e6..740c3b5c6f8 100644 --- a/hal/source/mpu/mbed_mpu_v7m.c +++ b/hal/source/mpu/mbed_mpu_v7m.c @@ -33,7 +33,7 @@ #endif #define MBED_MPU_RAM_START (MBED_MPU_ROM_END + 1) -MBED_STATIC_ASSERT( +static_assert( MBED_MPU_ROM_END == 0x04000000 - 1 || MBED_MPU_ROM_END == 0x08000000 - 1 || MBED_MPU_ROM_END == 0x0C000000 - 1 || diff --git a/hal/source/mpu/mbed_mpu_v8m.c b/hal/source/mpu/mbed_mpu_v8m.c index ccdbd592acf..4a1aafd5516 100644 --- a/hal/source/mpu/mbed_mpu_v8m.c +++ b/hal/source/mpu/mbed_mpu_v8m.c @@ -33,8 +33,8 @@ #endif #define MBED_MPU_RAM_START (MBED_MPU_ROM_END + 1) -MBED_STATIC_ASSERT(MBED_MPU_ROM_END <= 0x20000000 - 1, - "Unsupported value for MBED_MPU_ROM_END"); +static_assert(MBED_MPU_ROM_END <= 0x20000000 - 1, + "Unsupported value for MBED_MPU_ROM_END"); void mbed_mpu_init() { diff --git a/platform/cxxsupport/mstd_atomic b/platform/cxxsupport/mstd_atomic index 8f3a81e0d6f..95d2bc78706 100644 --- a/platform/cxxsupport/mstd_atomic +++ b/platform/cxxsupport/mstd_atomic @@ -23,7 +23,6 @@ #include #include #include -#include "platform/mbed_assert.h" #include "platform/mbed_atomic.h" #include "platform/mbed_critical.h" #include "platform/CriticalSectionLock.h" @@ -477,7 +476,7 @@ protected: */ template> struct AtomicBaseInt { - MBED_STRUCT_STATIC_ASSERT(sizeof(T) == sizeof(A), "AtomicBaseInt size mismatch"); + static_assert(sizeof(T) == sizeof(A), "AtomicBaseInt size mismatch"); using value_type = T; AtomicBaseInt() noexcept = default; constexpr AtomicBaseInt(T v) noexcept : u(A(v)) diff --git a/platform/include/platform/CircularBuffer.h b/platform/include/platform/CircularBuffer.h index a9780e7fe70..55a0516fcc0 100644 --- a/platform/include/platform/CircularBuffer.h +++ b/platform/include/platform/CircularBuffer.h @@ -70,12 +70,12 @@ class CircularBuffer { public: CircularBuffer() : _head(0), _tail(0), _full(false) { - MBED_STATIC_ASSERT( + static_assert( internal::is_unsigned::value, "CounterType must be unsigned" ); - MBED_STATIC_ASSERT( + static_assert( (sizeof(CounterType) >= sizeof(uint32_t)) || (BufferSize < (((uint64_t) 1) << (sizeof(CounterType) * 8))), "Invalid BufferSize for the CounterType" diff --git a/platform/include/platform/Span.h b/platform/include/platform/Span.h index 450b7f57a1c..32ca318f6e4 100644 --- a/platform/include/platform/Span.h +++ b/platform/include/platform/Span.h @@ -249,7 +249,7 @@ struct Span { */ static const index_type extent = Extent; - MBED_STATIC_ASSERT(Extent >= 0, "Invalid extent for a Span"); + static_assert(Extent >= 0, "Invalid extent for a Span"); /** * Construct an empty Span. @@ -262,7 +262,7 @@ struct Span { Span() : _data(NULL) { - MBED_STATIC_ASSERT( + static_assert( Extent == 0, "Cannot default construct a static-extent Span (unless Extent is 0)" ); @@ -333,7 +333,7 @@ struct Span { Span(const Span &other): _data(other.data()) { - MBED_STATIC_ASSERT( + static_assert( (span_detail::is_convertible::value), "OtherElementType(*)[] should be convertible to ElementType (*)[]" ); @@ -440,7 +440,7 @@ struct Span { template Span first() const { - MBED_STATIC_ASSERT( + static_assert( (0 <= Count) && (Count <= Extent), "Invalid subspan extent" ); @@ -459,7 +459,7 @@ struct Span { template Span last() const { - MBED_STATIC_ASSERT( + static_assert( (0 <= Count) && (Count <= Extent), "Invalid subspan extent" ); @@ -484,11 +484,11 @@ struct Span { Span subspan() const { - MBED_STATIC_ASSERT( + static_assert( 0 <= Offset && Offset <= Extent, "Invalid subspan offset" ); - MBED_STATIC_ASSERT( + static_assert( (Count == SPAN_DYNAMIC_EXTENT) || (0 <= Count && (Count + Offset) <= Extent), "Invalid subspan count" @@ -678,7 +678,7 @@ struct Span { Span(const Span &other): _data(other.data()), _size(other.size()) { - MBED_STATIC_ASSERT( + static_assert( (span_detail::is_convertible::value), "OtherElementType(*)[] should be convertible to ElementType (*)[]" ); diff --git a/platform/include/platform/mbed_assert.h b/platform/include/platform/mbed_assert.h index 7df16b8adfd..c5ec5702b8f 100644 --- a/platform/include/platform/mbed_assert.h +++ b/platform/include/platform/mbed_assert.h @@ -17,6 +17,7 @@ #ifndef MBED_ASSERT_H #define MBED_ASSERT_H +#include #include "platform/mbed_toolchain.h" #ifdef __cplusplus @@ -70,6 +71,10 @@ do { \ } while (0) #endif +// ARM Compiler 6 currently fails to define `static_assert` in assert.h; correct for this +#if !defined __cplusplus && !defined static_assert +#define static_assert _Static_assert +#endif /** MBED_STATIC_ASSERT * Declare compile-time assertions, results in compile-time error if condition is false diff --git a/platform/include/platform/mbed_version.h b/platform/include/platform/mbed_version.h index a3dcf3c211b..8013bf9b94a 100644 --- a/platform/include/platform/mbed_version.h +++ b/platform/include/platform/mbed_version.h @@ -64,7 +64,7 @@ * master branch code */ #define MBED_VERSION_CHECK(major, minor, patch) do { \ - MBED_STATIC_ASSERT((MBED_VERSION >= MBED_ENCODE_VERSION((major),(minor),(patch))), "Incompatible mbed-os version detected!!"); \ + static_assert((MBED_VERSION >= MBED_ENCODE_VERSION((major),(minor),(patch))), "Incompatible mbed-os version detected!!"); \ } while(0) #endif diff --git a/platform/source/CThunkBase.cpp b/platform/source/CThunkBase.cpp index ddae39c4bc9..e1b286a88e0 100644 --- a/platform/source/CThunkBase.cpp +++ b/platform/source/CThunkBase.cpp @@ -23,8 +23,8 @@ #include "platform/internal/CThunkBase.h" -MBED_STATIC_ASSERT(MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX < 256, "MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX must be less than 256"); -MBED_STATIC_ASSERT(MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX > 0, "MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX must be greater than 0"); +static_assert(MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX < 256, "MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX must be less than 256"); +static_assert(MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX > 0, "MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX must be greater than 0"); #define ENABLE_N(N) ((MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX & N) ? 1 : 0) diff --git a/platform/source/SysTimer.cpp b/platform/source/SysTimer.cpp index 2345e68bdd5..652fd0bc6eb 100644 --- a/platform/source/SysTimer.cpp +++ b/platform/source/SysTimer.cpp @@ -337,7 +337,7 @@ void SysTimer::handler() #if MBED_CONF_RTOS_PRESENT /* Whatever the OS wants (in case it isn't 1ms) */ -MBED_STATIC_ASSERT(1000000 % OS_TICK_FREQ == 0, "OS_TICK_FREQ must be a divisor of 1000000 for correct tick calculations"); +static_assert(1000000 % OS_TICK_FREQ == 0, "OS_TICK_FREQ must be a divisor of 1000000 for correct tick calculations"); #define OS_TICK_US (1000000 / OS_TICK_FREQ) #if OS_TICK_US != 1000 template class SysTimer, std::micro>>; diff --git a/platform/source/mbed_atomic_impl.c b/platform/source/mbed_atomic_impl.c index 5087ae62f81..5faafab9e68 100644 --- a/platform/source/mbed_atomic_impl.c +++ b/platform/source/mbed_atomic_impl.c @@ -20,10 +20,10 @@ #include "platform/mbed_critical.h" /* Inline bool implementations in the header use uint8_t versions to manipulate the bool */ -MBED_STATIC_ASSERT(sizeof(bool) == sizeof(uint8_t), "Surely bool is a byte"); +static_assert(sizeof(bool) == sizeof(uint8_t), "Surely bool is a byte"); /* Inline implementations in the header use uint32_t versions to manipulate pointers */ -MBED_STATIC_ASSERT(sizeof(void *) == sizeof(uint32_t), "Alas, pointers must be 32-bit"); +static_assert(sizeof(void *) == sizeof(uint32_t), "Alas, pointers must be 32-bit"); #define DO_MBED_LOCKED_OP(name, OP, retValue, T, fn_suffix) \ diff --git a/platform/source/mbed_retarget.cpp b/platform/source/mbed_retarget.cpp index 44b517d9349..07f824c2ca0 100644 --- a/platform/source/mbed_retarget.cpp +++ b/platform/source/mbed_retarget.cpp @@ -510,7 +510,7 @@ extern "C" std::FILE *fdopen(int fildes, const char *mode) { // This is to avoid scanf and the bloat it brings. char buf[1 + sizeof fildes]; /* @(integer) */ - MBED_STATIC_ASSERT(sizeof buf == 5, "Integers should be 4 bytes."); + static_assert(sizeof buf == 5, "Integers should be 4 bytes."); buf[0] = '@'; memcpy(buf + 1, &fildes, sizeof fildes); diff --git a/platform/tests/TESTS/mbed_micro/static_assert/test_c.c b/platform/tests/TESTS/mbed_micro/static_assert/test_c.c index adcff7073a3..584a40606d2 100644 --- a/platform/tests/TESTS/mbed_micro/static_assert/test_c.c +++ b/platform/tests/TESTS/mbed_micro/static_assert/test_c.c @@ -22,36 +22,36 @@ // multiple asserts are used to guarantee no conflicts occur in generated labels // Test for static asserts in global context -MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char), - "An int must be larger than char"); -MBED_STATIC_ASSERT(2 + 2 == 4, - "Hopefully the universe is mathematically consistent"); -MBED_STATIC_ASSERT(THE_ANSWER == 42, - "Said Deep Thought, with infinite majesty and calm"); +static_assert(sizeof(int) >= sizeof(char), + "An int must be larger than char"); +static_assert(2 + 2 == 4, + "Hopefully the universe is mathematically consistent"); +static_assert(THE_ANSWER == 42, + "Said Deep Thought, with infinite majesty and calm"); struct test { int dummy; // Test for static asserts in struct context - MBED_STRUCT_STATIC_ASSERT(sizeof(int) >= sizeof(char), - "An int must be larger than char"); - MBED_STRUCT_STATIC_ASSERT(2 + 2 == 4, - "Hopefully the universe is mathematically consistent"); - MBED_STRUCT_STATIC_ASSERT(THE_ANSWER == 42, - "Said Deep Thought, with infinite majesty and calm"); + static_assert(sizeof(int) >= sizeof(char), + "An int must be larger than char"); + static_assert(2 + 2 == 4, + "Hopefully the universe is mathematically consistent"); + static_assert(THE_ANSWER == 42, + "Said Deep Thought, with infinite majesty and calm"); }; -MBED_STATIC_ASSERT(sizeof(struct test) == sizeof(int), - "Static assertions should not change the size of a struct"); +static_assert(sizeof(struct test) == sizeof(int), + "Static assertions should not change the size of a struct"); void doit_c(void) { // Test for static asserts in function context - MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char), - "An int must be larger than char"); - MBED_STATIC_ASSERT(2 + 2 == 4, - "Hopefully the universe is mathematically consistent"); - MBED_STATIC_ASSERT(THE_ANSWER == 42, - "Said Deep Thought, with infinite majesty and calm"); + static_assert(sizeof(int) >= sizeof(char), + "An int must be larger than char"); + static_assert(2 + 2 == 4, + "Hopefully the universe is mathematically consistent"); + static_assert(THE_ANSWER == 42, + "Said Deep Thought, with infinite majesty and calm"); } diff --git a/platform/tests/TESTS/mbed_micro/static_assert/test_cpp.cpp b/platform/tests/TESTS/mbed_micro/static_assert/test_cpp.cpp index 024e4970cfc..17e1af40a0a 100644 --- a/platform/tests/TESTS/mbed_micro/static_assert/test_cpp.cpp +++ b/platform/tests/TESTS/mbed_micro/static_assert/test_cpp.cpp @@ -22,43 +22,43 @@ // multiple asserts are used to guarantee no conflicts occur in generated labels // Test for static asserts in global context -MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char), - "An int must be larger than char"); -MBED_STATIC_ASSERT(2 + 2 == 4, - "Hopefully the universe is mathematically consistent"); -MBED_STATIC_ASSERT(THE_ANSWER == 42, - "Said Deep Thought, with infinite majesty and calm"); +static_assert(sizeof(int) >= sizeof(char), + "An int must be larger than char"); +static_assert(2 + 2 == 4, + "Hopefully the universe is mathematically consistent"); +static_assert(THE_ANSWER == 42, + "Said Deep Thought, with infinite majesty and calm"); struct test { int dummy; // Test for static asserts in struct context - MBED_STRUCT_STATIC_ASSERT(sizeof(int) >= sizeof(char), - "An int must be larger than char"); - MBED_STRUCT_STATIC_ASSERT(2 + 2 == 4, - "Hopefully the universe is mathematically consistent"); - MBED_STRUCT_STATIC_ASSERT(THE_ANSWER == 42, - "Said Deep Thought, with infinite majesty and calm"); + static_assert(sizeof(int) >= sizeof(char), + "An int must be larger than char"); + static_assert(2 + 2 == 4, + "Hopefully the universe is mathematically consistent"); + static_assert(THE_ANSWER == 42, + "Said Deep Thought, with infinite majesty and calm"); - MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char), - "An int must be larger than char"); - MBED_STATIC_ASSERT(2 + 2 == 4, - "Hopefully the universe is mathematically consistent"); - MBED_STATIC_ASSERT(THE_ANSWER == 42, - "Said Deep Thought, with infinite majesty and calm"); + static_assert(sizeof(int) >= sizeof(char), + "An int must be larger than char"); + static_assert(2 + 2 == 4, + "Hopefully the universe is mathematically consistent"); + static_assert(THE_ANSWER == 42, + "Said Deep Thought, with infinite majesty and calm"); }; -MBED_STATIC_ASSERT(sizeof(struct test) == sizeof(int), - "Static assertions should not change the size of a struct"); +static_assert(sizeof(struct test) == sizeof(int), + "Static assertions should not change the size of a struct"); void doit_c(void) { // Test for static asserts in function context - MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char), - "An int must be larger than char"); - MBED_STATIC_ASSERT(2 + 2 == 4, - "Hopefully the universe is mathematically consistent"); - MBED_STATIC_ASSERT(THE_ANSWER == 42, - "Said Deep Thought, with infinite majesty and calm"); + static_assert(sizeof(int) >= sizeof(char), + "An int must be larger than char"); + static_assert(2 + 2 == 4, + "Hopefully the universe is mathematically consistent"); + static_assert(THE_ANSWER == 42, + "Said Deep Thought, with infinite majesty and calm"); } diff --git a/rtos/include/rtos/MemoryPool.h b/rtos/include/rtos/MemoryPool.h index 32d2255bfb6..14903504528 100644 --- a/rtos/include/rtos/MemoryPool.h +++ b/rtos/include/rtos/MemoryPool.h @@ -57,7 +57,7 @@ namespace rtos { */ template class MemoryPool : private mbed::NonCopyable > { - MBED_STATIC_ASSERT(pool_sz > 0, "Invalid memory pool size. Must be greater than 0."); + static_assert(pool_sz > 0, "Invalid memory pool size. Must be greater than 0."); public: /** Create and Initialize a memory pool. * diff --git a/rtos/source/Thread.cpp b/rtos/source/Thread.cpp index cfd1b20b458..8d1fa927a4e 100644 --- a/rtos/source/Thread.cpp +++ b/rtos/source/Thread.cpp @@ -31,12 +31,12 @@ #if MBED_CONF_RTOS_PRESENT #define ALIGN_UP(pos, align) ((pos) % (align) ? (pos) + ((align) - (pos) % (align)) : (pos)) -MBED_STATIC_ASSERT(ALIGN_UP(0, 8) == 0, "ALIGN_UP macro error"); -MBED_STATIC_ASSERT(ALIGN_UP(1, 8) == 8, "ALIGN_UP macro error"); +static_assert(ALIGN_UP(0, 8) == 0, "ALIGN_UP macro error"); +static_assert(ALIGN_UP(1, 8) == 8, "ALIGN_UP macro error"); #define ALIGN_DOWN(pos, align) ((pos) - ((pos) % (align))) -MBED_STATIC_ASSERT(ALIGN_DOWN(7, 8) == 0, "ALIGN_DOWN macro error"); -MBED_STATIC_ASSERT(ALIGN_DOWN(8, 8) == 8, "ALIGN_DOWN macro error"); +static_assert(ALIGN_DOWN(7, 8) == 0, "ALIGN_DOWN macro error"); +static_assert(ALIGN_DOWN(8, 8) == 8, "ALIGN_DOWN macro error"); namespace rtos { diff --git a/storage/blockdevice/COMPONENT_SD/source/SDBlockDevice.cpp b/storage/blockdevice/COMPONENT_SD/source/SDBlockDevice.cpp index 436551da2b5..ad90a4e6b3d 100644 --- a/storage/blockdevice/COMPONENT_SD/source/SDBlockDevice.cpp +++ b/storage/blockdevice/COMPONENT_SD/source/SDBlockDevice.cpp @@ -264,8 +264,8 @@ SDBlockDevice::SDBlockDevice(PinName mosi, PinName miso, PinName sclk, PinName c _card_type = SDCARD_NONE; // Set default to 100kHz for initialisation and 1MHz for data transfer - MBED_STATIC_ASSERT(((MBED_CONF_SD_INIT_FREQUENCY >= 100000) && (MBED_CONF_SD_INIT_FREQUENCY <= 400000)), - "Initialization frequency should be between 100KHz to 400KHz"); + static_assert(((MBED_CONF_SD_INIT_FREQUENCY >= 100000) && (MBED_CONF_SD_INIT_FREQUENCY <= 400000)), + "Initialization frequency should be between 100KHz to 400KHz"); _init_sck = MBED_CONF_SD_INIT_FREQUENCY; _transfer_sck = hz; @@ -285,8 +285,8 @@ SDBlockDevice::SDBlockDevice(const spi_pinmap_t &spi_pinmap, PinName cs, uint64_ _card_type = SDCARD_NONE; // Set default to 100kHz for initialisation and 1MHz for data transfer - MBED_STATIC_ASSERT(((MBED_CONF_SD_INIT_FREQUENCY >= 100000) && (MBED_CONF_SD_INIT_FREQUENCY <= 400000)), - "Initialization frequency should be between 100KHz to 400KHz"); + static_assert(((MBED_CONF_SD_INIT_FREQUENCY >= 100000) && (MBED_CONF_SD_INIT_FREQUENCY <= 400000)), + "Initialization frequency should be between 100KHz to 400KHz"); _init_sck = MBED_CONF_SD_INIT_FREQUENCY; _transfer_sck = hz; diff --git a/targets/TARGET_NUVOTON/TARGET_M2351/device/system_M2351.c b/targets/TARGET_NUVOTON/TARGET_M2351/device/system_M2351.c index d0f957e9c9a..e03cf915a03 100644 --- a/targets/TARGET_NUVOTON/TARGET_M2351/device/system_M2351.c +++ b/targets/TARGET_NUVOTON/TARGET_M2351/device/system_M2351.c @@ -49,9 +49,9 @@ const uint32_t gau32ClkSrcTbl[] = {__HXT, __LXT, 0UL, __LIRC, 0UL, __HIRC48, 0UL /* The configuration of TDB internal storage area defined in "partition_M2351_mem.h" * must match "tdb_internal/mbed_lib.json", so it can pass to linker files for * memory layout check. */ -MBED_STATIC_ASSERT(NU_TDB_INTERNAL_STORAGE_START == MBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_BASE_ADDRESS, +static_assert(NU_TDB_INTERNAL_STORAGE_START == MBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_BASE_ADDRESS, "NU_TDB_INTERNAL_STORAGE_START must be equal to MBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_BASE_ADDRESS"); -MBED_STATIC_ASSERT(NU_TDB_INTERNAL_STORAGE_SIZE == MBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_SIZE, +static_assert(NU_TDB_INTERNAL_STORAGE_SIZE == MBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_SIZE, "NU_TDB_INTERNAL_STORAGE_SIZE must be equal to MBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_SIZE"); #endif diff --git a/targets/TARGET_NUVOTON/TARGET_M2351/gpio_irq_api.c b/targets/TARGET_NUVOTON/TARGET_M2351/gpio_irq_api.c index c3f9426d328..8dbb8dc7372 100644 --- a/targets/TARGET_NUVOTON/TARGET_M2351/gpio_irq_api.c +++ b/targets/TARGET_NUVOTON/TARGET_M2351/gpio_irq_api.c @@ -161,7 +161,7 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) GPIO_T *gpio_base = NU_PORT_BASE(port_index); /* We assume BSP has such coding so that we can easily add/remove either irq type. */ - MBED_STATIC_ASSERT(GPIO_INT_BOTH_EDGE == (GPIO_INT_RISING | GPIO_INT_FALLING), + static_assert(GPIO_INT_BOTH_EDGE == (GPIO_INT_RISING | GPIO_INT_FALLING), "GPIO_INT_BOTH_EDGE must be bitwise OR of GPIO_INT_RISING and GPIO_INT_FALLING"); uint32_t irq_type; switch (event) { diff --git a/targets/TARGET_NUVOTON/TARGET_M251/gpio_irq_api.c b/targets/TARGET_NUVOTON/TARGET_M251/gpio_irq_api.c index 2fd60ee4e0f..d471893f4ae 100644 --- a/targets/TARGET_NUVOTON/TARGET_M251/gpio_irq_api.c +++ b/targets/TARGET_NUVOTON/TARGET_M251/gpio_irq_api.c @@ -157,7 +157,7 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) GPIO_T *gpio_base = NU_PORT_BASE(port_index); /* We assume BSP has such coding so that we can easily add/remove either irq type. */ - MBED_STATIC_ASSERT(GPIO_INT_BOTH_EDGE == (GPIO_INT_RISING | GPIO_INT_FALLING), + static_assert(GPIO_INT_BOTH_EDGE == (GPIO_INT_RISING | GPIO_INT_FALLING), "GPIO_INT_BOTH_EDGE must be bitwise OR of GPIO_INT_RISING and GPIO_INT_FALLING"); uint32_t irq_type; switch (event) { diff --git a/targets/TARGET_NUVOTON/TARGET_M261/gpio_irq_api.c b/targets/TARGET_NUVOTON/TARGET_M261/gpio_irq_api.c index 9173b2f144a..b36d4ff50cf 100644 --- a/targets/TARGET_NUVOTON/TARGET_M261/gpio_irq_api.c +++ b/targets/TARGET_NUVOTON/TARGET_M261/gpio_irq_api.c @@ -158,7 +158,7 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) GPIO_T *gpio_base = NU_PORT_BASE(port_index); /* We assume BSP has such coding so that we can easily add/remove either irq type. */ - MBED_STATIC_ASSERT(GPIO_INT_BOTH_EDGE == (GPIO_INT_RISING | GPIO_INT_FALLING), + static_assert(GPIO_INT_BOTH_EDGE == (GPIO_INT_RISING | GPIO_INT_FALLING), "GPIO_INT_BOTH_EDGE must be bitwise OR of GPIO_INT_RISING and GPIO_INT_FALLING"); uint32_t irq_type; switch (event) { diff --git a/targets/TARGET_NUVOTON/TARGET_M451/gpio_irq_api.c b/targets/TARGET_NUVOTON/TARGET_M451/gpio_irq_api.c index c7538f8d79c..b6ac940dd47 100644 --- a/targets/TARGET_NUVOTON/TARGET_M451/gpio_irq_api.c +++ b/targets/TARGET_NUVOTON/TARGET_M451/gpio_irq_api.c @@ -154,7 +154,7 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) GPIO_T *gpio_base = NU_PORT_BASE(port_index); /* We assume BSP has such coding so that we can easily add/remove either irq type. */ - MBED_STATIC_ASSERT(GPIO_INT_BOTH_EDGE == (GPIO_INT_RISING | GPIO_INT_FALLING), + static_assert(GPIO_INT_BOTH_EDGE == (GPIO_INT_RISING | GPIO_INT_FALLING), "GPIO_INT_BOTH_EDGE must be bitwise OR of GPIO_INT_RISING and GPIO_INT_FALLING"); uint32_t irq_type; switch (event) { diff --git a/targets/TARGET_NUVOTON/TARGET_M480/gpio_irq_api.c b/targets/TARGET_NUVOTON/TARGET_M480/gpio_irq_api.c index 0c5b4eb2b41..ee05cae9cfe 100644 --- a/targets/TARGET_NUVOTON/TARGET_M480/gpio_irq_api.c +++ b/targets/TARGET_NUVOTON/TARGET_M480/gpio_irq_api.c @@ -161,7 +161,7 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) GPIO_T *gpio_base = NU_PORT_BASE(port_index); /* We assume BSP has such coding so that we can easily add/remove either irq type. */ - MBED_STATIC_ASSERT(GPIO_INT_BOTH_EDGE == (GPIO_INT_RISING | GPIO_INT_FALLING), + static_assert(GPIO_INT_BOTH_EDGE == (GPIO_INT_RISING | GPIO_INT_FALLING), "GPIO_INT_BOTH_EDGE must be bitwise OR of GPIO_INT_RISING and GPIO_INT_FALLING"); uint32_t irq_type; switch (event) { diff --git a/targets/TARGET_NUVOTON/TARGET_NANO100/gpio_irq_api.c b/targets/TARGET_NUVOTON/TARGET_NANO100/gpio_irq_api.c index b57681cf07b..faf8b045525 100644 --- a/targets/TARGET_NUVOTON/TARGET_NANO100/gpio_irq_api.c +++ b/targets/TARGET_NUVOTON/TARGET_NANO100/gpio_irq_api.c @@ -176,7 +176,7 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) GPIO_T *gpio_base = NU_PORT_BASE(port_index); /* We assume BSP has such coding so that we can easily add/remove either irq type. */ - MBED_STATIC_ASSERT(GPIO_INT_BOTH_EDGE == (GPIO_INT_RISING | GPIO_INT_FALLING), + static_assert(GPIO_INT_BOTH_EDGE == (GPIO_INT_RISING | GPIO_INT_FALLING), "GPIO_INT_BOTH_EDGE must be bitwise OR of GPIO_INT_RISING and GPIO_INT_FALLING"); uint32_t irq_type; switch (event) { diff --git a/targets/TARGET_NUVOTON/TARGET_NUC472/gpio_irq_api.c b/targets/TARGET_NUVOTON/TARGET_NUC472/gpio_irq_api.c index 02fd13ce4ab..fd5a8806073 100644 --- a/targets/TARGET_NUVOTON/TARGET_NUC472/gpio_irq_api.c +++ b/targets/TARGET_NUVOTON/TARGET_NUC472/gpio_irq_api.c @@ -160,7 +160,7 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) GPIO_T *gpio_base = NU_PORT_BASE(port_index); /* We assume BSP has such coding so that we can easily add/remove either irq type. */ - MBED_STATIC_ASSERT(GPIO_INT_BOTH_EDGE == (GPIO_INT_RISING | GPIO_INT_FALLING), + static_assert(GPIO_INT_BOTH_EDGE == (GPIO_INT_RISING | GPIO_INT_FALLING), "GPIO_INT_BOTH_EDGE must be bitwise OR of GPIO_INT_RISING and GPIO_INT_FALLING"); uint32_t irq_type; switch (event) {