From: Eric Niebler <eniebler@fb.com>
Date: Thu, 20 Oct 2016 23:57:29 +0000 (-0700)
Subject: Reverted commit D3927397
X-Git-Tag: v2016.10.24.00~2
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=fbf4e10c59b331540e8a2668f436ea210a11c22a;p=folly.git

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
---

diff --git a/folly/FBString.h b/folly/FBString.h
index ab0c0d8f..bb3d339b 100644
--- a/folly/FBString.h
+++ b/folly/FBString.h
@@ -1176,30 +1176,17 @@ public:
       InIt begin,
       InIt end,
       typename std::enable_if<
-          !std::is_convertible<InIt, const value_type*>::value,
+          !std::is_same<InIt, value_type*>::value,
           const A>::type& /*a*/ = A()) {
     assign(begin, end);
   }
 
   // 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
   basic_fbstring(const value_type* b, const value_type* e, const A& /*a*/ = A())
       : 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
   basic_fbstring(value_type *s, size_type n, size_type c,
                  AcquireMallocatedString a)
diff --git a/folly/test/FBStringTest.cpp b/folly/test/FBStringTest.cpp
index 4c7ba8f7..fb4a7991 100644
--- a/folly/test/FBStringTest.cpp
+++ b/folly/test/FBStringTest.cpp
@@ -1426,9 +1426,3 @@ TEST(FBStringCtorTest, NullZeroConstruction) {
   folly::fbstring f(p, n);
   EXPECT_EQ(f.size(), 0);
 }
-
-// TEST(FBStringCtorTest, BadIteratorPair) {
-//   // Should fail to compile
-//   std::vector<fbstring> vs{{"hello", "world!"}};
-//   EXPECT_EQ(vs.size(), 2u);
-// }