Commit fbf4e10c authored by Eric Niebler's avatar Eric Niebler Committed by Facebook Github Bot

Reverted commit D3927397

Summary: Someone debugged a runtime crash and traced it back to code like: `vector<fbstring>{{"this", "that"}}`. Presumably the user thought they were passing an initializer list of strings to the vector constructor. Instead, they constructed a single fbstring with two char pointers pointing into //different// strings. With the appropriate fbstring constructors, we can flag this as invalid at compile-time.

Reviewed By: yfeldblum

Differential Revision: D3927397

fbshipit-source-id: ab61e1e8498ec99592a2a7726eaf1cb6324f1455
parent cbec2f20
...@@ -1176,30 +1176,17 @@ public: ...@@ -1176,30 +1176,17 @@ public:
InIt begin, InIt begin,
InIt end, InIt end,
typename std::enable_if< typename std::enable_if<
!std::is_convertible<InIt, const value_type*>::value, !std::is_same<InIt, value_type*>::value,
const A>::type& /*a*/ = A()) { const A>::type& /*a*/ = A()) {
assign(begin, end); assign(begin, end);
} }
// Specialization for const char*, const char* // Specialization for const char*, const char*
// Note: it's a template to keep it from being preferred when called as
// basic_fbstring("hello", "world!").
// See the constructor immediately below.
template <class = void>
FOLLY_MALLOC_NOINLINE FOLLY_MALLOC_NOINLINE
basic_fbstring(const value_type* b, const value_type* e, const A& /*a*/ = A()) basic_fbstring(const value_type* b, const value_type* e, const A& /*a*/ = A())
: store_(b, e - b) { : store_(b, e - b) {
} }
// Nonstandard constructor. To make the following code fail to compile
// instead of silently selecting the {Iter,Iter} constructor and crashing
// at runtime:
// std::vector<fbtring> const foo{{"this", "that"}};
template <std::size_t N, std::size_t M>
basic_fbstring(const value_type (&/*x*/)[N],
const value_type (&/*y*/)[M],
const A& /*a*/ = A()) = delete;
// Nonstandard constructor // Nonstandard constructor
basic_fbstring(value_type *s, size_type n, size_type c, basic_fbstring(value_type *s, size_type n, size_type c,
AcquireMallocatedString a) AcquireMallocatedString a)
......
...@@ -1426,9 +1426,3 @@ TEST(FBStringCtorTest, NullZeroConstruction) { ...@@ -1426,9 +1426,3 @@ TEST(FBStringCtorTest, NullZeroConstruction) {
folly::fbstring f(p, n); folly::fbstring f(p, n);
EXPECT_EQ(f.size(), 0); EXPECT_EQ(f.size(), 0);
} }
// TEST(FBStringCtorTest, BadIteratorPair) {
// // Should fail to compile
// std::vector<fbstring> vs{{"hello", "world!"}};
// EXPECT_EQ(vs.size(), 2u);
// }
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