RFR: JDK-8299688: Adopt C++14 compatible std::bit_cast introduced in C++20 [v5]

Justin King jcking at openjdk.org
Mon Jan 23 15:54:07 UTC 2023


> Adopts a C++14 compatible implementation of [std::bit_cast](https://en.cppreference.com/w/cpp/numeric/bit_cast).
> 
> `PrimitiveConversions::cast` is refactored into `bit_cast` and extended to support all compatible types. Additionally it makes use of `__builtin_bit_cast` when available, which is strictly well defined compared to fallback approaches which are sometimes lurking in undefined behavior territory.
> 
> Lastly some legacy casting is updated to use `bit_cast` in `utilities/globalDefinitions.hpp`.

Justin King has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 18 commits:

 - Merge remote-tracking branch 'upstream/master' into bit-cast
 - Restrict supported use cases
   
   Signed-off-by: Justin King <jcking at google.com>
 - Restrict supported use cases
   
   Signed-off-by: Justin King <jcking at google.com>
 - Remove addressof as nobody should be overloading operator&
   
   Signed-off-by: Justin King <jcking at google.com>
 - Sort includes and fix macro indentation
   
   Signed-off-by: Justin King <jcking at google.com>
 - Apple Clang thinks __builtin_bit_cast is present when its not
   
   Signed-off-by: Justin King <jcking at google.com>
 - Correctly handle const/volatile pointers
   
   Signed-off-by: Justin King <jcking at google.com>
 - Use __builtin_bit_cast when available for every specialization of bit_cast
   
   Signed-off-by: Justin King <jcking at google.com>
 - Minor cleanup
   
   Signed-off-by: Justin King <jcking at google.com>
 - Ensure operator& overloading is ignored
   
   Signed-off-by: Justin King <jcking at google.com>
 - ... and 8 more: https://git.openjdk.org/jdk/compare/c8dd7583...07648dd9

-------------

Changes: https://git.openjdk.org/jdk/pull/11865/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=11865&range=04
  Stats: 587 lines in 19 files changed: 299 ins; 235 del; 53 mod
  Patch: https://git.openjdk.org/jdk/pull/11865.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/11865/head:pull/11865

PR: https://git.openjdk.org/jdk/pull/11865


More information about the hotspot-dev mailing list