From 178be5db99d47508fb39c39aad2eae1080ba4b7a Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Tue, 10 Jan 2017 00:26:56 +0000 Subject: [PATCH] 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). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291514 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/AlignOf.h | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/include/llvm/Support/AlignOf.h b/include/llvm/Support/AlignOf.h index 5fda901a100..e1e304f4c1a 100644 --- a/include/llvm/Support/AlignOf.h +++ b/include/llvm/Support/AlignOf.h @@ -107,20 +107,18 @@ LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(128) // Once these are the baselines for LLVM, we can use std::aligned_union instead. namespace detail { -template class AlignerImpl; +template constexpr size_t aligner() { return alignof(T1); } -template -class AlignerImpl : AlignerImpl { - T1 t; - AlignerImpl() = delete; -}; - -template <> class AlignerImpl<> { AlignerImpl() = delete; }; +template constexpr size_t aligner() { + size_t rest = aligner(); + return (alignof(T1) > rest) ? alignof(T1) : rest; +} template constexpr size_t sizer() { return sizeof(T1); } template constexpr size_t sizer() { - return (sizeof(T1) > sizer()) ? sizeof(T1) : sizer(); + size_t rest = sizer(); + return (sizeof(T1) > rest) ? sizeof(T1) : rest; } } // end namespace detail @@ -132,7 +130,7 @@ template constexpr size_t sizer() { /// a placement new of any of these types. template struct AlignedCharArrayUnion - : llvm::AlignedCharArray), + : llvm::AlignedCharArray(), detail::sizer()> {}; } // end namespace llvm -- 2.49.0