Skip to content

Commit

Permalink
Replace nlSTATIC_ASSERT_PRINT with static_assert (#36075)
Browse files Browse the repository at this point in the history
* Replace nlSTATIC_ASSERT_PRINT with static_assert

* Remove unnecessary includes
  • Loading branch information
arkq authored Oct 15, 2024
1 parent 8a08d57 commit 064c205
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 17 deletions.
2 changes: 0 additions & 2 deletions src/inet/InetFaultInjection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

#include "InetFaultInjection.h"

#include <nlassert.h>

namespace chip {
namespace Inet {
namespace FaultInjection {
Expand Down
17 changes: 8 additions & 9 deletions src/lib/core/CHIPSafeCasts.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#pragma once

#include <limits.h>
#include <nlassert.h>
#include <stdint.h>

namespace chip {
Expand All @@ -42,7 +41,7 @@ namespace Uint8 {
*/
inline uint8_t * from_uchar(unsigned char * in)
{
nlSTATIC_ASSERT_PRINT(CHAR_BIT == 8, "Can't type cast unsigned char array as uint8_t array");
static_assert(CHAR_BIT == 8, "Can't type cast unsigned char array as uint8_t array");
#ifdef __cplusplus
return reinterpret_cast<uint8_t *>(in);
#else
Expand All @@ -59,7 +58,7 @@ inline uint8_t * from_uchar(unsigned char * in)
*/
inline const uint8_t * from_const_uchar(const unsigned char * in)
{
nlSTATIC_ASSERT_PRINT(CHAR_BIT == 8, "Can't type cast unsigned char array as uint8_t array");
static_assert(CHAR_BIT == 8, "Can't type cast unsigned char array as uint8_t array");
#ifdef __cplusplus
return reinterpret_cast<const uint8_t *>(in);
#else
Expand All @@ -76,7 +75,7 @@ inline const uint8_t * from_const_uchar(const unsigned char * in)
*/
inline uint8_t * from_char(char * in)
{
nlSTATIC_ASSERT_PRINT(CHAR_BIT == 8, "Can't type cast char array as uint8_t array");
static_assert(CHAR_BIT == 8, "Can't type cast char array as uint8_t array");
#ifdef __cplusplus
return reinterpret_cast<uint8_t *>(in);
#else
Expand All @@ -93,7 +92,7 @@ inline uint8_t * from_char(char * in)
*/
inline const uint8_t * from_const_char(const char * in)
{
nlSTATIC_ASSERT_PRINT(CHAR_BIT == 8, "Can't type cast char array as uint8_t array");
static_assert(CHAR_BIT == 8, "Can't type cast char array as uint8_t array");
#ifdef __cplusplus
return reinterpret_cast<const uint8_t *>(in);
#else
Expand All @@ -110,7 +109,7 @@ inline const uint8_t * from_const_char(const char * in)
*/
inline unsigned char * to_uchar(uint8_t * in)
{
nlSTATIC_ASSERT_PRINT(CHAR_BIT == 8, "Can't type cast uint8_t array to unsigned char array");
static_assert(CHAR_BIT == 8, "Can't type cast uint8_t array to unsigned char array");
#ifdef __cplusplus
return reinterpret_cast<unsigned char *>(in);
#else
Expand All @@ -127,7 +126,7 @@ inline unsigned char * to_uchar(uint8_t * in)
*/
inline const unsigned char * to_const_uchar(const uint8_t * in)
{
nlSTATIC_ASSERT_PRINT(CHAR_BIT == 8, "Can't type cast uint8_t array to unsigned char array");
static_assert(CHAR_BIT == 8, "Can't type cast uint8_t array to unsigned char array");
#ifdef __cplusplus
return reinterpret_cast<const unsigned char *>(in);
#else
Expand All @@ -144,7 +143,7 @@ inline const unsigned char * to_const_uchar(const uint8_t * in)
*/
inline char * to_char(uint8_t * in)
{
nlSTATIC_ASSERT_PRINT(CHAR_BIT == 8, "Can't type cast uint8_t array to char array");
static_assert(CHAR_BIT == 8, "Can't type cast uint8_t array to char array");
#ifdef __cplusplus
return reinterpret_cast<char *>(in);
#else
Expand All @@ -161,7 +160,7 @@ inline char * to_char(uint8_t * in)
*/
inline const char * to_const_char(const uint8_t * in)
{
nlSTATIC_ASSERT_PRINT(CHAR_BIT == 8, "Can't type cast uint8_t array to char array");
static_assert(CHAR_BIT == 8, "Can't type cast uint8_t array to char array");
#ifdef __cplusplus
return reinterpret_cast<const char *>(in);
#else
Expand Down
1 change: 0 additions & 1 deletion src/lib/support/BytesCircularBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include <algorithm>
#include <limits>
#include <nlassert.h>
#include <string.h>

#include <lib/support/CodeUtils.h>
Expand Down
2 changes: 0 additions & 2 deletions src/lib/support/CHIPFaultInjection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
*/
#include "CHIPFaultInjection.h"

#include <nlassert.h>

#include <string.h>

namespace chip {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/support/PersistentStorageMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ namespace chip {
do \
{ \
constexpr size_t len = std::extent<decltype(keyPrefix)>::value; \
nlSTATIC_ASSERT_PRINT(len > 0, "keyPrefix length must be known at compile time"); \
static_assert(len > 0, "keyPrefix length must be known at compile time"); \
/* 2 * sizeof(chip::NodeId) to accommodate 2 character for each byte in Node Id */ \
char key[len + 2 * sizeof(chip::NodeId) + 1]; \
nlSTATIC_ASSERT_PRINT(sizeof(node) <= sizeof(uint64_t), "Node ID size is greater than expected"); \
static_assert(sizeof(node) <= sizeof(uint64_t), "Node ID size is greater than expected"); \
/* Be careful about switching to ChipLogFormatX64: it would change the storage keys! */ \
snprintf(key, sizeof(key), "%s%" PRIx64, keyPrefix, node); \
action; \
Expand Down
1 change: 0 additions & 1 deletion src/system/SystemFaultInjection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
/* module header, also carries config, comes first */
#include <system/SystemFaultInjection.h>

#include <nlassert.h>
#include <string.h>

namespace chip {
Expand Down

0 comments on commit 064c205

Please sign in to comment.