Skip to content

Commit db5b4e7

Browse files
committed
Change MBED_STATIC_ASSERTs version for built-in
1 parent a28e809 commit db5b4e7

File tree

30 files changed

+87
-89
lines changed

30 files changed

+87
-89
lines changed

TESTS/mbedmicro-mbed/static_assert/test_c.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,43 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
#include "mbed_assert.h"
18+
#include <assert.h>
1919
#define THE_ANSWER 42
2020

2121
// Tests for static asserts in different contexts
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),
25+
static_assert(sizeof(int) >= sizeof(char),
2626
"An int must be larger than char");
27-
MBED_STATIC_ASSERT(2 + 2 == 4,
27+
static_assert(2 + 2 == 4,
2828
"Hopefully the universe is mathematically consistent");
29-
MBED_STATIC_ASSERT(THE_ANSWER == 42,
29+
static_assert(THE_ANSWER == 42,
3030
"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),
36+
static_assert(sizeof(int) >= sizeof(char),
3737
"An int must be larger than char");
38-
MBED_STRUCT_STATIC_ASSERT(2 + 2 == 4,
38+
static_assert(2 + 2 == 4,
3939
"Hopefully the universe is mathematically consistent");
40-
MBED_STRUCT_STATIC_ASSERT(THE_ANSWER == 42,
40+
static_assert(THE_ANSWER == 42,
4141
"Said Deep Thought, with infinite majesty and calm");
4242
};
4343

44-
MBED_STATIC_ASSERT(sizeof(struct test) == sizeof(int),
44+
static_assert(sizeof(struct test) == sizeof(int),
4545
"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),
50+
static_assert(sizeof(int) >= sizeof(char),
5151
"An int must be larger than char");
52-
MBED_STATIC_ASSERT(2 + 2 == 4,
52+
static_assert(2 + 2 == 4,
5353
"Hopefully the universe is mathematically consistent");
54-
MBED_STATIC_ASSERT(THE_ANSWER == 42,
54+
static_assert(THE_ANSWER == 42,
5555
"Said Deep Thought, with infinite majesty and calm");
5656
}
5757

TESTS/mbedmicro-mbed/static_assert/test_cpp.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,43 @@
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),
25+
static_assert(sizeof(int) >= sizeof(char),
2626
"An int must be larger than char");
27-
MBED_STATIC_ASSERT(2 + 2 == 4,
27+
static_assert(2 + 2 == 4,
2828
"Hopefully the universe is mathematically consistent");
29-
MBED_STATIC_ASSERT(THE_ANSWER == 42,
29+
static_assert(THE_ANSWER == 42,
3030
"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),
36+
static_assert(sizeof(int) >= sizeof(char),
3737
"An int must be larger than char");
38-
MBED_STRUCT_STATIC_ASSERT(2 + 2 == 4,
38+
static_assert(2 + 2 == 4,
3939
"Hopefully the universe is mathematically consistent");
40-
MBED_STRUCT_STATIC_ASSERT(THE_ANSWER == 42,
40+
static_assert(THE_ANSWER == 42,
4141
"Said Deep Thought, with infinite majesty and calm");
4242

43-
MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
43+
static_assert(sizeof(int) >= sizeof(char),
4444
"An int must be larger than char");
45-
MBED_STATIC_ASSERT(2 + 2 == 4,
45+
static_assert(2 + 2 == 4,
4646
"Hopefully the universe is mathematically consistent");
47-
MBED_STATIC_ASSERT(THE_ANSWER == 42,
47+
static_assert(THE_ANSWER == 42,
4848
"Said Deep Thought, with infinite majesty and calm");
4949
};
5050

51-
MBED_STATIC_ASSERT(sizeof(struct test) == sizeof(int),
51+
static_assert(sizeof(struct test) == sizeof(int),
5252
"Static assertions should not change the size of a struct");
5353

5454
void doit_c(void)
5555
{
5656
// Test for static asserts in function context
57-
MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
57+
static_assert(sizeof(int) >= sizeof(char),
5858
"An int must be larger than char");
59-
MBED_STATIC_ASSERT(2 + 2 == 4,
59+
static_assert(2 + 2 == 4,
6060
"Hopefully the universe is mathematically consistent");
61-
MBED_STATIC_ASSERT(THE_ANSWER == 42,
61+
static_assert(THE_ANSWER == 42,
6262
"Said Deep Thought, with infinite majesty and calm");
6363
}
6464

components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ SDBlockDevice::SDBlockDevice(PinName mosi, PinName miso, PinName sclk, PinName c
264264
_card_type = SDCARD_NONE;
265265

266266
// Set default to 100kHz for initialisation and 1MHz for data transfer
267-
MBED_STATIC_ASSERT(((MBED_CONF_SD_INIT_FREQUENCY >= 100000) && (MBED_CONF_SD_INIT_FREQUENCY <= 400000)),
267+
static_assert(((MBED_CONF_SD_INIT_FREQUENCY >= 100000) && (MBED_CONF_SD_INIT_FREQUENCY <= 400000)),
268268
"Initialization frequency should be between 100KHz to 400KHz");
269269
_init_sck = MBED_CONF_SD_INIT_FREQUENCY;
270270
_transfer_sck = hz;
@@ -285,7 +285,7 @@ SDBlockDevice::SDBlockDevice(const spi_pinmap_t &spi_pinmap, PinName cs, uint64_
285285
_card_type = SDCARD_NONE;
286286

287287
// Set default to 100kHz for initialisation and 1MHz for data transfer
288-
MBED_STATIC_ASSERT(((MBED_CONF_SD_INIT_FREQUENCY >= 100000) && (MBED_CONF_SD_INIT_FREQUENCY <= 400000)),
288+
static_assert(((MBED_CONF_SD_INIT_FREQUENCY >= 100000) && (MBED_CONF_SD_INIT_FREQUENCY <= 400000)),
289289
"Initialization frequency should be between 100KHz to 400KHz");
290290
_init_sck = MBED_CONF_SD_INIT_FREQUENCY;
291291
_transfer_sck = hz;

drivers/source/MbedCRC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ 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,
26+
static_assert(MBED_CRC_TABLE_SIZE == 0 || MBED_CRC_TABLE_SIZE == 16 || MBED_CRC_TABLE_SIZE == 256,
2727
"Configuration setting drivers.crc-table-size must be set to 0, 16 or 256");
2828

2929
#if MBED_CRC_TABLE_SIZE > 0

events/source/equeue_mbed.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ static void equeue_tick_update()
105105

106106
void equeue_tick_init()
107107
{
108-
MBED_STATIC_ASSERT(sizeof(equeue_timer) >= sizeof(ALIAS_TIMER),
108+
static_assert(sizeof(equeue_timer) >= sizeof(ALIAS_TIMER),
109109
"The equeue_timer buffer must fit the class Timer");
110-
MBED_STATIC_ASSERT(sizeof(equeue_ticker) >= sizeof(ALIAS_TICKER),
110+
static_assert(sizeof(equeue_ticker) >= sizeof(ALIAS_TICKER),
111111
"The equeue_ticker buffer must fit the class Ticker");
112112
ALIAS_TIMER *timer = new (equeue_timer) ALIAS_TIMER;
113113
ALIAS_TICKER *ticker = new (equeue_ticker) ALIAS_TICKER;
@@ -155,7 +155,7 @@ void equeue_mutex_unlock(equeue_mutex_t *m)
155155

156156
#include "rtos/EventFlags.h"
157157

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

160160
int equeue_sema_create(equeue_sema_t *s)
161161
{

features/FEATURE_BLE/ble/common/Duration.h

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

143143
/**

features/FEATURE_EXPERIMENTAL_API/TARGET_PSA/TARGET_MBED_PSA_SRV/services/crypto/COMPONENT_PSA_SRV_IPC/psa_crypto_spm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@
3030
#include <stdlib.h>
3131
#include <string.h>
3232
#include <stdbool.h>
33+
#include <assert.h>
3334

3435
#include "psa_manifest/sid.h"
3536
#include "psa/client.h"
3637
#include "psa/crypto.h"
3738
#include "crypto_platform_spe.h"
38-
#include "mbed_assert.h"
3939

4040
#define MINOR_VER 1
4141
#define CLIENT_PSA_KEY_ID_SIZE_IN_BYTES 4
4242

43-
MBED_STATIC_ASSERT(sizeof(psa_key_id_t) == CLIENT_PSA_KEY_ID_SIZE_IN_BYTES, "Unexpected psa_key_id_t size");
43+
static_assert(sizeof(psa_key_id_t) == CLIENT_PSA_KEY_ID_SIZE_IN_BYTES, "Unexpected psa_key_id_t size");
4444

4545
/****************************************************************/
4646
/* INTERNAL HELPER FUNCTIONS */

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
);

features/netsocket/NetworkStack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ class NetworkStackWrapper : public NetworkStack {
428428
// Conversion function for network stacks
429429
NetworkStack *nsapi_create_stack(nsapi_stack_t *stack)
430430
{
431-
MBED_STATIC_ASSERT(sizeof stack->_stack_buffer >= sizeof(NetworkStackWrapper),
431+
static_assert(sizeof stack->_stack_buffer >= sizeof(NetworkStackWrapper),
432432
"The nsapi_stack_t stack buffer must fit a NetworkStackWrapper");
433433
return new (stack->_stack_buffer) NetworkStackWrapper;
434434
}

hal/mbed_pinmap_default.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ 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]),
45+
static_assert(sizeof(ff_arduino_pins) / sizeof(ff_arduino_pins[0]) == sizeof(ff_arduino_names) / sizeof(ff_arduino_names[0]),
4646
"Arrays must have the same length");
4747

4848
const PinList *pinmap_ff_arduino_pins()

hal/mpu/mbed_mpu_v7m.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
#include <assert.h>
1718
#include "hal/mpu_api.h"
18-
#include "platform/mbed_assert.h"
1919
#include "cmsis.h"
2020

2121
#if ((__ARM_ARCH_7M__ == 1U) || (__ARM_ARCH_7EM__ == 1U) || (__ARM_ARCH_6M__ == 1U)) && \
@@ -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/mpu/mbed_mpu_v8m.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
#include <assert.h>
1718
#include "hal/mpu_api.h"
18-
#include "platform/mbed_assert.h"
1919
#include "cmsis.h"
2020

2121
#if ((__ARM_ARCH_8M_BASE__ == 1U) || (__ARM_ARCH_8M_MAIN__ == 1U)) && \
@@ -33,7 +33,7 @@
3333
#endif
3434
#define MBED_MPU_RAM_START (MBED_MPU_ROM_END + 1)
3535

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

3939
void mbed_mpu_init()

platform/CircularBuffer.h

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

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

platform/Span.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ struct Span {
238238
*/
239239
static const index_type extent = Extent;
240240

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

243243
/**
244244
* Construct an empty Span.
@@ -251,7 +251,7 @@ struct Span {
251251
Span() :
252252
_data(NULL)
253253
{
254-
MBED_STATIC_ASSERT(
254+
static_assert(
255255
Extent == 0,
256256
"Cannot default construct a static-extent Span (unless Extent is 0)"
257257
);
@@ -322,7 +322,7 @@ struct Span {
322322
Span(const Span<OtherElementType, Extent> &other):
323323
_data(other.data())
324324
{
325-
MBED_STATIC_ASSERT(
325+
static_assert(
326326
(span_detail::is_convertible<OtherElementType (*)[1], ElementType (*)[1]>::value),
327327
"OtherElementType(*)[] should be convertible to ElementType (*)[]"
328328
);
@@ -389,7 +389,7 @@ struct Span {
389389
template<ptrdiff_t Count>
390390
Span<element_type, Count> first() const
391391
{
392-
MBED_STATIC_ASSERT(
392+
static_assert(
393393
(0 <= Count) && (Count <= Extent),
394394
"Invalid subspan extent"
395395
);
@@ -408,7 +408,7 @@ struct Span {
408408
template<ptrdiff_t Count>
409409
Span<element_type, Count> last() const
410410
{
411-
MBED_STATIC_ASSERT(
411+
static_assert(
412412
(0 <= Count) && (Count <= Extent),
413413
"Invalid subspan extent"
414414
);
@@ -433,11 +433,11 @@ struct Span {
433433
Span<element_type, Count == SPAN_DYNAMIC_EXTENT ? Extent - Offset : Count>
434434
subspan() const
435435
{
436-
MBED_STATIC_ASSERT(
436+
static_assert(
437437
0 <= Offset && Offset <= Extent,
438438
"Invalid subspan offset"
439439
);
440-
MBED_STATIC_ASSERT(
440+
static_assert(
441441
(Count == SPAN_DYNAMIC_EXTENT) ||
442442
(0 <= Count && (Count + Offset) <= Extent),
443443
"Invalid subspan count"
@@ -617,7 +617,7 @@ struct Span<ElementType, SPAN_DYNAMIC_EXTENT> {
617617
Span(const Span<OtherElementType, OtherExtent> &other):
618618
_data(other.data()), _size(other.size())
619619
{
620-
MBED_STATIC_ASSERT(
620+
static_assert(
621621
(span_detail::is_convertible<OtherElementType (*)[1], ElementType (*)[1]>::value),
622622
"OtherElementType(*)[] should be convertible to ElementType (*)[]"
623623
);

0 commit comments

Comments
 (0)