From 3e9604c7434127b9d5b8964cdebfdc7ac4693581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Sat, 7 Dec 2024 22:51:31 -0800 Subject: [PATCH] Removed BX_STATIC_ASSERT. Not needed in C++17. --- include/bx/error.h | 4 ++-- include/bx/inline/hash.inl | 2 +- include/bx/inline/math.inl | 8 ++++---- include/bx/inline/readerwriter.inl | 12 ++++++------ include/bx/inline/sort.inl | 12 ++++++------ include/bx/inline/typetraits.inl | 2 +- include/bx/macros.h | 3 --- src/bounds.cpp | 2 +- src/easing.cpp | 2 +- src/file.cpp | 6 +++--- src/hash.cpp | 12 ++++++------ src/mutex.cpp | 4 ++-- src/semaphore.cpp | 6 +++--- src/thread.cpp | 8 ++++---- tests/macros_test.cpp | 14 +++++++------- tests/string_test.cpp | 2 +- 16 files changed, 48 insertions(+), 51 deletions(-) diff --git a/include/bx/error.h b/include/bx/error.h index 7ccd200..c01b6b9 100644 --- a/include/bx/error.h +++ b/include/bx/error.h @@ -21,8 +21,8 @@ BX_ERROR_USE_TEMP_WHEN_NULL(_ptr); \ bx::ErrorScope bxErrorScope(const_cast(&tmpError), "" __VA_ARGS__) -#define BX_ERROR_RESULT(_err, _code) \ - BX_STATIC_ASSERT(_code != 0, "ErrorCode 0 is reserved!"); \ +#define BX_ERROR_RESULT(_err, _code) \ + static_assert(_code != 0, "ErrorCode 0 is reserved!"); \ static constexpr bx::ErrorResult _err = { _code } namespace bx diff --git a/include/bx/inline/hash.inl b/include/bx/inline/hash.inl index 97df9e1..c796ac6 100644 --- a/include/bx/inline/hash.inl +++ b/include/bx/inline/hash.inl @@ -142,7 +142,7 @@ namespace bx template inline uint32_t hash(const Ty& _data) { - BX_STATIC_ASSERT(isTriviallyCopyable() ); + static_assert(isTriviallyCopyable() ); return hash(&_data, sizeof(Ty) ); } diff --git a/include/bx/inline/math.inl b/include/bx/inline/math.inl index 5fc99f3..e188730 100644 --- a/include/bx/inline/math.inl +++ b/include/bx/inline/math.inl @@ -668,28 +668,28 @@ namespace bx template inline BX_CONSTEXPR_FUNC uint8_t findFirstSet(Ty _val) { - BX_STATIC_ASSERT(isInteger(), "Type Ty must be of integer type!"); + static_assert(isInteger(), "Type Ty must be of integer type!"); return Ty(0) == _val ? uint8_t(0) : countTrailingZeros(_val) + 1; } template inline BX_CONSTEXPR_FUNC uint8_t findLastSet(Ty _val) { - BX_STATIC_ASSERT(isInteger(), "Type Ty must be of integer type!"); + static_assert(isInteger(), "Type Ty must be of integer type!"); return Ty(0) == _val ? uint8_t(0) : sizeof(Ty)*8 - countLeadingZeros(_val); } template inline BX_CONSTEXPR_FUNC uint8_t ceilLog2(Ty _a) { - BX_STATIC_ASSERT(isInteger(), "Type Ty must be of integer type!"); + static_assert(isInteger(), "Type Ty must be of integer type!"); return Ty(_a) < Ty(1) ? Ty(0) : sizeof(Ty)*8 - countLeadingZeros(_a - 1); } template inline BX_CONSTEXPR_FUNC uint8_t floorLog2(Ty _a) { - BX_STATIC_ASSERT(isInteger(), "Type Ty must be of integer type!"); + static_assert(isInteger(), "Type Ty must be of integer type!"); return Ty(_a) < Ty(1) ? Ty(0) : sizeof(Ty)*8 - 1 - countLeadingZeros(_a); } diff --git a/include/bx/inline/readerwriter.inl b/include/bx/inline/readerwriter.inl index b15d76d..83c0bf4 100644 --- a/include/bx/inline/readerwriter.inl +++ b/include/bx/inline/readerwriter.inl @@ -276,7 +276,7 @@ namespace bx inline int32_t read(ReaderI* _reader, Ty& _value, Error* _err) { BX_ERROR_SCOPE(_err); - BX_STATIC_ASSERT(isTriviallyCopyable() ); + static_assert(isTriviallyCopyable() ); return _reader->read(&_value, sizeof(Ty), _err); } @@ -284,7 +284,7 @@ namespace bx inline int32_t readHE(ReaderI* _reader, Ty& _value, bool _fromLittleEndian, Error* _err) { BX_ERROR_SCOPE(_err); - BX_STATIC_ASSERT(isTriviallyCopyable() ); + static_assert(isTriviallyCopyable() ); Ty value; int32_t result = _reader->read(&value, sizeof(Ty), _err); _value = toHostEndian(value, _fromLittleEndian); @@ -322,7 +322,7 @@ namespace bx inline int32_t write(WriterI* _writer, const Ty& _value, Error* _err) { BX_ERROR_SCOPE(_err); - BX_STATIC_ASSERT(isTriviallyCopyable() ); + static_assert(isTriviallyCopyable() ); return _writer->write(&_value, sizeof(Ty), _err); } @@ -347,7 +347,7 @@ namespace bx inline int32_t writeLE(WriterI* _writer, const Ty& _value, Error* _err) { BX_ERROR_SCOPE(_err); - BX_STATIC_ASSERT(isTriviallyCopyable() ); + static_assert(isTriviallyCopyable() ); Ty value = toLittleEndian(_value); int32_t result = _writer->write(&value, sizeof(Ty), _err); return result; @@ -363,7 +363,7 @@ namespace bx inline int32_t writeBE(WriterI* _writer, const Ty& _value, Error* _err) { BX_ERROR_SCOPE(_err); - BX_STATIC_ASSERT(isTriviallyCopyable() ); + static_assert(isTriviallyCopyable() ); Ty value = toBigEndian(_value); int32_t result = _writer->write(&value, sizeof(Ty), _err); return result; @@ -414,7 +414,7 @@ namespace bx inline int32_t peek(ReaderSeekerI* _reader, Ty& _value, Error* _err) { BX_ERROR_SCOPE(_err); - BX_STATIC_ASSERT(isTriviallyCopyable() ); + static_assert(isTriviallyCopyable() ); return peek(_reader, &_value, sizeof(Ty), _err); } diff --git a/include/bx/inline/sort.inl b/include/bx/inline/sort.inl index 1a6f7e3..b94d3ac 100644 --- a/include/bx/inline/sort.inl +++ b/include/bx/inline/sort.inl @@ -44,28 +44,28 @@ namespace bx template inline void quickSort(void* _data, uint32_t _num, uint32_t _stride, const ComparisonFn _fn) { - BX_STATIC_ASSERT(isTriviallyMoveAssignable(), "Element type must be trivially move assignable"); + static_assert(isTriviallyMoveAssignable(), "Element type must be trivially move assignable"); quickSort(_data, _num, _stride, _fn); } template inline void quickSort(Ty* _data, uint32_t _num, const ComparisonFn _fn) { - BX_STATIC_ASSERT(isTriviallyMoveAssignable(), "Element type must be trivially move assignable"); + static_assert(isTriviallyMoveAssignable(), "Element type must be trivially move assignable"); quickSort( (void*)_data, _num, sizeof(Ty), _fn); } template inline uint32_t unique(void* _data, uint32_t _num, uint32_t _stride, const ComparisonFn _fn) { - BX_STATIC_ASSERT(isTriviallyMoveAssignable(), "Element type must be trivially move assignable"); + static_assert(isTriviallyMoveAssignable(), "Element type must be trivially move assignable"); return unique(_data, _num, _stride, _fn); } template inline uint32_t unique(Ty* _data, uint32_t _num, const ComparisonFn _fn) { - BX_STATIC_ASSERT(isTriviallyMoveAssignable(), "Element type must be trivially move assignable"); + static_assert(isTriviallyMoveAssignable(), "Element type must be trivially move assignable"); return unique( (void*)_data, _num, sizeof(Ty), _fn); } @@ -189,7 +189,7 @@ done: template inline void radixSort(uint32_t* _keys, uint32_t* _tempKeys, Ty* _values, Ty* _tempValues, uint32_t _size) { - BX_STATIC_ASSERT(isTriviallyMoveAssignable(), "Sort element type must be trivially move assignable"); + static_assert(isTriviallyMoveAssignable(), "Sort element type must be trivially move assignable"); uint32_t* keys = _keys; uint32_t* tempKeys = _tempKeys; @@ -325,7 +325,7 @@ done: template inline void radixSort(uint64_t* _keys, uint64_t* _tempKeys, Ty* _values, Ty* _tempValues, uint32_t _size) { - BX_STATIC_ASSERT(isTriviallyMoveAssignable(), "Sort element type must be trivially move assignable"); + static_assert(isTriviallyMoveAssignable(), "Sort element type must be trivially move assignable"); uint64_t* keys = _keys; uint64_t* tempKeys = _tempKeys; diff --git a/include/bx/inline/typetraits.inl b/include/bx/inline/typetraits.inl index 8344f18..a26ca1e 100644 --- a/include/bx/inline/typetraits.inl +++ b/include/bx/inline/typetraits.inl @@ -591,7 +591,7 @@ namespace bx template inline constexpr Ty&& forward(RemoveReferenceType&& _a) { - BX_STATIC_ASSERT(!isLvalueReference(), "Can not forward an Rvalue as an Lvalue."); + static_assert(!isLvalueReference(), "Can not forward an Rvalue as an Lvalue."); return static_cast(_a); } diff --git a/include/bx/macros.h b/include/bx/macros.h index c453c0f..c403720 100644 --- a/include/bx/macros.h +++ b/include/bx/macros.h @@ -88,9 +88,6 @@ /// #define BX_CONSTEXPR_FUNC constexpr BX_CONST_FUNC -/// -#define BX_STATIC_ASSERT(_condition, ...) static_assert(_condition, "" __VA_ARGS__) - /// #define BX_ALIGN_DECL_16(_decl) BX_ALIGN_DECL(16, _decl) #define BX_ALIGN_DECL_256(_decl) BX_ALIGN_DECL(256, _decl) diff --git a/src/bounds.cpp b/src/bounds.cpp index 851aefb..2136241 100644 --- a/src/bounds.cpp +++ b/src/bounds.cpp @@ -627,7 +627,7 @@ namespace bx bool intersect(const Ray& _ray, const Capsule& _capsule, Hit* _hit) { - BX_STATIC_ASSERT(sizeof(Capsule) == sizeof(Cylinder) ); + static_assert(sizeof(Capsule) == sizeof(Cylinder) ); return intersect(_ray, *( (const Cylinder*)&_capsule), true, _hit); } diff --git a/src/easing.cpp b/src/easing.cpp index a49c17d..9bc4dce 100644 --- a/src/easing.cpp +++ b/src/easing.cpp @@ -53,7 +53,7 @@ namespace bx easeInOutBounce, easeOutInBounce, }; - BX_STATIC_ASSERT(BX_COUNTOF(s_easeFunc) == Easing::Count); + static_assert(BX_COUNTOF(s_easeFunc) == Easing::Count); EaseFn getEaseFunc(Easing::Enum _enum) { diff --git a/src/file.cpp b/src/file.cpp index c34a7ac..1b182b2 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -494,7 +494,7 @@ namespace bx FileReader::FileReader() { - BX_STATIC_ASSERT(sizeof(FileReaderImpl) <= sizeof(m_internal) ); + static_assert(sizeof(FileReaderImpl) <= sizeof(m_internal) ); BX_PLACEMENT_NEW(m_internal, FileReaderImpl)(NULL); } @@ -530,7 +530,7 @@ namespace bx FileWriter::FileWriter() { - BX_STATIC_ASSERT(sizeof(FileWriterImpl) <= sizeof(m_internal) ); + static_assert(sizeof(FileWriterImpl) <= sizeof(m_internal) ); BX_PLACEMENT_NEW(m_internal, FileWriterImpl)(NULL); } @@ -711,7 +711,7 @@ namespace bx DirectoryReader::DirectoryReader() { - BX_STATIC_ASSERT(sizeof(DirectoryReaderImpl) <= sizeof(m_internal) ); + static_assert(sizeof(DirectoryReaderImpl) <= sizeof(m_internal) ); BX_PLACEMENT_NEW(m_internal, DirectoryReaderImpl); } diff --git a/src/hash.cpp b/src/hash.cpp index e2b932b..0bbe709 100644 --- a/src/hash.cpp +++ b/src/hash.cpp @@ -43,7 +43,7 @@ static const uint32_t s_crcTableIeee[] = 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d, }; -BX_STATIC_ASSERT(BX_COUNTOF(s_crcTableIeee) == 256); +static_assert(BX_COUNTOF(s_crcTableIeee) == 256); static const uint32_t s_crcTableCastagnoli[] = { @@ -80,7 +80,7 @@ static const uint32_t s_crcTableCastagnoli[] = 0xf36e6f75, 0x0105ec76, 0x12551f82, 0xe03e9c81, 0x34f4f86a, 0xc69f7b69, 0xd5cf889d, 0x27a40b9e, 0x79b737ba, 0x8bdcb4b9, 0x988c474d, 0x6ae7c44e, 0xbe2da0a5, 0x4c4623a6, 0x5f16d052, 0xad7d5351, }; -BX_STATIC_ASSERT(BX_COUNTOF(s_crcTableCastagnoli) == 256); +static_assert(BX_COUNTOF(s_crcTableCastagnoli) == 256); static const uint32_t s_crcTableKoopman[] = { @@ -117,7 +117,7 @@ static const uint32_t s_crcTableKoopman[] = 0xcc9b9520, 0x5a0e51ea, 0x37d3ace9, 0xa1466823, 0xec6856ef, 0x7afd9225, 0x17206f26, 0x81b5abec, 0x8d7c12be, 0x1be9d674, 0x76342b77, 0xe0a1efbd, 0xad8fd171, 0x3b1a15bb, 0x56c7e8b8, 0xc0522c72, }; -BX_STATIC_ASSERT(BX_COUNTOF(s_crcTableKoopman) == 256); +static_assert(BX_COUNTOF(s_crcTableKoopman) == 256); static const uint32_t* s_crcTable[] = { @@ -125,7 +125,7 @@ static const uint32_t* s_crcTable[] = s_crcTableCastagnoli, s_crcTableKoopman, }; -BX_STATIC_ASSERT(BX_COUNTOF(s_crcTable) == HashCrc32::Count); +static_assert(BX_COUNTOF(s_crcTable) == HashCrc32::Count); void HashCrc32::begin(Enum _type) { @@ -270,7 +270,7 @@ struct HashMurmur2APod m_hash ^= m_hash >> 15; } }; -BX_STATIC_ASSERT(sizeof(HashMurmur2A) == sizeof(HashMurmur2APod) ); +static_assert(sizeof(HashMurmur2A) == sizeof(HashMurmur2APod) ); void HashMurmur2A::add(const void* _data, int32_t _len) { @@ -334,7 +334,7 @@ struct HashMurmur3Pod m_hash ^= m_hash >> 16; } }; -BX_STATIC_ASSERT(sizeof(HashMurmur3) == sizeof(HashMurmur3Pod) ); +static_assert(sizeof(HashMurmur3) == sizeof(HashMurmur3Pod) ); void HashMurmur3::add(const void* _data, int32_t _len) { diff --git a/src/mutex.cpp b/src/mutex.cpp index a29134c..56320b8 100644 --- a/src/mutex.cpp +++ b/src/mutex.cpp @@ -44,7 +44,7 @@ namespace bx Mutex::Mutex() { - BX_STATIC_ASSERT(sizeof(int32_t) <= sizeof(m_internal) ); + static_assert(sizeof(int32_t) <= sizeof(m_internal) ); uint32_t* futex = (uint32_t*)m_internal; *futex = State::Unlocked; @@ -123,7 +123,7 @@ namespace bx Mutex::Mutex() { - BX_STATIC_ASSERT(sizeof(pthread_mutex_t) <= sizeof(m_internal) ); + static_assert(sizeof(pthread_mutex_t) <= sizeof(m_internal) ); pthread_mutexattr_t attr; diff --git a/src/semaphore.cpp b/src/semaphore.cpp index 3525349..67738c8 100644 --- a/src/semaphore.cpp +++ b/src/semaphore.cpp @@ -54,7 +54,7 @@ namespace bx #if BX_CRT_NONE Semaphore::Semaphore() { - BX_STATIC_ASSERT(sizeof(SemaphoreInternal) <= sizeof(m_internal) ); + static_assert(sizeof(SemaphoreInternal) <= sizeof(m_internal) ); } Semaphore::~Semaphore() @@ -77,7 +77,7 @@ namespace bx Semaphore::Semaphore() { - BX_STATIC_ASSERT(sizeof(SemaphoreInternal) <= sizeof(m_internal) ); + static_assert(sizeof(SemaphoreInternal) <= sizeof(m_internal) ); SemaphoreInternal* si = (SemaphoreInternal*)m_internal; si->m_handle = dispatch_semaphore_create(0); @@ -137,7 +137,7 @@ namespace bx Semaphore::Semaphore() { - BX_STATIC_ASSERT(sizeof(SemaphoreInternal) <= sizeof(m_internal) ); + static_assert(sizeof(SemaphoreInternal) <= sizeof(m_internal) ); SemaphoreInternal* si = (SemaphoreInternal*)m_internal; si->m_count = 0; diff --git a/src/thread.cpp b/src/thread.cpp index 8117f19..7297169 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -96,7 +96,7 @@ namespace bx , m_exitCode(kExitSuccess) , m_running(false) { - BX_STATIC_ASSERT(sizeof(ThreadInternal) <= sizeof(m_internal) ); + static_assert(sizeof(ThreadInternal) <= sizeof(m_internal) ); ThreadInternal* ti = (ThreadInternal*)m_internal; #if BX_CRT_NONE @@ -330,7 +330,7 @@ namespace bx #if BX_CRT_NONE TlsData::TlsData() { - BX_STATIC_ASSERT(sizeof(TlsDataInternal) <= sizeof(m_internal) ); + static_assert(sizeof(TlsDataInternal) <= sizeof(m_internal) ); TlsDataInternal* ti = (TlsDataInternal*)m_internal; BX_UNUSED(ti); @@ -357,7 +357,7 @@ namespace bx #elif BX_PLATFORM_WINDOWS TlsData::TlsData() { - BX_STATIC_ASSERT(sizeof(TlsDataInternal) <= sizeof(m_internal) ); + static_assert(sizeof(TlsDataInternal) <= sizeof(m_internal) ); TlsDataInternal* ti = (TlsDataInternal*)m_internal; ti->m_id = TlsAlloc(); @@ -387,7 +387,7 @@ namespace bx TlsData::TlsData() { - BX_STATIC_ASSERT(sizeof(TlsDataInternal) <= sizeof(m_internal) ); + static_assert(sizeof(TlsDataInternal) <= sizeof(m_internal) ); TlsDataInternal* ti = (TlsDataInternal*)m_internal; int result = pthread_key_create(&ti->m_id, NULL); diff --git a/tests/macros_test.cpp b/tests/macros_test.cpp index 0a5ad8d..db4f7a9 100644 --- a/tests/macros_test.cpp +++ b/tests/macros_test.cpp @@ -7,7 +7,7 @@ #include #include -BX_STATIC_ASSERT(false +static_assert(false || BX_CRT_BIONIC || BX_CRT_GLIBC || BX_CRT_LIBCXX @@ -17,12 +17,12 @@ BX_STATIC_ASSERT(false || BX_CRT_NONE ); -BX_STATIC_ASSERT(1 == BX_VA_ARGS_COUNT(1) ); -BX_STATIC_ASSERT(2 == BX_VA_ARGS_COUNT(1, 2) ); -BX_STATIC_ASSERT(3 == BX_VA_ARGS_COUNT(1, 2, 3) ); -BX_STATIC_ASSERT(4 == BX_VA_ARGS_COUNT(1, 2, 3, 4) ); -BX_STATIC_ASSERT(5 == BX_VA_ARGS_COUNT(1, 2, 3, 4, 5) ); -BX_STATIC_ASSERT(6 == BX_VA_ARGS_COUNT(1, 2, 3, 4, 5, 6) ); +static_assert(1 == BX_VA_ARGS_COUNT(1) ); +static_assert(2 == BX_VA_ARGS_COUNT(1, 2) ); +static_assert(3 == BX_VA_ARGS_COUNT(1, 2, 3) ); +static_assert(4 == BX_VA_ARGS_COUNT(1, 2, 3, 4) ); +static_assert(5 == BX_VA_ARGS_COUNT(1, 2, 3, 4, 5) ); +static_assert(6 == BX_VA_ARGS_COUNT(1, 2, 3, 4, 5, 6) ); BX_NO_INLINE void unusedFunction() { diff --git a/tests/string_test.cpp b/tests/string_test.cpp index 8ef3ac0..4cc3e4a 100644 --- a/tests/string_test.cpp +++ b/tests/string_test.cpp @@ -207,7 +207,7 @@ TEST_CASE("strCmpV sort", "[string][sort]") "test_100.txt", }; - BX_STATIC_ASSERT(BX_COUNTOF(test) == BX_COUNTOF(expected) ); + static_assert(BX_COUNTOF(test) == BX_COUNTOF(expected) ); bx::quickSort(test, BX_COUNTOF(test), sizeof(const char*), strCmpV);