[PATCH] D132332: [ADT] Clarify llvm::bit_cast implementation comments

Joe Loser via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 21 09:44:41 PDT 2022


jloser created this revision.
jloser added reviewers: MaskRay, kazu, dblaikie.
Herald added a subscriber: StephenFan.
Herald added a project: All.
jloser requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

When reviewing https://reviews.llvm.org/D132330, I noticed a few pre-existing
comments regarding the implementation of `llvm::bit_cast`. These comments are a
bit misleading since `std::bit_cast` is a C++20 standard library thing, not a
C++17 one (otherwise we could use it directly). Clarify that in the comment.
Also, the implementation in standard libraries as mandated by the standard
requires the destination type to be `trivially_copyable`. Remove the comment
that suggests that `llvm::bit_cast` differs from `std::bit_cast` in that manner.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132332

Files:
  llvm/include/llvm/ADT/bit.h


Index: llvm/include/llvm/ADT/bit.h
===================================================================
--- llvm/include/llvm/ADT/bit.h
+++ llvm/include/llvm/ADT/bit.h
@@ -20,9 +20,8 @@
 
 namespace llvm {
 
-// This implementation of bit_cast is different from the C++17 one in two ways:
-//  - It isn't constexpr because that requires compiler support.
-//  - It requires trivially-constructible To, to avoid UB in the implementation.
+// This implementation of bit_cast is different from the C++20 one.
+// This version isn't constexpr because that requires compiler support.
 template <
     typename To, typename From,
     typename = std::enable_if_t<sizeof(To) == sizeof(From)>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132332.454323.patch
Type: text/x-patch
Size: 684 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220821/04259812/attachment.bin>


More information about the llvm-commits mailing list