diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2014-04-15 06:29:04 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2014-04-15 06:29:04 +0000 |
commit | eb19b8f58b12532e736051fee46dcf2115a4888d (patch) | |
tree | 1a50a0fa17a5ad797dcdcae844cb7e61eddca75f /include/llvm/Support/Allocator.h | |
parent | 9eb71e20aead0f5642068e7582cef994258a7d69 (diff) | |
download | llvm-eb19b8f58b12532e736051fee46dcf2115a4888d.tar.gz llvm-eb19b8f58b12532e736051fee46dcf2115a4888d.tar.bz2 llvm-eb19b8f58b12532e736051fee46dcf2115a4888d.tar.xz |
[Allocator] Constrain the Deallocate templated overloads to only apply
to types which we can compute the size of. The comparison with zero
isn't actually interesting here, it's mostly about putting sizeof into
a sfinae context.
This is particular important for Deallocate as otherwise the void*
overload can quickly become ambiguous.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206251 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/Allocator.h')
-rw-r--r-- | include/llvm/Support/Allocator.h | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/include/llvm/Support/Allocator.h b/include/llvm/Support/Allocator.h index 4da7acefb6..d96c8f254c 100644 --- a/include/llvm/Support/Allocator.h +++ b/include/llvm/Support/Allocator.h @@ -97,12 +97,15 @@ public: } /// \brief Deallocate space for one object without destroying it. - template <typename T> void Deallocate(T *Ptr) { + template <typename T> + typename std::enable_if<sizeof(T) != 0, void>::type Deallocate(T *Ptr) { Deallocate(static_cast<const void *>(Ptr)); } /// \brief Allocate space for an array of objects without constructing them. - template <typename T> void Deallocate(T *Ptr, size_t /*Num*/) { + template <typename T> + typename std::enable_if<sizeof(T) != 0, void>::type + Deallocate(T *Ptr, size_t /*Num*/) { Deallocate(static_cast<const void *>(Ptr)); } }; |