RFR: JDK-8299688: Adopt C++14 compatible std::bit_cast introduced in C++20 [v4]
Justin King
jcking at openjdk.org
Mon Jan 23 19:10:52 UTC 2023
On Mon, 23 Jan 2023 08:05:54 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:
>> src/hotspot/share/utilities/bitCast.hpp line 41:
>>
>>> 39: // Trivial implementation when To and From are the same.
>>> 40: template <typename To, typename From, ENABLE_IF(std::is_same<From, To>::value)>
>>> 41: constexpr To bit_cast(const From& from) {
>>
>> This is missing the tivially copiable requirement for std::bit_cast. Also, it seems like the is_same
>> SFINAE should not be needed here. Why not just
>>
>> template <typename T, ENABLE_IF(std::is_trivially_copyable<T>::value)>
>> constexpr T bit_cast(const T& value) {
>> return value;
>> }
>
> The need for this overload to match the Standard specification is one of the reasons why I had refrained
> from doing something like this change. This overload's existence (slightly) complicates others by requiring
> an additional `!std::is_same<To, From>` constraint. Since such a nop conversion hasn't arisen in our code
> (yet), there isn't currently a need for this. I also don't see any tests for it.
I removed the is_same. It technically isn't needed to conform. I also decided to not conform to the full standard and restrict uses based on the existing PrimitiveConversions::cast restrictions.
-------------
PR: https://git.openjdk.org/jdk/pull/11865
More information about the hotspot-dev
mailing list