From: Nicholas Ormrod Date: Fri, 12 Jun 2015 17:49:08 +0000 (-0700) Subject: Suppress clang memcpy warnings X-Git-Tag: v0.47.0~26 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=3bb128276a7edeae46d14f4a345298c3a1e983ba;p=folly.git Suppress clang memcpy warnings 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 --- diff --git a/folly/FBVector.h b/folly/FBVector.h index 28662fc8..754ebfef 100644 --- a/folly/FBVector.h +++ b/folly/FBVector.h @@ -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 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 @@ -556,7 +556,7 @@ private: static const T* S_copy_n(T* dest, const T* first, size_type n) { if (folly::IsTriviallyCopyable::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(dest, first, n); @@ -567,7 +567,7 @@ private: S_copy_n(T* dest, std::move_iterator mIt, size_type n) { if (folly::IsTriviallyCopyable::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>(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::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)); }