Commit 6a3ea696 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot

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
parent 26b139fc
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment