[libc++] Clean up mess around __throw_runtime_error

We were defining the function in locale.cpp, and we actually had two
overloads for it. This is pretty confusing given that one was static
and not exported from the dylib, and the other one was. Instead, use
the vanilla __throw_runtime_error function everywhere even though that
adds a tiny bit of code duplication.

Differential Revision: https://reviews.llvm.org/D155008
diff --git a/libcxx/src/locale.cpp b/libcxx/src/locale.cpp
index bd70a27..3922bd8 100644
--- a/libcxx/src/locale.cpp
+++ b/libcxx/src/locale.cpp
@@ -7,7 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 #include <__utility/unreachable.h>
-#include <__verbose_abort>
 #include <algorithm>
 #include <clocale>
 #include <codecvt>
@@ -111,15 +110,6 @@
     return static_cast<size_t>(end - begin);
 }
 
-_LIBCPP_NORETURN static void __throw_runtime_error(const string &msg)
-{
-#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
-    throw runtime_error(msg);
-#else
-    _LIBCPP_VERBOSE_ABORT("runtime_error was thrown in -fno-exceptions mode with message \"%s\"", msg.c_str());
-#endif
-}
-
 }
 
 string
@@ -739,8 +729,8 @@
       __l_(newlocale(LC_ALL_MASK, n, 0))
 {
     if (__l_ == 0)
-        __throw_runtime_error("collate_byname<char>::collate_byname"
-                            " failed to construct for " + string(n));
+        __throw_runtime_error(("collate_byname<char>::collate_byname"
+                               " failed to construct for " + string(n)).c_str());
 }
 
 collate_byname<char>::collate_byname(const string& name, size_t refs)
@@ -748,8 +738,8 @@
       __l_(newlocale(LC_ALL_MASK, name.c_str(), 0))
 {
     if (__l_ == 0)
-        __throw_runtime_error("collate_byname<char>::collate_byname"
-                            " failed to construct for " + name);
+        __throw_runtime_error(("collate_byname<char>::collate_byname"
+                               " failed to construct for " + name).c_str());
 }
 
 collate_byname<char>::~collate_byname()
@@ -788,8 +778,8 @@
       __l_(newlocale(LC_ALL_MASK, n, 0))
 {
     if (__l_ == 0)
-        __throw_runtime_error("collate_byname<wchar_t>::collate_byname(size_t refs)"
-                            " failed to construct for " + string(n));
+        __throw_runtime_error(("collate_byname<wchar_t>::collate_byname(size_t refs)"
+                               " failed to construct for " + string(n)).c_str());
 }
 
 collate_byname<wchar_t>::collate_byname(const string& name, size_t refs)
@@ -797,8 +787,8 @@
       __l_(newlocale(LC_ALL_MASK, name.c_str(), 0))
 {
     if (__l_ == 0)
-        __throw_runtime_error("collate_byname<wchar_t>::collate_byname(size_t refs)"
-                            " failed to construct for " + name);
+        __throw_runtime_error(("collate_byname<wchar_t>::collate_byname(size_t refs)"
+                               " failed to construct for " + name).c_str());
 }
 
 collate_byname<wchar_t>::~collate_byname()
@@ -1284,8 +1274,8 @@
       __l_(newlocale(LC_ALL_MASK, name, 0))
 {
     if (__l_ == 0)
-        __throw_runtime_error("ctype_byname<char>::ctype_byname"
-                            " failed to construct for " + string(name));
+        __throw_runtime_error(("ctype_byname<char>::ctype_byname"
+                               " failed to construct for " + string(name)).c_str());
 }
 
 ctype_byname<char>::ctype_byname(const string& name, size_t refs)
@@ -1293,8 +1283,8 @@
       __l_(newlocale(LC_ALL_MASK, name.c_str(), 0))
 {
     if (__l_ == 0)
-        __throw_runtime_error("ctype_byname<char>::ctype_byname"
-                            " failed to construct for " + name);
+        __throw_runtime_error(("ctype_byname<char>::ctype_byname"
+                               " failed to construct for " + name).c_str());
 }
 
 ctype_byname<char>::~ctype_byname()
@@ -1338,8 +1328,8 @@
       __l_(newlocale(LC_ALL_MASK, name, 0))
 {
     if (__l_ == 0)
-        __throw_runtime_error("ctype_byname<wchar_t>::ctype_byname"
-                            " failed to construct for " + string(name));
+        __throw_runtime_error(("ctype_byname<wchar_t>::ctype_byname"
+                               " failed to construct for " + string(name)).c_str());
 }
 
 ctype_byname<wchar_t>::ctype_byname(const string& name, size_t refs)
@@ -1347,8 +1337,8 @@
       __l_(newlocale(LC_ALL_MASK, name.c_str(), 0))
 {
     if (__l_ == 0)
-        __throw_runtime_error("ctype_byname<wchar_t>::ctype_byname"
-                            " failed to construct for " + name);
+        __throw_runtime_error(("ctype_byname<wchar_t>::ctype_byname"
+                               " failed to construct for " + name).c_str());
 }
 
 ctype_byname<wchar_t>::~ctype_byname()
@@ -1609,8 +1599,8 @@
       __l_(newlocale(LC_ALL_MASK, nm, 0))
 {
     if (__l_ == 0)
-        __throw_runtime_error("codecvt_byname<wchar_t, char, mbstate_t>::codecvt_byname"
-                            " failed to construct for " + string(nm));
+        __throw_runtime_error(("codecvt_byname<wchar_t, char, mbstate_t>::codecvt_byname"
+                               " failed to construct for " + string(nm)).c_str());
 }
 
 codecvt<wchar_t, char, mbstate_t>::~codecvt()
@@ -4720,8 +4710,8 @@
     {
         __libcpp_unique_locale loc(nm);
         if (!loc)
-            __throw_runtime_error("numpunct_byname<char>::numpunct_byname"
-                                " failed to construct for " + string(nm));
+            __throw_runtime_error(("numpunct_byname<char>::numpunct_byname"
+                                   " failed to construct for " + string(nm)).c_str());
 
         lconv* lc = __libcpp_localeconv_l(loc.get());
         if (!checked_string_to_char_convert(__decimal_point_, lc->decimal_point,
@@ -4761,8 +4751,8 @@
     {
         __libcpp_unique_locale loc(nm);
         if (!loc)
-            __throw_runtime_error("numpunct_byname<wchar_t>::numpunct_byname"
-                                " failed to construct for " + string(nm));
+            __throw_runtime_error(("numpunct_byname<wchar_t>::numpunct_byname"
+                                   " failed to construct for " + string(nm)).c_str());
 
         lconv* lc = __libcpp_localeconv_l(loc.get());
         checked_string_to_wchar_convert(__decimal_point_, lc->decimal_point,
@@ -5193,16 +5183,14 @@
     : __loc_(newlocale(LC_ALL_MASK, nm, 0))
 {
     if (__loc_ == 0)
-        __throw_runtime_error("time_get_byname"
-                            " failed to construct for " + string(nm));
+        __throw_runtime_error(("time_get_byname failed to construct for " + string(nm)).c_str());
 }
 
 __time_get::__time_get(const string& nm)
     : __loc_(newlocale(LC_ALL_MASK, nm.c_str(), 0))
 {
     if (__loc_ == 0)
-        __throw_runtime_error("time_get_byname"
-                            " failed to construct for " + nm);
+        __throw_runtime_error(("time_get_byname failed to construct for " + nm).c_str());
 }
 
 __time_get::~__time_get()
@@ -5851,16 +5839,14 @@
     : __loc_(newlocale(LC_ALL_MASK, nm, 0))
 {
     if (__loc_ == 0)
-        __throw_runtime_error("time_put_byname"
-                            " failed to construct for " + string(nm));
+        __throw_runtime_error(("time_put_byname failed to construct for " + string(nm)).c_str());
 }
 
 __time_put::__time_put(const string& nm)
     : __loc_(newlocale(LC_ALL_MASK, nm.c_str(), 0))
 {
     if (__loc_ == 0)
-        __throw_runtime_error("time_put_byname"
-                            " failed to construct for " + nm);
+        __throw_runtime_error(("time_put_byname failed to construct for " + nm).c_str());
 }
 
 __time_put::~__time_put()
@@ -6278,8 +6264,7 @@
     typedef moneypunct<char, false> base;
     __libcpp_unique_locale loc(nm);
     if (!loc)
-        __throw_runtime_error("moneypunct_byname"
-                            " failed to construct for " + string(nm));
+        __throw_runtime_error(("moneypunct_byname failed to construct for " + string(nm)).c_str());
 
     lconv* lc = __libcpp_localeconv_l(loc.get());
     if (!checked_string_to_char_convert(__decimal_point_,
@@ -6322,8 +6307,7 @@
     typedef moneypunct<char, true> base;
     __libcpp_unique_locale loc(nm);
     if (!loc)
-        __throw_runtime_error("moneypunct_byname"
-                            " failed to construct for " + string(nm));
+        __throw_runtime_error(("moneypunct_byname failed to construct for " + string(nm)).c_str());
 
     lconv* lc = __libcpp_localeconv_l(loc.get());
     if (!checked_string_to_char_convert(__decimal_point_,
@@ -6383,8 +6367,7 @@
     typedef moneypunct<wchar_t, false> base;
     __libcpp_unique_locale loc(nm);
     if (!loc)
-        __throw_runtime_error("moneypunct_byname"
-                            " failed to construct for " + string(nm));
+        __throw_runtime_error(("moneypunct_byname failed to construct for " + string(nm)).c_str());
     lconv* lc = __libcpp_localeconv_l(loc.get());
     if (!checked_string_to_wchar_convert(__decimal_point_,
                                          lc->mon_decimal_point,
@@ -6448,8 +6431,7 @@
     typedef moneypunct<wchar_t, true> base;
     __libcpp_unique_locale loc(nm);
     if (!loc)
-        __throw_runtime_error("moneypunct_byname"
-                            " failed to construct for " + string(nm));
+        __throw_runtime_error(("moneypunct_byname failed to construct for " + string(nm)).c_str());
 
     lconv* lc = __libcpp_localeconv_l(loc.get());
     if (!checked_string_to_wchar_convert(__decimal_point_,
@@ -6527,15 +6509,6 @@
 
 void __do_nothing(void*) {}
 
-void __throw_runtime_error(const char* msg)
-{
-#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
-    throw runtime_error(msg);
-#else
-    _LIBCPP_VERBOSE_ABORT("runtime_error was thrown in -fno-exceptions mode with message \"%s\"", msg);
-#endif
-}
-
                            template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate<char>;
 _LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate<wchar_t>;)
 
diff --git a/libcxx/src/stdexcept.cpp b/libcxx/src/stdexcept.cpp
index d5c9173..bc25c0f 100644
--- a/libcxx/src/stdexcept.cpp
+++ b/libcxx/src/stdexcept.cpp
@@ -6,12 +6,25 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include <__verbose_abort>
 #include <new>
 #include <stdexcept>
 #include <string>
 
 #ifdef _LIBCPP_ABI_VCRUNTIME
-#include "support/runtime/stdexcept_vcruntime.ipp"
+#  include "support/runtime/stdexcept_vcruntime.ipp"
 #else
-#include "support/runtime/stdexcept_default.ipp"
+#  include "support/runtime/stdexcept_default.ipp"
 #endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+_LIBCPP_NORETURN void __throw_runtime_error(const char* msg) {
+#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+  throw runtime_error(msg);
+#else
+  _LIBCPP_VERBOSE_ABORT("runtime_error was thrown in -fno-exceptions mode with message \"%s\"", msg);
+#endif
+}
+
+_LIBCPP_END_NAMESPACE_STD
diff --git a/libcxx/utils/data/ignore_format.txt b/libcxx/utils/data/ignore_format.txt
index c3a5242..83e175e 100644
--- a/libcxx/utils/data/ignore_format.txt
+++ b/libcxx/utils/data/ignore_format.txt
@@ -555,7 +555,6 @@
 libcxx/src/random.cpp
 libcxx/src/random_shuffle.cpp
 libcxx/src/regex.cpp
-libcxx/src/stdexcept.cpp
 libcxx/src/std_stream.h
 libcxx/src/string.cpp
 libcxx/src/strstream.cpp