Make fbstring libgcc-safe
authorNicholas Ormrod <njormrod@fb.com>
Wed, 18 Jun 2014 16:35:10 +0000 (09:35 -0700)
committerAnton Likhtarov <alikhtarov@fb.com>
Thu, 26 Jun 2014 02:24:24 +0000 (19:24 -0700)
Summary:
Some libgcc-incompatible code has been added to fbstring.
Removed/reorganized it so that we can drop fbstring right into libgcc.

Test Plan:
fbconfig -r folly && fbmake runtests

Copied FBString.h into libgcc's basic_fbstring.h, with no modifications.
Successfully tp2_build libgcc/4.8.1. Adjusted symlink, then fbmake clean
&& fbconfig -r folly && fbmake dbg. The fbmake dbg failed with an
assertion error, which is consistent with @lucian's observations in
D1373725; the important part is that the error was at runtime, so the
compile-time changes of this diff looks good.

Reviewed By: lucian@fb.com

Subscribers: folly@lists, sdwilsh, njormrod, lucian

FB internal diff: D1382873

folly/FBString.h

index 2f4c9a445a3fa7d4c41afd01e7fc936173c79036..4b59ac9e797646540003d7ff3b78f388e13c2bdf 100644 (file)
 #include <atomic>
 #include <limits>
 #include <type_traits>
-#include <algorithm>
-
-#include "folly/Portability.h"
 
-// libc++ doesn't provide this header, nor does msvc
-#ifdef FOLLY_HAVE_BITS_CXXCONFIG_H
 // This file appears in two locations: inside fbcode and in the
 // libstdc++ source code (when embedding fbstring as std::string).
-// To aid in this schizophrenic use, two macros are defined in
-// c++config.h:
-//   _LIBSTDCXX_FBSTRING - Set inside libstdc++.  This is useful to
-//      gate use inside fbcode v. libstdc++
-#include <bits/c++config.h>
-#endif
-
+// To aid in this schizophrenic use, _LIBSTDCXX_FBSTRING is defined in
+// libstdc++'s c++config.h, to gate use inside fbcode v. libstdc++.
 #ifdef _LIBSTDCXX_FBSTRING
 
 #pragma GCC system_header
 
 #else // !_LIBSTDCXX_FBSTRING
 
+#include "folly/Portability.h"
+
+// libc++ doesn't provide this header, nor does msvc
+#ifdef FOLLY_HAVE_BITS_CXXCONFIG_H
+#include <bits/c++config.h>
+#endif
+
 #include <string>
 #include <cstring>
 #include <cassert>
+#include <algorithm>
 
 #include "folly/Traits.h"
 #include "folly/Malloc.h"
@@ -1014,11 +1012,9 @@ public:
   /* implicit */ basic_fbstring(const value_type* s, const A& a = A())
       : store_(s, s
           ? traits_type::length(s)
-          : [] {
-              std::__throw_logic_error(
-                "basic_fbstring: null pointer initializer not valid");
-              return 0;
-            }()) {
+          : (std::__throw_logic_error(
+                "basic_fbstring: null pointer initializer not valid"),
+             0)) {
   }
 
   basic_fbstring(const value_type* s, size_type n, const A& a = A())
@@ -2426,6 +2422,7 @@ struct hash< ::folly::fbstring> {
 
 }
 
+#ifndef _LIBSTDCXX_FBSTRING
 #if FOLLY_HAVE_DEPRECATED_ASSOC
 #if defined(_GLIBCXX_SYMVER) && !defined(__BIONIC__)
 namespace __gnu_cxx {
@@ -2447,6 +2444,7 @@ struct hash< ::folly::fbstring> {
 }
 #endif // _GLIBCXX_SYMVER && !__BIONIC__
 #endif // FOLLY_HAVE_DEPRECATED_ASSOC
+#endif // _LIBSTDCXX_FBSTRING
 
 #endif // _LIBSTDCXX_FBSTRING