RFR: JDK-8299688: Adopt C++14 compatible std::bit_cast introduced in C++20 [v4]
Kim Barrett
kbarrett at openjdk.org
Mon Jan 23 10:02:21 UTC 2023
On Mon, 23 Jan 2023 07:44:10 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:
>> Justin King has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Remove addressof as nobody should be overloading operator&
>>
>> Signed-off-by: Justin King <jcking at google.com>
>
> 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.
-------------
PR: https://git.openjdk.org/jdk/pull/11865
More information about the hotspot-dev
mailing list