now works with -fno-exceptions and -fno-rtti

llvm-svn: 110828
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: 54b409fdb9489b305bf95f4d4f52b49c7926c429
diff --git a/src/exception.cpp b/src/exception.cpp
index 9bed6f4..7c52115 100644
--- a/src/exception.cpp
+++ b/src/exception.cpp
@@ -54,15 +54,21 @@
 void
 std::terminate()
 {
-    try {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
         (*__terminate_handler)();
         // handler should not return
         ::abort ();
+#ifndef _LIBCPP_NO_EXCEPTIONS
     } 
-    catch (...) {
+    catch (...)
+    {
         // handler should not throw exception
         ::abort ();
     }
+#endif
 }
 
 
diff --git a/src/ios.cpp b/src/ios.cpp
index eb597bf..4139cd4 100644
--- a/src/ios.cpp
+++ b/src/ios.cpp
@@ -260,8 +260,10 @@
         __rdstate_ = state;
     else
         __rdstate_ = state | badbit;
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (((state | (__rdbuf_ ? goodbit : badbit)) & __exceptions_) != 0)
         throw failure("ios_base::clear");
+#endif
 }
 
 // init
@@ -300,23 +302,31 @@
     if (__event_cap_ < rhs.__event_size_)
     {
         new_callbacks.reset((event_callback*)malloc(sizeof(event_callback) * rhs.__event_size_));
+#ifndef _LIBCPP_NO_EXCEPTIONS
         if (!new_callbacks)
             throw bad_alloc();
+#endif
         new_ints.reset((int*)malloc(sizeof(int) * rhs.__event_size_));
+#ifndef _LIBCPP_NO_EXCEPTIONS
         if (!new_ints)
             throw bad_alloc();
+#endif
     }
     if (__iarray_cap_ < rhs.__iarray_size_)
     {
         new_longs.reset((long*)malloc(sizeof(long) * rhs.__iarray_size_));
+#ifndef _LIBCPP_NO_EXCEPTIONS
         if (!new_longs)
             throw bad_alloc();
+#endif
     }
     if (__parray_cap_ < rhs.__parray_size_)
     {
         new_pointers.reset((void**)malloc(sizeof(void*) * rhs.__parray_size_));
+#ifndef _LIBCPP_NO_EXCEPTIONS
         if (!new_pointers)
             throw bad_alloc();
+#endif
     }
     // Got everything we need.  Copy everything but __rdstate_, __rdbuf_ and __exceptions_
     __fmtflags_ = rhs.__fmtflags_;
@@ -417,16 +427,20 @@
 ios_base::__set_badbit_and_consider_rethrow()
 {
     __rdstate_ |= badbit;
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__exceptions_ & badbit)
         throw;
+#endif
 }
 
 void
 ios_base::__set_failbit_and_consider_rethrow()
 {
     __rdstate_ |= failbit;
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__exceptions_ & failbit)
         throw;
+#endif
 }
 
 bool
diff --git a/src/locale.cpp b/src/locale.cpp
index e0d97dc..93d881e 100644
--- a/src/locale.cpp
+++ b/src/locale.cpp
@@ -132,8 +132,10 @@
       name_(name),
       facets_(N)
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     try
     {
+#endif
         facets_ = locale::classic().__locale_->facets_;
         for (unsigned i = 0; i < facets_.size(); ++i)
             if (facets_[i])
@@ -158,6 +160,7 @@
         install(new time_put_byname<wchar_t>(name_));
         install(new messages_byname<char>(name_));
         install(new messages_byname<wchar_t>(name_));
+#ifndef _LIBCPP_NO_EXCEPTIONS
     }
     catch (...)
     {
@@ -166,6 +169,7 @@
                 facets_[i]->__release_shared();
         throw;
     }
+#endif
 }
 
 locale::__imp::__imp(const __imp& other)
@@ -186,8 +190,10 @@
     for (unsigned i = 0; i < facets_.size(); ++i)
         if (facets_[i])
             facets_[i]->__add_shared();
+#ifndef _LIBCPP_NO_EXCEPTIONS
     try
     {
+#endif
         if (c & locale::collate)
         {
             install(new collate_byname<char>(name));
@@ -226,6 +232,7 @@
             install(new messages_byname<char>(name));
             install(new messages_byname<wchar_t>(name));
         }
+#ifndef _LIBCPP_NO_EXCEPTIONS
     }
     catch (...)
     {
@@ -234,6 +241,7 @@
                 facets_[i]->__release_shared();
         throw;
     }
+#endif
 }
 
 template<class F>
@@ -253,8 +261,10 @@
     for (unsigned i = 0; i < facets_.size(); ++i)
         if (facets_[i])
             facets_[i]->__add_shared();
+#ifndef _LIBCPP_NO_EXCEPTIONS
     try
     {
+#endif
         if (c & locale::collate)
         {
             install_from<_STD::collate<char> >(one);
@@ -301,6 +311,7 @@
             install_from<_STD::messages<char> >(one);
             install_from<_STD::messages<wchar_t> >(one);
         }
+#ifndef _LIBCPP_NO_EXCEPTIONS
     }
     catch (...)
     {
@@ -309,6 +320,7 @@
                 facets_[i]->__release_shared();
         throw;
     }
+#endif
 }
 
 locale::__imp::__imp(const __imp& other, facet* f, long id)
@@ -346,8 +358,10 @@
 const locale::facet*
 locale::__imp::use_facet(long id) const
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (!has_facet(id))
         throw bad_cast();
+#endif
     return facets_[id];
 }
 
@@ -414,8 +428,12 @@
 }
 
 locale::locale(const char* name)
+#ifndef _LIBCPP_NO_EXCEPTIONS
     : __locale_(name ? new __imp(name)
                      : throw runtime_error("locale constructed with null"))
+#else
+    : __locale_(new __imp(name))
+#endif
 {
     __locale_->__add_shared();
 }
@@ -427,8 +445,12 @@
 }
 
 locale::locale(const locale& other, const char* name, category c)
+#ifndef _LIBCPP_NO_EXCEPTIONS
     : __locale_(name ? new __imp(*other.__locale_, name, c)
                      : throw runtime_error("locale constructed with null"))
+#else
+    : __locale_(new __imp(*other.__locale_, name, c))
+#endif
 {
     __locale_->__add_shared();
 }
@@ -545,18 +567,22 @@
     : collate<char>(refs),
       __l(newlocale(LC_ALL_MASK, n, 0))
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__l == 0)
         throw runtime_error("collate_byname<char>::collate_byname"
                             " failed to construct for " + string(n));
+#endif
 }
 
 collate_byname<char>::collate_byname(const string& name, size_t refs)
     : collate<char>(refs),
       __l(newlocale(LC_ALL_MASK, name.c_str(), 0))
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__l == 0)
         throw runtime_error("collate_byname<char>::collate_byname"
                             " failed to construct for " + name);
+#endif
 }
 
 collate_byname<char>::~collate_byname()
@@ -593,18 +619,22 @@
     : collate<wchar_t>(refs),
       __l(newlocale(LC_ALL_MASK, n, 0))
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__l == 0)
         throw runtime_error("collate_byname<wchar_t>::collate_byname(size_t refs)"
                             " failed to construct for " + string(n));
+#endif
 }
 
 collate_byname<wchar_t>::collate_byname(const string& name, size_t refs)
     : collate<wchar_t>(refs),
       __l(newlocale(LC_ALL_MASK, name.c_str(), 0))
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__l == 0)
         throw runtime_error("collate_byname<wchar_t>::collate_byname(size_t refs)"
                             " failed to construct for " + name);
+#endif
 }
 
 collate_byname<wchar_t>::~collate_byname()
@@ -828,18 +858,22 @@
     : ctype<char>(0, false, refs),
       __l(newlocale(LC_ALL_MASK, name, 0))
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__l == 0)
         throw runtime_error("ctype_byname<char>::ctype_byname"
                             " failed to construct for " + string(name));
+#endif
 }
 
 ctype_byname<char>::ctype_byname(const string& name, size_t refs)
     : ctype<char>(0, false, refs),
       __l(newlocale(LC_ALL_MASK, name.c_str(), 0))
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__l == 0)
         throw runtime_error("ctype_byname<char>::ctype_byname"
                             " failed to construct for " + name);
+#endif
 }
 
 ctype_byname<char>::~ctype_byname()
@@ -881,18 +915,22 @@
     : ctype<wchar_t>(refs),
       __l(newlocale(LC_ALL_MASK, name, 0))
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__l == 0)
         throw runtime_error("ctype_byname<wchar_t>::ctype_byname"
                             " failed to construct for " + string(name));
+#endif
 }
 
 ctype_byname<wchar_t>::ctype_byname(const string& name, size_t refs)
     : ctype<wchar_t>(refs),
       __l(newlocale(LC_ALL_MASK, name.c_str(), 0))
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__l == 0)
         throw runtime_error("ctype_byname<wchar_t>::ctype_byname"
                             " failed to construct for " + name);
+#endif
 }
 
 ctype_byname<wchar_t>::~ctype_byname()
@@ -1092,9 +1130,11 @@
     : locale::facet(refs),
       __l(newlocale(LC_ALL_MASK, nm, 0))
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__l == 0)
         throw runtime_error("codecvt_byname<wchar_t, char, mbstate_t>::codecvt_byname"
                             " failed to construct for " + string(nm));
+#endif
 }
 
 codecvt<wchar_t, char, mbstate_t>::~codecvt()
@@ -3832,9 +3872,11 @@
     if (strcmp(nm, "C") != 0)
     {
         unique_ptr<_xlocale, int(*)(locale_t)>  loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
+#ifndef _LIBCPP_NO_EXCEPTIONS
         if (loc == 0)
             throw runtime_error("numpunct_byname<char>::numpunct_byname"
                                 " failed to construct for " + string(nm));
+#endif
         lconv* lc = localeconv_l(loc.get());
         if (*lc->decimal_point)
             __decimal_point_ = *lc->decimal_point;
@@ -3869,9 +3911,11 @@
     if (strcmp(nm, "C") != 0)
     {
         unique_ptr<_xlocale, int(*)(locale_t)>  loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
+#ifndef _LIBCPP_NO_EXCEPTIONS
         if (loc == 0)
             throw runtime_error("numpunct_byname<char>::numpunct_byname"
                                 " failed to construct for " + string(nm));
+#endif
         lconv* lc = localeconv_l(loc.get());
         if (*lc->decimal_point)
             __decimal_point_ = *lc->decimal_point;
@@ -4274,17 +4318,21 @@
 __time_get::__time_get(const char* nm)
     : __loc_(newlocale(LC_ALL_MASK, nm, 0))
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__loc_ == 0)
         throw runtime_error("time_get_byname"
                             " failed to construct for " + string(nm));
+#endif
 }
 
 __time_get::__time_get(const string& nm)
     : __loc_(newlocale(LC_ALL_MASK, nm.c_str(), 0))
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__loc_ == 0)
         throw runtime_error("time_get_byname"
                             " failed to construct for " + nm);
+#endif
 }
 
 __time_get::~__time_get()
@@ -4921,17 +4969,21 @@
 __time_put::__time_put(const char* nm)
     : __loc_(newlocale(LC_ALL_MASK, nm, 0))
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__loc_ == 0)
         throw runtime_error("time_put_byname"
                             " failed to construct for " + string(nm));
+#endif
 }
 
 __time_put::__time_put(const string& nm)
     : __loc_(newlocale(LC_ALL_MASK, nm.c_str(), 0))
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__loc_ == 0)
         throw runtime_error("time_put_byname"
                             " failed to construct for " + nm);
+#endif
 }
 
 __time_put::~__time_put()
@@ -5210,9 +5262,11 @@
 {
     typedef moneypunct<char, false> base;
     unique_ptr<_xlocale, int(*)(locale_t)>  loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (loc == 0)
         throw runtime_error("moneypunct_byname"
                             " failed to construct for " + string(nm));
+#endif
     lconv* lc = localeconv_l(loc.get());
     if (*lc->mon_decimal_point)
         __decimal_point_ = *lc->mon_decimal_point;
@@ -5246,9 +5300,11 @@
 {
     typedef moneypunct<char, true> base;
     unique_ptr<_xlocale, int(*)(locale_t)>  loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (loc == 0)
         throw runtime_error("moneypunct_byname"
                             " failed to construct for " + string(nm));
+#endif
     lconv* lc = localeconv_l(loc.get());
     if (*lc->mon_decimal_point)
         __decimal_point_ = *lc->mon_decimal_point;
@@ -5282,9 +5338,11 @@
 {
     typedef moneypunct<wchar_t, false> base;
     unique_ptr<_xlocale, int(*)(locale_t)>  loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (loc == 0)
         throw runtime_error("moneypunct_byname"
                             " failed to construct for " + string(nm));
+#endif
     lconv* lc = localeconv_l(loc.get());
     if (*lc->mon_decimal_point)
         __decimal_point_ = static_cast<wchar_t>(*lc->mon_decimal_point);
@@ -5341,9 +5399,11 @@
 {
     typedef moneypunct<wchar_t, true> base;
     unique_ptr<_xlocale, int(*)(locale_t)>  loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (loc == 0)
         throw runtime_error("moneypunct_byname"
                             " failed to construct for " + string(nm));
+#endif
     lconv* lc = localeconv_l(loc.get());
     if (*lc->mon_decimal_point)
         __decimal_point_ = static_cast<wchar_t>(*lc->mon_decimal_point);
@@ -5398,7 +5458,9 @@
 
 void __throw_runtime_error(const char* msg)
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     throw runtime_error(msg);
+#endif
 }
 
 template class collate<char>;
diff --git a/src/memory.cpp b/src/memory.cpp
index f35b838..2caa12b 100644
--- a/src/memory.cpp
+++ b/src/memory.cpp
@@ -107,12 +107,16 @@
     return 0;
 }
 
+#ifndef _LIBCPP_NO_RTTI
+
 const void*
 __shared_weak_count::__get_deleter(const type_info&) const
 {
     return 0;
 }
 
+#endif
+
 void
 declare_reachable(void*)
 {
diff --git a/src/mutex.cpp b/src/mutex.cpp
index 1f8160d..fa1e7a0 100644
--- a/src/mutex.cpp
+++ b/src/mutex.cpp
@@ -220,8 +220,10 @@
         pthread_cond_wait(&cv, &mut);
     if (flag == 0)
     {
+#ifndef _LIBCPP_NO_EXCEPTIONS
         try
         {
+#endif
             flag = 1;
             pthread_mutex_unlock(&mut);
             func(arg);
@@ -229,6 +231,7 @@
             flag = ~0ul;
             pthread_mutex_unlock(&mut);
             pthread_cond_broadcast(&cv);
+#ifndef _LIBCPP_NO_EXCEPTIONS
         }
         catch (...)
         {
@@ -238,6 +241,7 @@
             pthread_cond_broadcast(&cv);
             throw;
         }
+#endif
     }
     else
         pthread_mutex_unlock(&mut);
diff --git a/src/new.cpp b/src/new.cpp
index 964d87b..f751f17 100644
--- a/src/new.cpp
+++ b/src/new.cpp
@@ -42,7 +42,11 @@
         if (__new_handler)
             __new_handler();
         else
+#ifndef _LIBCPP_NO_EXCEPTIONS
             throw std::bad_alloc();
+#else
+            break;
+#endif
     }
     return p;
 }
@@ -52,13 +56,17 @@
 operator new(size_t size, const std::nothrow_t&) throw()
 {
     void* p = 0;
+#ifndef _LIBCPP_NO_EXCEPTIONS
     try
     {
+#endif
         p = ::operator new(size);
+#ifndef _LIBCPP_NO_EXCEPTIONS
     }
     catch (...)
     {
     }
+#endif
     return p;
 }
 
@@ -74,13 +82,17 @@
 operator new[](size_t size, const std::nothrow_t& nothrow) throw()
 {
     void* p = 0;
+#ifndef _LIBCPP_NO_EXCEPTIONS
     try
     {
+#endif
         p = ::operator new[](size);
+#ifndef _LIBCPP_NO_EXCEPTIONS
     }
     catch (...)
     {
     }
+#endif
     return p;
 }
 
@@ -162,7 +174,9 @@
 void
 __throw_bad_alloc()
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     throw bad_alloc();
+#endif
 }
 
 }  // std
diff --git a/src/string.cpp b/src/string.cpp
index 819935c..946e915 100644
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -79,9 +79,11 @@
         ptr = const_cast<char*>(p);
     if (ptr == p)
     {
+#ifndef _LIBCPP_NO_EXCEPTIONS
         if (r == 0)
             throw invalid_argument("stoi: no conversion");
         throw out_of_range("stoi: out of range");
+#endif
     }
     if (idx)
         *idx = static_cast<size_t>(ptr - p);
@@ -98,9 +100,11 @@
         ptr = const_cast<wchar_t*>(p);
     if (ptr == p)
     {
+#ifndef _LIBCPP_NO_EXCEPTIONS
         if (r == 0)
             throw invalid_argument("stoi: no conversion");
         throw out_of_range("stoi: out of range");
+#endif
     }
     if (idx)
         *idx = static_cast<size_t>(ptr - p);
@@ -115,9 +119,11 @@
     long r = strtol(p, &ptr, base);
     if (ptr == p)
     {
+#ifndef _LIBCPP_NO_EXCEPTIONS
         if (r == 0)
             throw invalid_argument("stol: no conversion");
         throw out_of_range("stol: out of range");
+#endif
     }
     if (idx)
         *idx = static_cast<size_t>(ptr - p);
@@ -132,9 +138,11 @@
     long r = wcstol(p, &ptr, base);
     if (ptr == p)
     {
+#ifndef _LIBCPP_NO_EXCEPTIONS
         if (r == 0)
             throw invalid_argument("stol: no conversion");
         throw out_of_range("stol: out of range");
+#endif
     }
     if (idx)
         *idx = static_cast<size_t>(ptr - p);
@@ -149,9 +157,11 @@
     unsigned long r = strtoul(p, &ptr, base);
     if (ptr == p)
     {
+#ifndef _LIBCPP_NO_EXCEPTIONS
         if (r == 0)
             throw invalid_argument("stoul: no conversion");
         throw out_of_range("stoul: out of range");
+#endif
     }
     if (idx)
         *idx = static_cast<size_t>(ptr - p);
@@ -166,9 +176,11 @@
     unsigned long r = wcstoul(p, &ptr, base);
     if (ptr == p)
     {
+#ifndef _LIBCPP_NO_EXCEPTIONS
         if (r == 0)
             throw invalid_argument("stoul: no conversion");
         throw out_of_range("stoul: out of range");
+#endif
     }
     if (idx)
         *idx = static_cast<size_t>(ptr - p);
@@ -183,9 +195,11 @@
     long long r = strtoll(p, &ptr, base);
     if (ptr == p)
     {
+#ifndef _LIBCPP_NO_EXCEPTIONS
         if (r == 0)
             throw invalid_argument("stoll: no conversion");
         throw out_of_range("stoll: out of range");
+#endif
     }
     if (idx)
         *idx = static_cast<size_t>(ptr - p);
@@ -200,9 +214,11 @@
     long long r = wcstoll(p, &ptr, base);
     if (ptr == p)
     {
+#ifndef _LIBCPP_NO_EXCEPTIONS
         if (r == 0)
             throw invalid_argument("stoll: no conversion");
         throw out_of_range("stoll: out of range");
+#endif
     }
     if (idx)
         *idx = static_cast<size_t>(ptr - p);
@@ -217,9 +233,11 @@
     unsigned long long r = strtoull(p, &ptr, base);
     if (ptr == p)
     {
+#ifndef _LIBCPP_NO_EXCEPTIONS
         if (r == 0)
             throw invalid_argument("stoull: no conversion");
         throw out_of_range("stoull: out of range");
+#endif
     }
     if (idx)
         *idx = static_cast<size_t>(ptr - p);
@@ -234,9 +252,11 @@
     unsigned long long r = wcstoull(p, &ptr, base);
     if (ptr == p)
     {
+#ifndef _LIBCPP_NO_EXCEPTIONS
         if (r == 0)
             throw invalid_argument("stoull: no conversion");
         throw out_of_range("stoull: out of range");
+#endif
     }
     if (idx)
         *idx = static_cast<size_t>(ptr - p);
@@ -252,10 +272,12 @@
     errno = 0;
     double r = strtod(p, &ptr);
     swap(errno, errno_save);
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (errno_save == ERANGE)
         throw out_of_range("stof: out of range");
     if (ptr == p)
         throw invalid_argument("stof: no conversion");
+#endif
     if (idx)
         *idx = static_cast<size_t>(ptr - p);
     return static_cast<float>(r);
@@ -270,10 +292,12 @@
     errno = 0;
     double r = wcstod(p, &ptr);
     swap(errno, errno_save);
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (errno_save == ERANGE)
         throw out_of_range("stof: out of range");
     if (ptr == p)
         throw invalid_argument("stof: no conversion");
+#endif
     if (idx)
         *idx = static_cast<size_t>(ptr - p);
     return static_cast<float>(r);
@@ -288,10 +312,12 @@
     errno = 0;
     double r = strtod(p, &ptr);
     swap(errno, errno_save);
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (errno_save == ERANGE)
         throw out_of_range("stod: out of range");
     if (ptr == p)
         throw invalid_argument("stod: no conversion");
+#endif
     if (idx)
         *idx = static_cast<size_t>(ptr - p);
     return r;
@@ -306,10 +332,12 @@
     errno = 0;
     double r = wcstod(p, &ptr);
     swap(errno, errno_save);
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (errno_save == ERANGE)
         throw out_of_range("stod: out of range");
     if (ptr == p)
         throw invalid_argument("stod: no conversion");
+#endif
     if (idx)
         *idx = static_cast<size_t>(ptr - p);
     return r;
@@ -324,10 +352,12 @@
     errno = 0;
     long double r = strtold(p, &ptr);
     swap(errno, errno_save);
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (errno_save == ERANGE)
         throw out_of_range("stold: out of range");
     if (ptr == p)
         throw invalid_argument("stold: no conversion");
+#endif
     if (idx)
         *idx = static_cast<size_t>(ptr - p);
     return r;
@@ -342,10 +372,12 @@
     errno = 0;
     long double r = wcstold(p, &ptr);
     swap(errno, errno_save);
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (errno_save == ERANGE)
         throw out_of_range("stold: out of range");
     if (ptr == p)
         throw invalid_argument("stold: no conversion");
+#endif
     if (idx)
         *idx = static_cast<size_t>(ptr - p);
     return r;
diff --git a/src/system_error.cpp b/src/system_error.cpp
index 3c1f000..1ca85cb 100644
--- a/src/system_error.cpp
+++ b/src/system_error.cpp
@@ -193,7 +193,9 @@
 void
 __throw_system_error(int ev, const char* what_arg)
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     throw system_error(error_code(ev, system_category()), what_arg);
+#endif
 }
 
 _LIBCPP_END_NAMESPACE_STD
diff --git a/src/thread.cpp b/src/thread.cpp
index f2db6d5..de53f78 100644
--- a/src/thread.cpp
+++ b/src/thread.cpp
@@ -24,8 +24,10 @@
 thread::join()
 {
     int ec = pthread_join(__t_, 0);
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (ec)
         throw system_error(error_code(ec, system_category()), "thread::join failed");
+#endif
     __t_ = 0;
 }
 
@@ -39,8 +41,10 @@
         if (ec == 0)
             __t_ = 0;
     }
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (ec)
         throw system_error(error_code(ec, system_category()), "thread::detach failed");
+#endif
 }
 
 unsigned