[llvm] bc316c2 - Fix SFINAE in llvm::bit_cast.

Justin Lebar via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 12 08:26:40 PST 2020


Author: Justin Lebar
Date: 2020-02-12T08:26:10-08:00
New Revision: bc316c21570b3ff93a7e064a6fb2f6b56d26d850

URL: https://github.com/llvm/llvm-project/commit/bc316c21570b3ff93a7e064a6fb2f6b56d26d850
DIFF: https://github.com/llvm/llvm-project/commit/bc316c21570b3ff93a7e064a6fb2f6b56d26d850.diff

LOG: Fix SFINAE in llvm::bit_cast.

Summary:
As far as I can tell, the SFINAE was broken; there is no such thing as
std::is_trivially_constructible<T>::type.

Subscribers: dexonsmith, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D74380

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/bit.h b/llvm/include/llvm/ADT/bit.h
index a790d5ed2d21..d76bc6c6046c 100644
--- a/llvm/include/llvm/ADT/bit.h
+++ b/llvm/include/llvm/ADT/bit.h
@@ -22,23 +22,28 @@ namespace llvm {
 // This implementation of bit_cast is 
diff erent 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.
-template <typename To, typename From
-          , typename = typename std::enable_if<sizeof(To) == sizeof(From)>::type
+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 = typename std::is_trivially_constructible<To>::type
+    ,
+    typename = std::enable_if_t<std::is_trivially_constructible<To>::value>
 #elif __has_feature(is_trivially_constructible)
-          , typename = typename std::enable_if<__is_trivially_constructible(To)>::type
+    ,
+    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 = typename std::enable_if<std::is_trivially_copyable<To>::value>::type
-          , typename = typename std::enable_if<std::is_trivially_copyable<From>::value>::type
+    ,
+    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 = typename std::enable_if<__is_trivially_copyable(To)>::type
-          , typename = typename std::enable_if<__is_trivially_copyable(From)>::type
+    ,
+    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
@@ -46,7 +51,7 @@ template <typename To, typename From
 // 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
->
+    >
 inline To bit_cast(const From &from) noexcept {
   To to;
   std::memcpy(&to, &from, sizeof(To));


        


More information about the llvm-commits mailing list