Suppress clang memcpy warnings
authorNicholas Ormrod <njormrod@fb.com>
Fri, 12 Jun 2015 17:49:08 +0000 (10:49 -0700)
committerSara Golemon <sgolemon@fb.com>
Fri, 12 Jun 2015 20:18:16 +0000 (13:18 -0700)
Summary: Clang warns when types with vtables are memcpy'd. If the type
has declared itself to be relocatable, then this is the desired
behavior. If the type has not declared itself to be relocatable, then
the memcpy codepath is dead. However, the dead codepath is still
instantiated (it's inside an if block with a static check, but c++
doesn't have static-if), so the compiler spits out a nasty warning
anyways.

Each memcpy reference inside of fbvector has been void-ified. I have
looked at all the codepaths leading to the memcpys, and see that they
have isRelocatable or isTriviallyCopyable checks.

Reviewed By: @markisaa

Differential Revision: D2148286

folly/FBVector.h

index 28662fc8a44a54d7ee4854dc41bbc2d205f96c12..754ebfef5f48a93d6a703d34ea58d6ae4c8162ae 100644 (file)
@@ -523,7 +523,7 @@ private:
 
   static void
   S_uninitialized_copy_bits(T* dest, const T* first, const T* last) {
-    std::memcpy(dest, first, (last - first) * sizeof(T));
+    std::memcpy((void*)dest, (void*)first, (last - first) * sizeof(T));
   }
 
   static void
@@ -531,7 +531,7 @@ private:
                        std::move_iterator<T*> last) {
     T* bFirst = first.base();
     T* bLast = last.base();
-    std::memcpy(dest, bFirst, (bLast - bFirst) * sizeof(T));
+    std::memcpy((void*)dest, (void*)bFirst, (bLast - bFirst) * sizeof(T));
   }
 
   template <typename It>
@@ -556,7 +556,7 @@ private:
 
   static const T* S_copy_n(T* dest, const T* first, size_type n) {
     if (folly::IsTriviallyCopyable<T>::value) {
-      std::memcpy(dest, first, n * sizeof(T));
+      std::memcpy((void*)dest, (void*)first, n * sizeof(T));
       return first + n;
     } else {
       return S_copy_n<const T*>(dest, first, n);
@@ -567,7 +567,7 @@ private:
   S_copy_n(T* dest, std::move_iterator<T*> mIt, size_type n) {
     if (folly::IsTriviallyCopyable<T>::value) {
       T* first = mIt.base();
-      std::memcpy(dest, first, n * sizeof(T));
+      std::memcpy((void*)dest, (void*)first, n * sizeof(T));
       return std::make_move_iterator(first + n);
     } else {
       return S_copy_n<std::move_iterator<T*>>(dest, mIt, n);
@@ -637,7 +637,7 @@ private:
   }
 
   void relocate_move_or_memcpy(T* dest, T* first, T* last, std::true_type) {
-    std::memcpy(dest, first, (last - first) * sizeof(T));
+    std::memcpy((void*)dest, (void*)first, (last - first) * sizeof(T));
   }
 
   void relocate_move_or_memcpy(T* dest, T* first, T* last, std::false_type) {
@@ -1176,7 +1176,7 @@ public:
         if (folly::IsRelocatable<T>::value && usingStdAllocator::value) {
           D_destroy_range_a((iterator)first, (iterator)last);
           if (last - first >= cend() - last) {
-            std::memcpy((iterator)first, last, (cend() - last) * sizeof(T));
+            std::memcpy((void*)first, (void*)last, (cend() - last) * sizeof(T));
           } else {
             std::memmove((iterator)first, last, (cend() - last) * sizeof(T));
           }