[llvm] r291514 - Fix MSVC build of AlignedCharArrayUnion

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 9 16:26:56 PST 2017


Author: rnk
Date: Mon Jan  9 18:26:56 2017
New Revision: 291514

URL: http://llvm.org/viewvc/llvm-project?rev=291514&view=rev
Log:
Fix MSVC build of AlignedCharArrayUnion

Use constexpr recursion for alignof like we do for sizeof. Seems to work
with Clang and MSVC. Also, don't recurse twice to avoid slowdowns in
compilers that don't memoize constexpr results (Clang).

Modified:
    llvm/trunk/include/llvm/Support/AlignOf.h

Modified: llvm/trunk/include/llvm/Support/AlignOf.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/AlignOf.h?rev=291514&r1=291513&r2=291514&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/AlignOf.h (original)
+++ llvm/trunk/include/llvm/Support/AlignOf.h Mon Jan  9 18:26:56 2017
@@ -107,20 +107,18 @@ LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT
 // Once these are the baselines for LLVM, we can use std::aligned_union instead.
 
 namespace detail {
-template <typename... Ts> class AlignerImpl;
+template <typename T1> constexpr size_t aligner() { return alignof(T1); }
 
-template <typename T1, typename... Ts>
-class AlignerImpl<T1, Ts...> : AlignerImpl<Ts...> {
-  T1 t;
-  AlignerImpl() = delete;
-};
-
-template <> class AlignerImpl<> { AlignerImpl() = delete; };
+template <typename T1, typename T2, typename... Ts> constexpr size_t aligner() {
+  size_t rest = aligner<T2, Ts...>();
+  return (alignof(T1) > rest) ? alignof(T1) : rest;
+}
 
 template <typename T1> constexpr size_t sizer() { return sizeof(T1); }
 
 template <typename T1, typename T2, typename... Ts> constexpr size_t sizer() {
-  return (sizeof(T1) > sizer<T2, Ts...>()) ? sizeof(T1) : sizer<T2, Ts...>();
+  size_t rest = sizer<T2, Ts...>();
+  return (sizeof(T1) > rest) ? sizeof(T1) : rest;
 }
 } // end namespace detail
 
@@ -132,7 +130,7 @@ template <typename T1, typename T2, type
 /// a placement new of any of these types.
 template <typename... Ts>
 struct AlignedCharArrayUnion
-    : llvm::AlignedCharArray<alignof(llvm::detail::AlignerImpl<Ts...>),
+    : llvm::AlignedCharArray<detail::aligner<Ts...>(),
                              detail::sizer<Ts...>()> {};
 } // end namespace llvm
 




More information about the llvm-commits mailing list