folly/Traits.h: fix a deep problem with FBVector
authorJim Meyering <meyering@fb.com>
Fri, 13 Jan 2017 21:01:25 +0000 (13:01 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 13 Jan 2017 21:03:02 +0000 (13:03 -0800)
commit73199d4c98b3d158a7a188b779cf2f2b0cc7ec88
tree42298655b5cf0787d9409a202200e8dad3d10c11
parent0e7c824d239f6668be1afb2ffd334f89ce294c80
folly/Traits.h: fix a deep problem with FBVector

Summary:
This started when many fbvector-related tests began failing with reports of
ASAN-detected heap abuse (usually invalid free of an address 16 bytes
into an already-freed buffer).

It was very specific, though. The bug struck only when:
  - gcc-5-based platform
  - compiling with clang (~3.8) and GCC5's libstdc++, not gcc
  - strings were short enough to reside within an in-situ std::string

Why? because FBVector.h:1588's conditional:

  if (folly::IsRelocatable<T>::value && usingStdAllocator::value) {

was true for clang (erroneously), but false for gcc. The difference
was in `IsRelocatable<std::string>::value`.  However, manual tests showed that
each component from the definition of `IsRelocatable` were the same for both
gcc and clang. Then Jay Feldblum realized that we'd probably specialized
that trait for `std::string`, and sure enough, I found the culprit:

```
FOLLY_ASSUME_FBVECTOR_COMPATIBLE_3(std::basic_string)
```

Reviewed By: pixelb

Differential Revision: D4414159

fbshipit-source-id: 60e3fb4b096ec77cbd2b48c561e5c6ec8f128fff
folly/Traits.h