Fixed constexpr-ness of bx::bitCast.

This commit is contained in:
Бранимир Караџић
2024-11-14 21:08:13 -08:00
parent 109637aa6f
commit cf3b711016
4 changed files with 21 additions and 101 deletions

View File

@@ -223,7 +223,7 @@ namespace bx
/// Performs `static_cast` of value `_from`, and in debug build runtime verifies/asserts
/// that the value didn't change.
template<typename Ty, typename FromT>
constexpr Ty narrowCast(const FromT& _from, Location _location = Location::current() );
Ty narrowCast(const FromT& _from, Location _location = Location::current() );
/// Copy memory block.
///

View File

@@ -153,18 +153,21 @@ namespace bx
static_assert(sizeof(Ty) == sizeof(FromT)
, "bx::bitCast failed! Ty and FromT must be the same size."
);
static_assert(isTriviallyCopyable<FromT>()
, "bx::bitCast failed! FromT must be trivially copyable."
);
static_assert(isTriviallyCopyable<Ty>()
, "bx::bitCast failed! Ty must be trivially copyable."
);
static_assert(isTriviallyConstructible<Ty>()
, "bx::bitCast failed! Destination target must be trivially constructible."
, "bx::bitCast failed! Ty must be trivially constructible."
);
Ty to;
memCopy(&to, &_from, sizeof(Ty) );
return to;
return __builtin_bit_cast(Ty, _from);
}
template<typename Ty, typename FromT>
inline constexpr Ty narrowCast(const FromT& _from, Location _location)
inline Ty narrowCast(const FromT& _from, Location _location)
{
Ty to = static_cast<Ty>(_from);
BX_ASSERT_LOC(_location, static_cast<FromT>(to) == _from

View File

@@ -342,18 +342,6 @@
# define BX_COMPILER_NAME "MSVC 17.0"
# elif BX_COMPILER_MSVC >= 1920 // Visual Studio 2019
# define BX_COMPILER_NAME "MSVC 16.0"
# elif BX_COMPILER_MSVC >= 1910 // Visual Studio 2017
# define BX_COMPILER_NAME "MSVC 15.0"
# elif BX_COMPILER_MSVC >= 1900 // Visual Studio 2015
# define BX_COMPILER_NAME "MSVC 14.0"
# elif BX_COMPILER_MSVC >= 1800 // Visual Studio 2013
# define BX_COMPILER_NAME "MSVC 12.0"
# elif BX_COMPILER_MSVC >= 1700 // Visual Studio 2012
# define BX_COMPILER_NAME "MSVC 11.0"
# elif BX_COMPILER_MSVC >= 1600 // Visual Studio 2010
# define BX_COMPILER_NAME "MSVC 10.0"
# elif BX_COMPILER_MSVC >= 1500 // Visual Studio 2008
# define BX_COMPILER_NAME "MSVC 9.0"
# else
# define BX_COMPILER_NAME "MSVC"
# endif //
@@ -481,6 +469,12 @@ static_assert(!BX_COMPILER_GCC || BX_COMPILER_GCC >= 80400, "\n\n"
"\tMinimum supported GCC version is 8.4 (March 4, 2020).\n"
"\t\n");
// https://learn.microsoft.com/en-us/visualstudio/releases/2019/history
static_assert(!BX_COMPILER_MSVC || BX_COMPILER_MSVC >= 1927, "\n\n"
"\t** IMPORTANT! **\n\n"
"\tMinimum supported MSVC 19.27 / Visual Studio 2019 version 16.7 (August 5, 2020).\n"
"\t\n");
static_assert(!BX_CPU_ENDIAN_BIG, "\n\n"
"\t** IMPORTANT! **\n\n"
"\tThe code was not tested for big endian, and big endian CPU is considered unsupported.\n"