Make Allocate<T>() return a T* instead of a void*. And use
authorDan Gohman <gohman@apple.com>
Tue, 24 Jun 2008 17:49:26 +0000 (17:49 +0000)
committerDan Gohman <gohman@apple.com>
Tue, 24 Jun 2008 17:49:26 +0000 (17:49 +0000)
static_cast instead of reinterpret_cast.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52686 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/Allocator.h

index 33cdca13e64e014720466c7fc66fba649a472035..14211488a5953fa2a813e784c5d000b7a3abb4ab 100644 (file)
@@ -25,12 +25,14 @@ public:
   ~MallocAllocator() {}
   
   void Reset() {}
+
   void *Allocate(size_t Size, size_t Alignment) { return malloc(Size); }
   
   template <typename T>
-  void *Allocate() { return reinterpret_cast<T*>(malloc(sizeof(T))); }
+  T *Allocate() { return static_cast<T*>(malloc(sizeof(T))); }
   
   void Deallocate(void *Ptr) { free(Ptr); }
+
   void PrintStats() const {}
 };
 
@@ -45,15 +47,16 @@ public:
   ~BumpPtrAllocator();
   
   void Reset();
+
   void *Allocate(size_t Size, size_t Alignment);
 
   template <typename T>
-  void *Allocate() { 
-    return reinterpret_cast<T*>(Allocate(sizeof(T),AlignOf<T>::Alignment));
+  T *Allocate() { 
+    return static_cast<T*>(Allocate(sizeof(T),AlignOf<T>::Alignment));
   }
-
   
   void Deallocate(void *Ptr) {}
+
   void PrintStats() const;
 };