[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
This commit is contained in:
Louis Dionne
2023-07-11 14:55:26 -04:00
parent 042abb477c
commit 280d68e7f8
3 changed files with 45 additions and 60 deletions

View File

@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include <__utility/unreachable.h>
#include <__verbose_abort>
#include <algorithm>
#include <clocale>
#include <codecvt>
@@ -111,15 +110,6 @@ countof(const T * const begin, const T * const end)
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 @@ collate_byname<char>::collate_byname(const char* n, size_t refs)
__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 @@ collate_byname<char>::collate_byname(const string& name, size_t refs)
__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 @@ collate_byname<wchar_t>::collate_byname(const char* n, size_t refs)
__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 @@ collate_byname<wchar_t>::collate_byname(const string& name, size_t refs)
__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 @@ ctype_byname<char>::ctype_byname(const char* name, size_t refs)
__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 @@ ctype_byname<char>::ctype_byname(const string& name, size_t refs)
__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 @@ ctype_byname<wchar_t>::ctype_byname(const char* name, size_t refs)
__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 @@ ctype_byname<wchar_t>::ctype_byname(const string& name, size_t refs)
__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 @@ codecvt<wchar_t, char, mbstate_t>::codecvt(const char* nm, size_t refs)
__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 @@ numpunct_byname<char>::__init(const char* nm)
{
__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 @@ numpunct_byname<wchar_t>::__init(const char* nm)
{
__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 @@ __time_get::__time_get(const char* nm)
: __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 @@ __time_put::__time_put(const char* nm)
: __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 @@ moneypunct_byname<char, false>::init(const char* nm)
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 @@ moneypunct_byname<char, true>::init(const char* nm)
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 @@ moneypunct_byname<wchar_t, false>::init(const char* nm)
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 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
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 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
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>;)

View File

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

View File

@@ -555,7 +555,6 @@ libcxx/src/pstl/libdispatch.cpp
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