[llvm] r206251 - [Allocator] Constrain the Deallocate templated overloads to only apply

Chandler Carruth chandlerc at gmail.com
Mon Apr 14 23:29:04 PDT 2014


Author: chandlerc
Date: Tue Apr 15 01:29:04 2014
New Revision: 206251

URL: http://llvm.org/viewvc/llvm-project?rev=206251&view=rev
Log:
[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.

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

Modified: llvm/trunk/include/llvm/Support/Allocator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Allocator.h?rev=206251&r1=206250&r2=206251&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Allocator.h (original)
+++ llvm/trunk/include/llvm/Support/Allocator.h Tue Apr 15 01:29:04 2014
@@ -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));
   }
 };





More information about the llvm-commits mailing list