[PATCH] D132330: [ADT] Simplify llvm::bit_cast (NFC)
Kazu Hirata via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 21 08:54:14 PDT 2022
kazu created this revision.
Herald added a project: All.
kazu requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This patch removes macro tricks to check GCC versions.
The commit message from 19262fc5966ab569f21f3d440f8b001bca666f17
states that "is_trivially_copyable is only in GCC 5.1 and later".
Note that we now require GCC 7.1 or higher.
Since both std::is_trivially_constructible and
std::is_trivially_copyable are C++11 features, and we now require
C++17, we probably don't need to worry about the availability of the
C++11 features.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D132330
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
@@ -25,34 +25,10 @@
// - It requires trivially-constructible To, to avoid UB in the implementation.
template <
typename To, typename From,
- typename = std::enable_if_t<sizeof(To) == sizeof(From)>
-#if (__has_feature(is_trivially_constructible) && defined(_LIBCPP_VERSION)) || \
- (defined(__GNUC__) && __GNUC__ >= 5)
- ,
- typename = std::enable_if_t<std::is_trivially_constructible<To>::value>
-#elif __has_feature(is_trivially_constructible)
- ,
- typename = std::enable_if_t<__is_trivially_constructible(To)>
-#else
- // See comment below.
-#endif
-#if (__has_feature(is_trivially_copyable) && defined(_LIBCPP_VERSION)) || \
- (defined(__GNUC__) && __GNUC__ >= 5)
- ,
+ typename = std::enable_if_t<sizeof(To) == sizeof(From)>,
+ typename = std::enable_if_t<std::is_trivially_constructible<To>::value>,
typename = std::enable_if_t<std::is_trivially_copyable<To>::value>,
- typename = std::enable_if_t<std::is_trivially_copyable<From>::value>
-#elif __has_feature(is_trivially_copyable)
- ,
- typename = std::enable_if_t<__is_trivially_copyable(To)>,
- typename = std::enable_if_t<__is_trivially_copyable(From)>
-#else
-// This case is GCC 4.x. clang with libc++ or libstdc++ never get here. Unlike
-// llvm/Support/type_traits.h's is_trivially_copyable we don't want to
-// provide a good-enough answer here: developers in that configuration will hit
-// compilation failures on the bots instead of locally. That's acceptable
-// because it's very few developers, and only until we move past C++11.
-#endif
- >
+ typename = std::enable_if_t<std::is_trivially_copyable<From>::value>>
inline To bit_cast(const From &from) noexcept {
To to;
std::memcpy(&to, &from, sizeof(To));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132330.454318.patch
Type: text/x-patch
Size: 1914 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220821/95481de5/attachment.bin>
More information about the llvm-commits
mailing list