From: Christopher Dykes Date: Tue, 19 Jul 2016 22:44:31 +0000 (-0700) Subject: Handle small_vectors with 0 inline capacity correctly X-Git-Tag: 2016.07.26~27 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6a3ea69693839f0521620a7ace498b9c038924d4;p=folly.git Handle small_vectors with 0 inline capacity correctly Summary: It is an error to attempt to get the size of a zero length array, such as `unsigned char[0]`, which is what you get if `MaxInline` has been passed in as 0. We can work around this by simply defining `InlineStorageType` to be `void*` if the size is exactly 0, which will result in the capacity correctly being stored out of line. Reviewed By: yfeldblum Differential Revision: D3572898 fbshipit-source-id: c96bb7cc6a890044bb74b0f6d5238c503552ee25 --- diff --git a/folly/small_vector.h b/folly/small_vector.h index 042961bc..da4547b4 100644 --- a/folly/small_vector.h +++ b/folly/small_vector.h @@ -1038,14 +1038,20 @@ private: } FOLLY_PACK_ATTR; #if (FOLLY_X64 || FOLLY_PPC64) - typedef unsigned char InlineStorageType[sizeof(value_type) * MaxInline]; + typedef unsigned char InlineStorageDataType[sizeof(value_type) * MaxInline]; #else typedef typename std::aligned_storage< sizeof(value_type) * MaxInline, alignof(value_type) - >::type InlineStorageType; + >::type InlineStorageDataType; #endif + typedef typename std::conditional< + sizeof(value_type) * MaxInline != 0, + InlineStorageDataType, + void* + >::type InlineStorageType; + static bool const kHasInlineCapacity = sizeof(HeapPtrWithCapacity) < sizeof(InlineStorageType);