Skip to content

Commit

Permalink
Merge pull request ARMmbed#13085 from pea-pod/remove-deprecated-mbed-…
Browse files Browse the repository at this point in the history
…assert

Change MBED_STATIC_ASSERTs version for built-in
  • Loading branch information
0xc0170 committed Nov 24, 2020
2 parents f227856 + 507181d commit 57bbb47
Show file tree
Hide file tree
Showing 30 changed files with 109 additions and 105 deletions.
2 changes: 1 addition & 1 deletion connectivity/FEATURE_BLE/include/ble/common/Duration.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ struct Duration {
Duration(Duration<OtherRep, OtherTB, OtherRange, OtherF> 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");
}

/**
Expand Down
4 changes: 2 additions & 2 deletions connectivity/netsocket/source/NetworkStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions drivers/source/MbedCRC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ namespace mbed {

SingletonPtr<PlatformMutex> 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

Expand Down
10 changes: 5 additions & 5 deletions events/source/equeue_mbed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
{
Expand Down
14 changes: 7 additions & 7 deletions features/frameworks/utest/utest/utest_specification.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace v1 {
cases(static_cast<const Case*>(static_cast<const CaseType*>(cases))), length(N),
defaults(defaults)
{
MBED_STATIC_ASSERT(
static_assert(
sizeof(CaseType) == sizeof(Case),
"CaseType and Case should have the same size"
);
Expand All @@ -69,7 +69,7 @@ namespace v1 {
cases(static_cast<const Case*>(static_cast<const CaseType*>(cases))), length(N),
defaults(defaults)
{
MBED_STATIC_ASSERT(
static_assert(
sizeof(CaseType) == sizeof(Case),
"CaseType and Case should have the same size"
);
Expand All @@ -83,7 +83,7 @@ namespace v1 {
cases(static_cast<const Case*>(static_cast<const CaseType*>(cases))), length(N),
defaults(defaults)
{
MBED_STATIC_ASSERT(
static_assert(
sizeof(CaseType) == sizeof(Case),
"CaseType and Case should have the same size"
);
Expand All @@ -98,7 +98,7 @@ namespace v1 {
cases(static_cast<const Case*>(static_cast<const CaseType*>(cases))), length(N),
defaults(defaults)
{
MBED_STATIC_ASSERT(
static_assert(
sizeof(CaseType) == sizeof(Case),
"CaseType and Case should have the same size"
);
Expand All @@ -122,7 +122,7 @@ namespace v1 {
cases(static_cast<const Case*>(static_cast<const CaseType*>(cases))), length(N),
defaults(defaults)
{
MBED_STATIC_ASSERT(
static_assert(
sizeof(CaseType) == sizeof(Case),
"CaseType and Case should have the same size"
);
Expand All @@ -137,7 +137,7 @@ namespace v1 {
cases(static_cast<const Case*>(static_cast<const CaseType*>(cases))), length(N),
defaults(defaults)
{
MBED_STATIC_ASSERT(
static_assert(
sizeof(CaseType) == sizeof(Case),
"CaseType and Case should have the same size"
);
Expand All @@ -153,7 +153,7 @@ namespace v1 {
cases(static_cast<const Case*>(static_cast<const CaseType*>(cases))), length(N),
defaults(defaults)
{
MBED_STATIC_ASSERT(
static_assert(
sizeof(CaseType) == sizeof(Case),
"CaseType and Case should have the same size"
);
Expand Down
4 changes: 2 additions & 2 deletions hal/source/mbed_pinmap_default.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion hal/source/mpu/mbed_mpu_v7m.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
4 changes: 2 additions & 2 deletions hal/source/mpu/mbed_mpu_v8m.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
3 changes: 1 addition & 2 deletions platform/cxxsupport/mstd_atomic
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <mstd_memory>
#include <mstd_type_traits>
#include <mstd_utility>
#include "platform/mbed_assert.h"
#include "platform/mbed_atomic.h"
#include "platform/mbed_critical.h"
#include "platform/CriticalSectionLock.h"
Expand Down Expand Up @@ -477,7 +476,7 @@ protected:
*/
template<typename T, typename A = atomic_container_t<T>>
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))
Expand Down
4 changes: 2 additions & 2 deletions platform/include/platform/CircularBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ class CircularBuffer {
public:
CircularBuffer() : _head(0), _tail(0), _full(false)
{
MBED_STATIC_ASSERT(
static_assert(
internal::is_unsigned<CounterType>::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"
Expand Down
16 changes: 8 additions & 8 deletions platform/include/platform/Span.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)"
);
Expand Down Expand Up @@ -333,7 +333,7 @@ struct Span {
Span(const Span<OtherElementType, Extent> &other):
_data(other.data())
{
MBED_STATIC_ASSERT(
static_assert(
(span_detail::is_convertible<OtherElementType (*)[1], ElementType (*)[1]>::value),
"OtherElementType(*)[] should be convertible to ElementType (*)[]"
);
Expand Down Expand Up @@ -440,7 +440,7 @@ struct Span {
template<ptrdiff_t Count>
Span<element_type, Count> first() const
{
MBED_STATIC_ASSERT(
static_assert(
(0 <= Count) && (Count <= Extent),
"Invalid subspan extent"
);
Expand All @@ -459,7 +459,7 @@ struct Span {
template<ptrdiff_t Count>
Span<element_type, Count> last() const
{
MBED_STATIC_ASSERT(
static_assert(
(0 <= Count) && (Count <= Extent),
"Invalid subspan extent"
);
Expand All @@ -484,11 +484,11 @@ struct Span {
Span<element_type, Count == SPAN_DYNAMIC_EXTENT ? Extent - Offset : Count>
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"
Expand Down Expand Up @@ -678,7 +678,7 @@ struct Span<ElementType, SPAN_DYNAMIC_EXTENT> {
Span(const Span<OtherElementType, OtherExtent> &other):
_data(other.data()), _size(other.size())
{
MBED_STATIC_ASSERT(
static_assert(
(span_detail::is_convertible<OtherElementType (*)[1], ElementType (*)[1]>::value),
"OtherElementType(*)[] should be convertible to ElementType (*)[]"
);
Expand Down
5 changes: 5 additions & 0 deletions platform/include/platform/mbed_assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef MBED_ASSERT_H
#define MBED_ASSERT_H

#include <assert.h>
#include "platform/mbed_toolchain.h"

#ifdef __cplusplus
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion platform/include/platform/mbed_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions platform/source/CThunkBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion platform/source/SysTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ void SysTimer<Period, IRQ>::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::ratio_multiply<std::ratio<OS_TICK_US>, std::micro>>;
Expand Down
4 changes: 2 additions & 2 deletions platform/source/mbed_atomic_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
2 changes: 1 addition & 1 deletion platform/source/mbed_retarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
40 changes: 20 additions & 20 deletions platform/tests/TESTS/mbed_micro/static_assert/test_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Loading

0 comments on commit 57bbb47

Please sign in to comment.