Skip to content

Commit 57bbb47

Browse files
authored
Merge pull request #13085 from pea-pod/remove-deprecated-mbed-assert
Change MBED_STATIC_ASSERTs version for built-in
2 parents f227856 + 507181d commit 57bbb47

File tree

30 files changed

+109
-105
lines changed

30 files changed

+109
-105
lines changed

connectivity/FEATURE_BLE/include/ble/common/Duration.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ struct Duration {
141141
Duration(Duration<OtherRep, OtherTB, OtherRange, OtherF> other) :
142142
duration(clamp(other.value() * (OtherTB / TB)))
143143
{
144-
MBED_STATIC_ASSERT(OtherTB >= TB && (OtherTB % TB) == 0, "Incompatible units");
144+
static_assert(OtherTB >= TB && (OtherTB % TB) == 0, "Incompatible units");
145145
}
146146

147147
/**

connectivity/netsocket/source/NetworkStack.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ class NetworkStackWrapper : public NetworkStack {
431431
// Conversion function for network stacks
432432
NetworkStack *nsapi_create_stack(nsapi_stack_t *stack)
433433
{
434-
MBED_STATIC_ASSERT(sizeof stack->_stack_buffer >= sizeof(NetworkStackWrapper),
435-
"The nsapi_stack_t stack buffer must fit a NetworkStackWrapper");
434+
static_assert(sizeof stack->_stack_buffer >= sizeof(NetworkStackWrapper),
435+
"The nsapi_stack_t stack buffer must fit a NetworkStackWrapper");
436436
return new (stack->_stack_buffer) NetworkStackWrapper;
437437
}

drivers/source/MbedCRC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ namespace mbed {
2323

2424
SingletonPtr<PlatformMutex> mbed_crc_mutex;
2525

26-
MBED_STATIC_ASSERT(MBED_CRC_TABLE_SIZE == 0 || MBED_CRC_TABLE_SIZE == 16 || MBED_CRC_TABLE_SIZE == 256,
27-
"Configuration setting drivers.crc-table-size must be set to 0, 16 or 256");
26+
static_assert(MBED_CRC_TABLE_SIZE == 0 || MBED_CRC_TABLE_SIZE == 16 || MBED_CRC_TABLE_SIZE == 256,
27+
"Configuration setting drivers.crc-table-size must be set to 0, 16 or 256");
2828

2929
#if MBED_CRC_TABLE_SIZE > 0
3030

events/source/equeue_mbed.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ static void equeue_tick_update()
106106

107107
void equeue_tick_init()
108108
{
109-
MBED_STATIC_ASSERT(sizeof(equeue_timer) >= sizeof(ALIAS_TIMER),
110-
"The equeue_timer buffer must fit the class Timer");
111-
MBED_STATIC_ASSERT(sizeof(equeue_ticker) >= sizeof(ALIAS_TICKER),
112-
"The equeue_ticker buffer must fit the class Ticker");
109+
static_assert(sizeof(equeue_timer) >= sizeof(ALIAS_TIMER),
110+
"The equeue_timer buffer must fit the class Timer");
111+
static_assert(sizeof(equeue_ticker) >= sizeof(ALIAS_TICKER),
112+
"The equeue_ticker buffer must fit the class Ticker");
113113
ALIAS_TIMER *timer = new (equeue_timer) ALIAS_TIMER;
114114
ALIAS_TICKER *ticker = new (equeue_ticker) ALIAS_TICKER;
115115

@@ -156,7 +156,7 @@ void equeue_mutex_unlock(equeue_mutex_t *m)
156156

157157
#include "rtos/EventFlags.h"
158158

159-
MBED_STATIC_ASSERT(sizeof(equeue_sema_t) == sizeof(rtos::EventFlags), "equeue_sema_t / rtos::EventFlags mismatch");
159+
static_assert(sizeof(equeue_sema_t) == sizeof(rtos::EventFlags), "equeue_sema_t / rtos::EventFlags mismatch");
160160

161161
int equeue_sema_create(equeue_sema_t *s)
162162
{

features/frameworks/utest/utest/utest_specification.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace v1 {
5555
cases(static_cast<const Case*>(static_cast<const CaseType*>(cases))), length(N),
5656
defaults(defaults)
5757
{
58-
MBED_STATIC_ASSERT(
58+
static_assert(
5959
sizeof(CaseType) == sizeof(Case),
6060
"CaseType and Case should have the same size"
6161
);
@@ -69,7 +69,7 @@ namespace v1 {
6969
cases(static_cast<const Case*>(static_cast<const CaseType*>(cases))), length(N),
7070
defaults(defaults)
7171
{
72-
MBED_STATIC_ASSERT(
72+
static_assert(
7373
sizeof(CaseType) == sizeof(Case),
7474
"CaseType and Case should have the same size"
7575
);
@@ -83,7 +83,7 @@ namespace v1 {
8383
cases(static_cast<const Case*>(static_cast<const CaseType*>(cases))), length(N),
8484
defaults(defaults)
8585
{
86-
MBED_STATIC_ASSERT(
86+
static_assert(
8787
sizeof(CaseType) == sizeof(Case),
8888
"CaseType and Case should have the same size"
8989
);
@@ -98,7 +98,7 @@ namespace v1 {
9898
cases(static_cast<const Case*>(static_cast<const CaseType*>(cases))), length(N),
9999
defaults(defaults)
100100
{
101-
MBED_STATIC_ASSERT(
101+
static_assert(
102102
sizeof(CaseType) == sizeof(Case),
103103
"CaseType and Case should have the same size"
104104
);
@@ -122,7 +122,7 @@ namespace v1 {
122122
cases(static_cast<const Case*>(static_cast<const CaseType*>(cases))), length(N),
123123
defaults(defaults)
124124
{
125-
MBED_STATIC_ASSERT(
125+
static_assert(
126126
sizeof(CaseType) == sizeof(Case),
127127
"CaseType and Case should have the same size"
128128
);
@@ -137,7 +137,7 @@ namespace v1 {
137137
cases(static_cast<const Case*>(static_cast<const CaseType*>(cases))), length(N),
138138
defaults(defaults)
139139
{
140-
MBED_STATIC_ASSERT(
140+
static_assert(
141141
sizeof(CaseType) == sizeof(Case),
142142
"CaseType and Case should have the same size"
143143
);
@@ -153,7 +153,7 @@ namespace v1 {
153153
cases(static_cast<const Case*>(static_cast<const CaseType*>(cases))), length(N),
154154
defaults(defaults)
155155
{
156-
MBED_STATIC_ASSERT(
156+
static_assert(
157157
sizeof(CaseType) == sizeof(Case),
158158
"CaseType and Case should have the same size"
159159
);

hal/source/mbed_pinmap_default.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ static const PinList ff_arduino_list = {
4242
ff_arduino_pins
4343
};
4444

45-
MBED_STATIC_ASSERT(sizeof(ff_arduino_pins) / sizeof(ff_arduino_pins[0]) == sizeof(ff_arduino_names) / sizeof(ff_arduino_names[0]),
46-
"Arrays must have the same length");
45+
static_assert(sizeof(ff_arduino_pins) / sizeof(ff_arduino_pins[0]) == sizeof(ff_arduino_names) / sizeof(ff_arduino_names[0]),
46+
"Arrays must have the same length");
4747

4848
const PinList *pinmap_ff_arduino_pins()
4949
{

hal/source/mpu/mbed_mpu_v7m.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#endif
3434
#define MBED_MPU_RAM_START (MBED_MPU_ROM_END + 1)
3535

36-
MBED_STATIC_ASSERT(
36+
static_assert(
3737
MBED_MPU_ROM_END == 0x04000000 - 1 ||
3838
MBED_MPU_ROM_END == 0x08000000 - 1 ||
3939
MBED_MPU_ROM_END == 0x0C000000 - 1 ||

hal/source/mpu/mbed_mpu_v8m.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
#endif
3434
#define MBED_MPU_RAM_START (MBED_MPU_ROM_END + 1)
3535

36-
MBED_STATIC_ASSERT(MBED_MPU_ROM_END <= 0x20000000 - 1,
37-
"Unsupported value for MBED_MPU_ROM_END");
36+
static_assert(MBED_MPU_ROM_END <= 0x20000000 - 1,
37+
"Unsupported value for MBED_MPU_ROM_END");
3838

3939
void mbed_mpu_init()
4040
{

platform/cxxsupport/mstd_atomic

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <mstd_memory>
2424
#include <mstd_type_traits>
2525
#include <mstd_utility>
26-
#include "platform/mbed_assert.h"
2726
#include "platform/mbed_atomic.h"
2827
#include "platform/mbed_critical.h"
2928
#include "platform/CriticalSectionLock.h"
@@ -477,7 +476,7 @@ protected:
477476
*/
478477
template<typename T, typename A = atomic_container_t<T>>
479478
struct AtomicBaseInt {
480-
MBED_STRUCT_STATIC_ASSERT(sizeof(T) == sizeof(A), "AtomicBaseInt size mismatch");
479+
static_assert(sizeof(T) == sizeof(A), "AtomicBaseInt size mismatch");
481480
using value_type = T;
482481
AtomicBaseInt() noexcept = default;
483482
constexpr AtomicBaseInt(T v) noexcept : u(A(v))

platform/include/platform/CircularBuffer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ class CircularBuffer {
7070
public:
7171
CircularBuffer() : _head(0), _tail(0), _full(false)
7272
{
73-
MBED_STATIC_ASSERT(
73+
static_assert(
7474
internal::is_unsigned<CounterType>::value,
7575
"CounterType must be unsigned"
7676
);
7777

78-
MBED_STATIC_ASSERT(
78+
static_assert(
7979
(sizeof(CounterType) >= sizeof(uint32_t)) ||
8080
(BufferSize < (((uint64_t) 1) << (sizeof(CounterType) * 8))),
8181
"Invalid BufferSize for the CounterType"

platform/include/platform/Span.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ struct Span {
249249
*/
250250
static const index_type extent = Extent;
251251

252-
MBED_STATIC_ASSERT(Extent >= 0, "Invalid extent for a Span");
252+
static_assert(Extent >= 0, "Invalid extent for a Span");
253253

254254
/**
255255
* Construct an empty Span.
@@ -262,7 +262,7 @@ struct Span {
262262
Span() :
263263
_data(NULL)
264264
{
265-
MBED_STATIC_ASSERT(
265+
static_assert(
266266
Extent == 0,
267267
"Cannot default construct a static-extent Span (unless Extent is 0)"
268268
);
@@ -333,7 +333,7 @@ struct Span {
333333
Span(const Span<OtherElementType, Extent> &other):
334334
_data(other.data())
335335
{
336-
MBED_STATIC_ASSERT(
336+
static_assert(
337337
(span_detail::is_convertible<OtherElementType (*)[1], ElementType (*)[1]>::value),
338338
"OtherElementType(*)[] should be convertible to ElementType (*)[]"
339339
);
@@ -440,7 +440,7 @@ struct Span {
440440
template<ptrdiff_t Count>
441441
Span<element_type, Count> first() const
442442
{
443-
MBED_STATIC_ASSERT(
443+
static_assert(
444444
(0 <= Count) && (Count <= Extent),
445445
"Invalid subspan extent"
446446
);
@@ -459,7 +459,7 @@ struct Span {
459459
template<ptrdiff_t Count>
460460
Span<element_type, Count> last() const
461461
{
462-
MBED_STATIC_ASSERT(
462+
static_assert(
463463
(0 <= Count) && (Count <= Extent),
464464
"Invalid subspan extent"
465465
);
@@ -484,11 +484,11 @@ struct Span {
484484
Span<element_type, Count == SPAN_DYNAMIC_EXTENT ? Extent - Offset : Count>
485485
subspan() const
486486
{
487-
MBED_STATIC_ASSERT(
487+
static_assert(
488488
0 <= Offset && Offset <= Extent,
489489
"Invalid subspan offset"
490490
);
491-
MBED_STATIC_ASSERT(
491+
static_assert(
492492
(Count == SPAN_DYNAMIC_EXTENT) ||
493493
(0 <= Count && (Count + Offset) <= Extent),
494494
"Invalid subspan count"
@@ -678,7 +678,7 @@ struct Span<ElementType, SPAN_DYNAMIC_EXTENT> {
678678
Span(const Span<OtherElementType, OtherExtent> &other):
679679
_data(other.data()), _size(other.size())
680680
{
681-
MBED_STATIC_ASSERT(
681+
static_assert(
682682
(span_detail::is_convertible<OtherElementType (*)[1], ElementType (*)[1]>::value),
683683
"OtherElementType(*)[] should be convertible to ElementType (*)[]"
684684
);

platform/include/platform/mbed_assert.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef MBED_ASSERT_H
1818
#define MBED_ASSERT_H
1919

20+
#include <assert.h>
2021
#include "platform/mbed_toolchain.h"
2122

2223
#ifdef __cplusplus
@@ -70,6 +71,10 @@ do { \
7071
} while (0)
7172
#endif
7273

74+
// ARM Compiler 6 currently fails to define `static_assert` in assert.h; correct for this
75+
#if !defined __cplusplus && !defined static_assert
76+
#define static_assert _Static_assert
77+
#endif
7378

7479
/** MBED_STATIC_ASSERT
7580
* Declare compile-time assertions, results in compile-time error if condition is false

platform/include/platform/mbed_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
* master branch code
6565
*/
6666
#define MBED_VERSION_CHECK(major, minor, patch) do { \
67-
MBED_STATIC_ASSERT((MBED_VERSION >= MBED_ENCODE_VERSION((major),(minor),(patch))), "Incompatible mbed-os version detected!!"); \
67+
static_assert((MBED_VERSION >= MBED_ENCODE_VERSION((major),(minor),(patch))), "Incompatible mbed-os version detected!!"); \
6868
} while(0)
6969

7070
#endif

platform/source/CThunkBase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
#include "platform/internal/CThunkBase.h"
2525

26-
MBED_STATIC_ASSERT(MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX < 256, "MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX must be less than 256");
27-
MBED_STATIC_ASSERT(MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX > 0, "MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX must be greater than 0");
26+
static_assert(MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX < 256, "MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX must be less than 256");
27+
static_assert(MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX > 0, "MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX must be greater than 0");
2828

2929
#define ENABLE_N(N) ((MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX & N) ? 1 : 0)
3030

platform/source/SysTimer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ void SysTimer<Period, IRQ>::handler()
342342

343343
#if MBED_CONF_RTOS_PRESENT
344344
/* Whatever the OS wants (in case it isn't 1ms) */
345-
MBED_STATIC_ASSERT(1000000 % OS_TICK_FREQ == 0, "OS_TICK_FREQ must be a divisor of 1000000 for correct tick calculations");
345+
static_assert(1000000 % OS_TICK_FREQ == 0, "OS_TICK_FREQ must be a divisor of 1000000 for correct tick calculations");
346346
#define OS_TICK_US (1000000 / OS_TICK_FREQ)
347347
#if OS_TICK_US != 1000
348348
template class SysTimer<std::ratio_multiply<std::ratio<OS_TICK_US>, std::micro>>;

platform/source/mbed_atomic_impl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
#include "platform/mbed_critical.h"
2121

2222
/* Inline bool implementations in the header use uint8_t versions to manipulate the bool */
23-
MBED_STATIC_ASSERT(sizeof(bool) == sizeof(uint8_t), "Surely bool is a byte");
23+
static_assert(sizeof(bool) == sizeof(uint8_t), "Surely bool is a byte");
2424

2525
/* Inline implementations in the header use uint32_t versions to manipulate pointers */
26-
MBED_STATIC_ASSERT(sizeof(void *) == sizeof(uint32_t), "Alas, pointers must be 32-bit");
26+
static_assert(sizeof(void *) == sizeof(uint32_t), "Alas, pointers must be 32-bit");
2727

2828

2929
#define DO_MBED_LOCKED_OP(name, OP, retValue, T, fn_suffix) \

platform/source/mbed_retarget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ extern "C" std::FILE *fdopen(int fildes, const char *mode)
510510
{
511511
// This is to avoid scanf and the bloat it brings.
512512
char buf[1 + sizeof fildes]; /* @(integer) */
513-
MBED_STATIC_ASSERT(sizeof buf == 5, "Integers should be 4 bytes.");
513+
static_assert(sizeof buf == 5, "Integers should be 4 bytes.");
514514
buf[0] = '@';
515515
memcpy(buf + 1, &fildes, sizeof fildes);
516516

platform/tests/TESTS/mbed_micro/static_assert/test_c.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,36 @@
2222
// multiple asserts are used to guarantee no conflicts occur in generated labels
2323

2424
// Test for static asserts in global context
25-
MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
26-
"An int must be larger than char");
27-
MBED_STATIC_ASSERT(2 + 2 == 4,
28-
"Hopefully the universe is mathematically consistent");
29-
MBED_STATIC_ASSERT(THE_ANSWER == 42,
30-
"Said Deep Thought, with infinite majesty and calm");
25+
static_assert(sizeof(int) >= sizeof(char),
26+
"An int must be larger than char");
27+
static_assert(2 + 2 == 4,
28+
"Hopefully the universe is mathematically consistent");
29+
static_assert(THE_ANSWER == 42,
30+
"Said Deep Thought, with infinite majesty and calm");
3131

3232
struct test {
3333
int dummy;
3434

3535
// Test for static asserts in struct context
36-
MBED_STRUCT_STATIC_ASSERT(sizeof(int) >= sizeof(char),
37-
"An int must be larger than char");
38-
MBED_STRUCT_STATIC_ASSERT(2 + 2 == 4,
39-
"Hopefully the universe is mathematically consistent");
40-
MBED_STRUCT_STATIC_ASSERT(THE_ANSWER == 42,
41-
"Said Deep Thought, with infinite majesty and calm");
36+
static_assert(sizeof(int) >= sizeof(char),
37+
"An int must be larger than char");
38+
static_assert(2 + 2 == 4,
39+
"Hopefully the universe is mathematically consistent");
40+
static_assert(THE_ANSWER == 42,
41+
"Said Deep Thought, with infinite majesty and calm");
4242
};
4343

44-
MBED_STATIC_ASSERT(sizeof(struct test) == sizeof(int),
45-
"Static assertions should not change the size of a struct");
44+
static_assert(sizeof(struct test) == sizeof(int),
45+
"Static assertions should not change the size of a struct");
4646

4747
void doit_c(void)
4848
{
4949
// Test for static asserts in function context
50-
MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
51-
"An int must be larger than char");
52-
MBED_STATIC_ASSERT(2 + 2 == 4,
53-
"Hopefully the universe is mathematically consistent");
54-
MBED_STATIC_ASSERT(THE_ANSWER == 42,
55-
"Said Deep Thought, with infinite majesty and calm");
50+
static_assert(sizeof(int) >= sizeof(char),
51+
"An int must be larger than char");
52+
static_assert(2 + 2 == 4,
53+
"Hopefully the universe is mathematically consistent");
54+
static_assert(THE_ANSWER == 42,
55+
"Said Deep Thought, with infinite majesty and calm");
5656
}
5757

0 commit comments

Comments
 (0)