diff options
| author | David Chisnall <theraven@FreeBSD.org> | 2013-02-07 15:45:28 +0000 | 
|---|---|---|
| committer | David Chisnall <theraven@FreeBSD.org> | 2013-02-07 15:45:28 +0000 | 
| commit | cfdf2879c921f2ddcc56acc526e465600607b487 (patch) | |
| tree | 52637438fa031aa783147d9ac30dac90131dffdf /contrib/libc++/src | |
| parent | 45732078c1abbb1fcfeb9eaa54546afca3f0b1a8 (diff) | |
| parent | c7f918d0681828afdbddfdcc354b6f3dfc2a7b68 (diff) | |
Notes
Diffstat (limited to 'contrib/libc++/src')
| -rw-r--r-- | contrib/libc++/src/chrono.cpp | 4 | ||||
| -rw-r--r-- | contrib/libc++/src/debug.cpp | 2 | ||||
| -rw-r--r-- | contrib/libc++/src/exception.cpp | 8 | ||||
| -rw-r--r-- | contrib/libc++/src/future.cpp | 2 | ||||
| -rw-r--r-- | contrib/libc++/src/hash.cpp | 25 | ||||
| -rw-r--r-- | contrib/libc++/src/locale.cpp | 150 | ||||
| -rw-r--r-- | contrib/libc++/src/string.cpp | 136 | ||||
| -rw-r--r-- | contrib/libc++/src/thread.cpp | 6 | 
8 files changed, 200 insertions, 133 deletions
| diff --git a/contrib/libc++/src/chrono.cpp b/contrib/libc++/src/chrono.cpp index 73c83ee084e9..1ce2e2807a37 100644 --- a/contrib/libc++/src/chrono.cpp +++ b/contrib/libc++/src/chrono.cpp @@ -24,6 +24,8 @@ namespace chrono  // system_clock +const bool system_clock::is_steady; +  system_clock::time_point  system_clock::now() _NOEXCEPT  { @@ -46,6 +48,8 @@ system_clock::from_time_t(time_t t) _NOEXCEPT  // steady_clock +const bool steady_clock::is_steady; +  #if __APPLE__  //   mach_absolute_time() * MachInfo.numer / MachInfo.denom is the number of  //   nanoseconds since the computer booted up.  MachInfo.numer and MachInfo.denom diff --git a/contrib/libc++/src/debug.cpp b/contrib/libc++/src/debug.cpp index b8af4dde7749..f3a0262d1d5e 100644 --- a/contrib/libc++/src/debug.cpp +++ b/contrib/libc++/src/debug.cpp @@ -23,7 +23,7 @@ __get_db()  {      static __libcpp_db db;      return &db; -}; +}  _LIBCPP_VISIBLE  const __libcpp_db* diff --git a/contrib/libc++/src/exception.cpp b/contrib/libc++/src/exception.cpp index 0dbb6604a560..0cd182b716cb 100644 --- a/contrib/libc++/src/exception.cpp +++ b/contrib/libc++/src/exception.cpp @@ -33,7 +33,7 @@    #if defined(LIBCXXRT) || defined(_LIBCPPABI_VERSION)      #define HAVE_DEPENDENT_EH_ABI 1    #endif -#else  // __has_include(<cxxabi.h>) +#elif !defined(__GLIBCXX__) // __has_include(<cxxabi.h>)    static std::terminate_handler  __terminate_handler;    static std::unexpected_handler __unexpected_handler;  #endif // __has_include(<cxxabi.h>) @@ -41,7 +41,7 @@  namespace std  { -#if !defined(LIBCXXRT) && !defined(_LIBCPPABI_VERSION) +#if !defined(LIBCXXRT) && !defined(_LIBCPPABI_VERSION) && !defined(__GLIBCXX__)  // libcxxrt provides implementations of these functions itself.  unexpected_handler @@ -99,7 +99,7 @@ terminate() _NOEXCEPT  }  #endif // !defined(LIBCXXRT) && !defined(_LIBCPPABI_VERSION) -#ifndef LIBCXXRT +#if !defined(LIBCXXRT) && !defined(__GLIBCXX__)  bool uncaught_exception() _NOEXCEPT  {  #if __APPLE__ || defined(_LIBCPPABI_VERSION) @@ -124,7 +124,7 @@ const char* exception::what() const _NOEXCEPT  #endif  // _LIBCPPABI_VERSION  #endif //LIBCXXRT -#ifndef _LIBCPPABI_VERSION +#if !defined(_LIBCPPABI_VERSION) && !defined(__GLIBCXX__)  bad_exception::~bad_exception() _NOEXCEPT  { diff --git a/contrib/libc++/src/future.cpp b/contrib/libc++/src/future.cpp index feb37e42db4e..7d9a5b5da69a 100644 --- a/contrib/libc++/src/future.cpp +++ b/contrib/libc++/src/future.cpp @@ -78,8 +78,8 @@ __assoc_sub_state::set_value()          throw future_error(make_error_code(future_errc::promise_already_satisfied));  #endif      __state_ |= __constructed | ready; -    __lk.unlock();      __cv_.notify_all(); +    __lk.unlock();  }  void diff --git a/contrib/libc++/src/hash.cpp b/contrib/libc++/src/hash.cpp index 6f30d5a60581..55874788db5c 100644 --- a/contrib/libc++/src/hash.cpp +++ b/contrib/libc++/src/hash.cpp @@ -10,6 +10,14 @@  #include "__hash_table"  #include "algorithm"  #include "stdexcept" +#include "type_traits" + +// Don't silence a non-existent warning if clang doesn't yet have this warning. +#ifdef __clang__ +#if (__clang_major__ > 3) || ((__clang_major__ == 3) && (__clang_minor__ >= 2)) +#pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare" +#endif +#endif  _LIBCPP_BEGIN_NAMESPACE_STD @@ -144,21 +152,23 @@ const unsigned indices[] =  // are fewer potential primes to search, and fewer potential primes to divide  // against. +template <size_t _Sz = sizeof(size_t)>  inline _LIBCPP_INLINE_VISIBILITY -void -__check_for_overflow(size_t N, integral_constant<size_t, 32>) +typename enable_if<_Sz == 4, void>::type +__check_for_overflow(size_t N)  { -#ifndef _LIBCPP_NO_EXCEPTIONS  +#ifndef _LIBCPP_NO_EXCEPTIONS      if (N > 0xFFFFFFFB)          throw overflow_error("__next_prime overflow");  #endif  } +template <size_t _Sz = sizeof(size_t)>  inline _LIBCPP_INLINE_VISIBILITY -void -__check_for_overflow(size_t N, integral_constant<size_t, 64>) +typename enable_if<_Sz == 8, void>::type +__check_for_overflow(size_t N)  { -#ifndef _LIBCPP_NO_EXCEPTIONS  +#ifndef _LIBCPP_NO_EXCEPTIONS      if (N > 0xFFFFFFFFFFFFFFC5ull)          throw overflow_error("__next_prime overflow");  #endif @@ -174,8 +184,7 @@ __next_prime(size_t n)          return *std::lower_bound(small_primes, small_primes + N, n);      // Else n > largest small_primes      // Check for overflow -    __check_for_overflow(n, integral_constant<size_t,  -                                                   sizeof(n) * __CHAR_BIT__>()); +    __check_for_overflow(n);      // Start searching list of potential primes: L * k0 + indices[in]      const size_t M = sizeof(indices) / sizeof(indices[0]);      // Select first potential prime >= n diff --git a/contrib/libc++/src/locale.cpp b/contrib/libc++/src/locale.cpp index 542c0d7a20ff..53a8a4cc1f08 100644 --- a/contrib/libc++/src/locale.cpp +++ b/contrib/libc++/src/locale.cpp @@ -81,8 +81,35 @@ make(A0 a0, A1 a1, A2 a2)      return *(T*)&buf;  } +template <typename T, size_t N> +inline +_LIBCPP_CONSTEXPR +size_t +countof(const T (&)[N]) +{ +    return N; +} + +template <typename T> +inline +_LIBCPP_CONSTEXPR +size_t +countof(const T * const begin, const T * const end) +{ +    return static_cast<size_t>(end - begin); +} +  } +const locale::category locale::none; +const locale::category locale::collate; +const locale::category locale::ctype; +const locale::category locale::monetary; +const locale::category locale::numeric; +const locale::category locale::time; +const locale::category locale::messages; +const locale::category locale::all; +  #pragma clang diagnostic push  #pragma clang diagnostic ignored "-Wpadded" @@ -197,6 +224,11 @@ locale::__imp::__imp(const string& name, size_t refs)  #endif  // _LIBCPP_NO_EXCEPTIONS  } +// NOTE avoid the `base class should be explicitly initialized in the +// copy constructor` warning emitted by GCC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wextra" +  locale::__imp::__imp(const __imp& other)      : facets_(max<size_t>(N, other.facets_.size())),        name_(other.name_) @@ -207,6 +239,8 @@ locale::__imp::__imp(const __imp& other)              facets_[i]->__add_shared();  } +#pragma GCC diagnostic pop +  locale::__imp::__imp(const __imp& other, const string& name, locale::category c)      : facets_(N),        name_("*") @@ -691,6 +725,19 @@ collate_byname<wchar_t>::do_transform(const char_type* lo, const char_type* hi)  // template <> class ctype<wchar_t>; +const ctype_base::mask ctype_base::space; +const ctype_base::mask ctype_base::print; +const ctype_base::mask ctype_base::cntrl; +const ctype_base::mask ctype_base::upper; +const ctype_base::mask ctype_base::lower; +const ctype_base::mask ctype_base::alpha; +const ctype_base::mask ctype_base::digit; +const ctype_base::mask ctype_base::punct; +const ctype_base::mask ctype_base::xdigit; +const ctype_base::mask ctype_base::blank; +const ctype_base::mask ctype_base::alnum; +const ctype_base::mask ctype_base::graph; +      locale::id ctype<wchar_t>::id;  ctype<wchar_t>::~ctype() @@ -843,7 +890,7 @@ ctype<char>::do_toupper(char_type c) const      return isascii(c) ?        static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(c)]) : c;  #elif defined(__GLIBC__) -    return isascii(c) ? __classic_upper_table()[c] : c; +    return isascii(c) ? __classic_upper_table()[static_cast<size_t>(c)] : c;  #else      return (isascii(c) && islower_l(c, __cloc())) ? c-'a'+'A' : c;  #endif @@ -857,7 +904,7 @@ ctype<char>::do_toupper(char_type* low, const char_type* high) const          *low = isascii(*low) ?            static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(*low)]) : *low;  #elif defined(__GLIBC__) -        *low = isascii(*low) ? __classic_upper_table()[*low] : *low; +        *low = isascii(*low) ? __classic_upper_table()[static_cast<size_t>(*low)] : *low;  #else          *low = (isascii(*low) && islower_l(*low, __cloc())) ? *low-'a'+'A' : *low;  #endif @@ -871,7 +918,7 @@ ctype<char>::do_tolower(char_type c) const      return isascii(c) ?        static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(c)]) : c;  #elif defined(__GLIBC__) -    return isascii(c) ? __classic_lower_table()[c] : c; +    return isascii(c) ? __classic_lower_table()[static_cast<size_t>(c)] : c;  #else      return (isascii(c) && isupper_l(c, __cloc())) ? c-'A'+'a' : c;  #endif @@ -884,7 +931,7 @@ ctype<char>::do_tolower(char_type* low, const char_type* high) const  #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE          *low = isascii(*low) ? static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(*low)]) : *low;  #elif defined(__GLIBC__) -        *low = isascii(*low) ? __classic_lower_table()[*low] : *low; +        *low = isascii(*low) ? __classic_lower_table()[static_cast<size_t>(*low)] : *low;  #else          *low = (isascii(*low) && isupper_l(*low, __cloc())) ? *low-'A'+'a' : *low;  #endif @@ -1207,7 +1254,7 @@ ctype_byname<wchar_t>::do_narrow(char_type c, char dfault) const  #else      int r = __wctob_l(c, __l);  #endif -    return r != WEOF ? static_cast<char>(r) : dfault; +    return r != static_cast<int>(WEOF) ? static_cast<char>(r) : dfault;  }  const wchar_t* @@ -1220,7 +1267,7 @@ ctype_byname<wchar_t>::do_narrow(const char_type* low, const char_type* high, ch  #else          int r = __wctob_l(*low, __l);  #endif -        *dest = r != WEOF ? static_cast<char>(r) : dfault; +        *dest = r != static_cast<int>(WEOF) ? static_cast<char>(r) : dfault;      }      return low;  } @@ -2619,7 +2666,6 @@ utf16be_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,                         codecvt_mode mode = codecvt_mode(0))  {      const uint8_t* frm_nxt = frm; -    frm_nxt = frm;      if (mode & consume_header)      {          if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF) @@ -2752,7 +2798,6 @@ utf16le_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,                         codecvt_mode mode = codecvt_mode(0))  {      const uint8_t* frm_nxt = frm; -    frm_nxt = frm;      if (mode & consume_header)      {          if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE) @@ -2847,7 +2892,6 @@ utf16be_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,                         codecvt_mode mode = codecvt_mode(0))  {      const uint8_t* frm_nxt = frm; -    frm_nxt = frm;      if (mode & consume_header)      {          if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF) @@ -4559,6 +4603,7 @@ __time_get::~__time_get()  }  #pragma clang diagnostic ignored "-Wmissing-field-initializers" +#pragma GCC   diagnostic ignored "-Wmissing-field-initializers"  template <>  string @@ -4578,7 +4623,7 @@ __time_get_storage<char>::__analyze(char fmt, const ctype<char>& ct)      char f[3] = {0};      f[0] = '%';      f[1] = fmt; -    size_t n = strftime_l(buf, 100, f, &t, __loc_); +    size_t n = strftime_l(buf, countof(buf), f, &t, __loc_);      char* bb = buf;      char* be = buf + n;      string result; @@ -4724,15 +4769,15 @@ __time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct)      char f[3] = {0};      f[0] = '%';      f[1] = fmt; -    strftime_l(buf, 100, f, &t, __loc_); +    strftime_l(buf, countof(buf), f, &t, __loc_);      wchar_t wbuf[100];      wchar_t* wbb = wbuf;      mbstate_t mb = {0};      const char* bb = buf;  #ifdef _LIBCPP_LOCALE__L_EXTENSIONS -    size_t j = mbsrtowcs_l( wbb, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_); +    size_t j = mbsrtowcs_l( wbb, &bb, countof(wbuf), &mb, __loc_);  #else -    size_t j = __mbsrtowcs_l( wbb, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_); +    size_t j = __mbsrtowcs_l( wbb, &bb, countof(wbuf), &mb, __loc_);  #endif      if (j == size_t(-1))          __throw_runtime_error("locale not supported"); @@ -4870,26 +4915,26 @@ __time_get_storage<char>::init(const ctype<char>& ct)      for (int i = 0; i < 7; ++i)      {          t.tm_wday = i; -        strftime_l(buf, 100, "%A", &t, __loc_); +        strftime_l(buf, countof(buf), "%A", &t, __loc_);          __weeks_[i] = buf; -        strftime_l(buf, 100, "%a", &t, __loc_); +        strftime_l(buf, countof(buf), "%a", &t, __loc_);          __weeks_[i+7] = buf;      }      // __months_      for (int i = 0; i < 12; ++i)      {          t.tm_mon = i; -        strftime_l(buf, 100, "%B", &t, __loc_); +        strftime_l(buf, countof(buf), "%B", &t, __loc_);          __months_[i] = buf; -        strftime_l(buf, 100, "%b", &t, __loc_); +        strftime_l(buf, countof(buf), "%b", &t, __loc_);          __months_[i+12] = buf;      }      // __am_pm_      t.tm_hour = 1; -    strftime_l(buf, 100, "%p", &t, __loc_); +    strftime_l(buf, countof(buf), "%p", &t, __loc_);      __am_pm_[0] = buf;      t.tm_hour = 13; -    strftime_l(buf, 100, "%p", &t, __loc_); +    strftime_l(buf, countof(buf), "%p", &t, __loc_);      __am_pm_[1] = buf;      __c_ = __analyze('c', ct);      __r_ = __analyze('r', ct); @@ -4903,7 +4948,6 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)  {      tm t = {0};      char buf[100]; -    size_t be;      wchar_t wbuf[100];      wchar_t* wbe;      mbstate_t mb = {0}; @@ -4911,25 +4955,25 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)      for (int i = 0; i < 7; ++i)      {          t.tm_wday = i; -        be = strftime_l(buf, 100, "%A", &t, __loc_); +        strftime_l(buf, countof(buf), "%A", &t, __loc_);          mb = mbstate_t();          const char* bb = buf;  #ifdef _LIBCPP_LOCALE__L_EXTENSIONS -        size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_); +        size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);  #else -        size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_); +        size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);  #endif          if (j == size_t(-1))              __throw_runtime_error("locale not supported");          wbe = wbuf + j;          __weeks_[i].assign(wbuf, wbe); -        be = strftime_l(buf, 100, "%a", &t, __loc_); +        strftime_l(buf, countof(buf), "%a", &t, __loc_);          mb = mbstate_t();          bb = buf;  #ifdef _LIBCPP_LOCALE__L_EXTENSIONS -        j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_); +        j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);  #else -        j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_); +        j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);  #endif          if (j == size_t(-1))              __throw_runtime_error("locale not supported"); @@ -4940,25 +4984,25 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)      for (int i = 0; i < 12; ++i)      {          t.tm_mon = i; -        be = strftime_l(buf, 100, "%B", &t, __loc_); +        strftime_l(buf, countof(buf), "%B", &t, __loc_);          mb = mbstate_t();          const char* bb = buf;  #ifdef _LIBCPP_LOCALE__L_EXTENSIONS -        size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_); +        size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);  #else -        size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_); +        size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);  #endif          if (j == size_t(-1))              __throw_runtime_error("locale not supported");          wbe = wbuf + j;          __months_[i].assign(wbuf, wbe); -        be = strftime_l(buf, 100, "%b", &t, __loc_); +        strftime_l(buf, countof(buf), "%b", &t, __loc_);          mb = mbstate_t();          bb = buf;  #ifdef _LIBCPP_LOCALE__L_EXTENSIONS -        j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_); +        j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);  #else -        j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_); +        j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);  #endif          if (j == size_t(-1))              __throw_runtime_error("locale not supported"); @@ -4967,26 +5011,26 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)      }      // __am_pm_      t.tm_hour = 1; -    be = strftime_l(buf, 100, "%p", &t, __loc_); +    strftime_l(buf, countof(buf), "%p", &t, __loc_);      mb = mbstate_t();      const char* bb = buf;  #ifdef _LIBCPP_LOCALE__L_EXTENSIONS -    size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_); +    size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);  #else -    size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_); +    size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);  #endif      if (j == size_t(-1))          __throw_runtime_error("locale not supported");      wbe = wbuf + j;      __am_pm_[0].assign(wbuf, wbe);      t.tm_hour = 13; -    be = strftime_l(buf, 100, "%p", &t, __loc_); +    strftime_l(buf, countof(buf), "%p", &t, __loc_);      mb = mbstate_t();      bb = buf;  #ifdef _LIBCPP_LOCALE__L_EXTENSIONS -    j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_); +    j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);  #else -    j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_); +    j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);  #endif      if (j == size_t(-1))          __throw_runtime_error("locale not supported"); @@ -5249,7 +5293,7 @@ __time_put::__do_put(char* __nb, char*& __ne, const tm* __tm,      char fmt[] = {'%', __fmt, __mod, 0};      if (__mod != 0)          swap(fmt[1], fmt[2]); -    size_t n = strftime_l(__nb, static_cast<size_t>(__ne-__nb), fmt, __tm, __loc_); +    size_t n = strftime_l(__nb, countof(__nb, __ne), fmt, __tm, __loc_);      __ne = __nb + n;  } @@ -5263,9 +5307,9 @@ __time_put::__do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm,      mbstate_t mb = {0};      const char* __nb = __nar;  #ifdef _LIBCPP_LOCALE__L_EXTENSIONS -    size_t j = mbsrtowcs_l(__wb, &__nb, 100, &mb, __loc_); +    size_t j = mbsrtowcs_l(__wb, &__nb, countof(__wb, __we), &mb, __loc_);  #else -    size_t j = __mbsrtowcs_l(__wb, &__nb, 100, &mb, __loc_); +    size_t j = __mbsrtowcs_l(__wb, &__nb, countof(__wb, __we), &mb, __loc_);  #endif      if (j == size_t(-1))          __throw_runtime_error("locale not supported"); @@ -5788,9 +5832,9 @@ moneypunct_byname<wchar_t, false>::init(const char* nm)      mbstate_t mb = {0};      const char* bb = lc->currency_symbol;  #ifdef _LIBCPP_LOCALE__L_EXTENSIONS -    size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get()); +    size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());  #else -    size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get()); +    size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());  #endif      if (j == size_t(-1))          __throw_runtime_error("locale not supported"); @@ -5807,9 +5851,9 @@ moneypunct_byname<wchar_t, false>::init(const char* nm)          mb = mbstate_t();          bb = lc->positive_sign;  #ifdef _LIBCPP_LOCALE__L_EXTENSIONS -        j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get()); +        j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());  #else -        j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get()); +        j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());  #endif          if (j == size_t(-1))              __throw_runtime_error("locale not supported"); @@ -5823,9 +5867,9 @@ moneypunct_byname<wchar_t, false>::init(const char* nm)          mb = mbstate_t();          bb = lc->negative_sign;  #ifdef _LIBCPP_LOCALE__L_EXTENSIONS -        j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get()); +        j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());  #else -        j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get()); +        j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());  #endif          if (j == size_t(-1))              __throw_runtime_error("locale not supported"); @@ -5871,9 +5915,9 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)      mbstate_t mb = {0};      const char* bb = lc->int_curr_symbol;  #ifdef _LIBCPP_LOCALE__L_EXTENSIONS -    size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get()); +    size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());  #else -    size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get()); +    size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());  #endif      if (j == size_t(-1))          __throw_runtime_error("locale not supported"); @@ -5894,9 +5938,9 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)          mb = mbstate_t();          bb = lc->positive_sign;  #ifdef _LIBCPP_LOCALE__L_EXTENSIONS -        j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get()); +        j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());  #else -        j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get()); +        j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());  #endif          if (j == size_t(-1))              __throw_runtime_error("locale not supported"); @@ -5914,9 +5958,9 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)          mb = mbstate_t();          bb = lc->negative_sign;  #ifdef _LIBCPP_LOCALE__L_EXTENSIONS -        j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get()); +        j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());  #else -        j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get()); +        j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());  #endif          if (j == size_t(-1))              __throw_runtime_error("locale not supported"); diff --git a/contrib/libc++/src/string.cpp b/contrib/libc++/src/string.cpp index 750ba284e366..40723e74a156 100644 --- a/contrib/libc++/src/string.cpp +++ b/contrib/libc++/src/string.cpp @@ -31,17 +31,17 @@ stoi(const string& str, size_t* idx, int base)  {      char* ptr;      const char* const p = str.c_str(); +    typename remove_reference<decltype(errno)>::type errno_save = errno; +    errno = 0;      long r = strtol(p, &ptr, base); -    if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r) -        ptr = const_cast<char*>(p); -    if (ptr == p) -    { +    swap(errno, errno_save);  #ifndef _LIBCPP_NO_EXCEPTIONS -        if (r == 0) -            throw invalid_argument("stoi: no conversion"); +    if (errno_save == ERANGE || r < numeric_limits<int>::min() || +                                numeric_limits<int>::max() < r)          throw out_of_range("stoi: out of range"); +    if (ptr == p) +        throw invalid_argument("stoi: no conversion");  #endif  // _LIBCPP_NO_EXCEPTIONS -    }      if (idx)          *idx = static_cast<size_t>(ptr - p);      return static_cast<int>(r); @@ -52,17 +52,17 @@ stoi(const wstring& str, size_t* idx, int base)  {      wchar_t* ptr;      const wchar_t* const p = str.c_str(); +    typename remove_reference<decltype(errno)>::type errno_save = errno; +    errno = 0;      long r = wcstol(p, &ptr, base); -    if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r) -        ptr = const_cast<wchar_t*>(p); -    if (ptr == p) -    { +    swap(errno, errno_save);  #ifndef _LIBCPP_NO_EXCEPTIONS -        if (r == 0) -            throw invalid_argument("stoi: no conversion"); +    if (errno_save == ERANGE || r < numeric_limits<int>::min() || +                                numeric_limits<int>::max() < r)          throw out_of_range("stoi: out of range"); +    if (ptr == p) +        throw invalid_argument("stoi: no conversion");  #endif  // _LIBCPP_NO_EXCEPTIONS -    }      if (idx)          *idx = static_cast<size_t>(ptr - p);      return static_cast<int>(r); @@ -73,15 +73,16 @@ stol(const string& str, size_t* idx, int base)  {      char* ptr;      const char* const p = str.c_str(); +    typename remove_reference<decltype(errno)>::type errno_save = errno; +    errno = 0;      long r = strtol(p, &ptr, base); -    if (ptr == p) -    { +    swap(errno, errno_save);  #ifndef _LIBCPP_NO_EXCEPTIONS -        if (r == 0) -            throw invalid_argument("stol: no conversion"); +    if (errno_save == ERANGE)          throw out_of_range("stol: out of range"); +    if (ptr == p) +        throw invalid_argument("stol: no conversion");  #endif  // _LIBCPP_NO_EXCEPTIONS -    }      if (idx)          *idx = static_cast<size_t>(ptr - p);      return r; @@ -92,15 +93,16 @@ stol(const wstring& str, size_t* idx, int base)  {      wchar_t* ptr;      const wchar_t* const p = str.c_str(); +    typename remove_reference<decltype(errno)>::type errno_save = errno; +    errno = 0;      long r = wcstol(p, &ptr, base); -    if (ptr == p) -    { +    swap(errno, errno_save);  #ifndef _LIBCPP_NO_EXCEPTIONS -        if (r == 0) -            throw invalid_argument("stol: no conversion"); +    if (errno_save == ERANGE)          throw out_of_range("stol: out of range"); +    if (ptr == p) +        throw invalid_argument("stol: no conversion");  #endif  // _LIBCPP_NO_EXCEPTIONS -    }      if (idx)          *idx = static_cast<size_t>(ptr - p);      return r; @@ -111,15 +113,16 @@ stoul(const string& str, size_t* idx, int base)  {      char* ptr;      const char* const p = str.c_str(); +    typename remove_reference<decltype(errno)>::type errno_save = errno; +    errno = 0;      unsigned long r = strtoul(p, &ptr, base); -    if (ptr == p) -    { +    swap(errno, errno_save);  #ifndef _LIBCPP_NO_EXCEPTIONS -        if (r == 0) -            throw invalid_argument("stoul: no conversion"); +    if (errno_save == ERANGE)          throw out_of_range("stoul: out of range"); +    if (ptr == p) +        throw invalid_argument("stoul: no conversion");  #endif  // _LIBCPP_NO_EXCEPTIONS -    }      if (idx)          *idx = static_cast<size_t>(ptr - p);      return r; @@ -130,15 +133,16 @@ stoul(const wstring& str, size_t* idx, int base)  {      wchar_t* ptr;      const wchar_t* const p = str.c_str(); +    typename remove_reference<decltype(errno)>::type errno_save = errno; +    errno = 0;      unsigned long r = wcstoul(p, &ptr, base); -    if (ptr == p) -    { +    swap(errno, errno_save);  #ifndef _LIBCPP_NO_EXCEPTIONS -        if (r == 0) -            throw invalid_argument("stoul: no conversion"); +    if (errno_save == ERANGE)          throw out_of_range("stoul: out of range"); +    if (ptr == p) +        throw invalid_argument("stoul: no conversion");  #endif  // _LIBCPP_NO_EXCEPTIONS -    }      if (idx)          *idx = static_cast<size_t>(ptr - p);      return r; @@ -149,15 +153,16 @@ stoll(const string& str, size_t* idx, int base)  {      char* ptr;      const char* const p = str.c_str(); +    typename remove_reference<decltype(errno)>::type errno_save = errno; +    errno = 0;      long long r = strtoll(p, &ptr, base); -    if (ptr == p) -    { +    swap(errno, errno_save);  #ifndef _LIBCPP_NO_EXCEPTIONS -        if (r == 0) -            throw invalid_argument("stoll: no conversion"); +    if (errno_save == ERANGE)          throw out_of_range("stoll: out of range"); +    if (ptr == p) +        throw invalid_argument("stoll: no conversion");  #endif  // _LIBCPP_NO_EXCEPTIONS -    }      if (idx)          *idx = static_cast<size_t>(ptr - p);      return r; @@ -168,15 +173,16 @@ stoll(const wstring& str, size_t* idx, int base)  {      wchar_t* ptr;      const wchar_t* const p = str.c_str(); +    typename remove_reference<decltype(errno)>::type errno_save = errno; +    errno = 0;      long long r = wcstoll(p, &ptr, base); -    if (ptr == p) -    { +    swap(errno, errno_save);  #ifndef _LIBCPP_NO_EXCEPTIONS -        if (r == 0) -            throw invalid_argument("stoll: no conversion"); +    if (errno_save == ERANGE)          throw out_of_range("stoll: out of range"); +    if (ptr == p) +        throw invalid_argument("stoll: no conversion");  #endif  // _LIBCPP_NO_EXCEPTIONS -    }      if (idx)          *idx = static_cast<size_t>(ptr - p);      return r; @@ -187,15 +193,16 @@ stoull(const string& str, size_t* idx, int base)  {      char* ptr;      const char* const p = str.c_str(); +    typename remove_reference<decltype(errno)>::type errno_save = errno; +    errno = 0;      unsigned long long r = strtoull(p, &ptr, base); -    if (ptr == p) -    { +    swap(errno, errno_save);  #ifndef _LIBCPP_NO_EXCEPTIONS -        if (r == 0) -            throw invalid_argument("stoull: no conversion"); +    if (errno_save == ERANGE)          throw out_of_range("stoull: out of range"); +    if (ptr == p) +        throw invalid_argument("stoull: no conversion");  #endif  // _LIBCPP_NO_EXCEPTIONS -    }      if (idx)          *idx = static_cast<size_t>(ptr - p);      return r; @@ -206,15 +213,16 @@ stoull(const wstring& str, size_t* idx, int base)  {      wchar_t* ptr;      const wchar_t* const p = str.c_str(); +    typename remove_reference<decltype(errno)>::type errno_save = errno; +    errno = 0;      unsigned long long r = wcstoull(p, &ptr, base); -    if (ptr == p) -    { +    swap(errno, errno_save);  #ifndef _LIBCPP_NO_EXCEPTIONS -        if (r == 0) -            throw invalid_argument("stoull: no conversion"); +    if (errno_save == ERANGE)          throw out_of_range("stoull: out of range"); +    if (ptr == p) +        throw invalid_argument("stoull: no conversion");  #endif  // _LIBCPP_NO_EXCEPTIONS -    }      if (idx)          *idx = static_cast<size_t>(ptr - p);      return r; @@ -225,9 +233,9 @@ stof(const string& str, size_t* idx)  {      char* ptr;      const char* const p = str.c_str(); -    int errno_save = errno; +    typename remove_reference<decltype(errno)>::type errno_save = errno;      errno = 0; -    double r = strtod(p, &ptr); +    float r = strtof(p, &ptr);      swap(errno, errno_save);  #ifndef _LIBCPP_NO_EXCEPTIONS      if (errno_save == ERANGE) @@ -237,7 +245,7 @@ stof(const string& str, size_t* idx)  #endif  // _LIBCPP_NO_EXCEPTIONS      if (idx)          *idx = static_cast<size_t>(ptr - p); -    return static_cast<float>(r); +    return r;  }  float @@ -245,9 +253,9 @@ stof(const wstring& str, size_t* idx)  {      wchar_t* ptr;      const wchar_t* const p = str.c_str(); -    int errno_save = errno; +    typename remove_reference<decltype(errno)>::type errno_save = errno;      errno = 0; -    double r = wcstod(p, &ptr); +    float r = wcstof(p, &ptr);      swap(errno, errno_save);  #ifndef _LIBCPP_NO_EXCEPTIONS      if (errno_save == ERANGE) @@ -257,7 +265,7 @@ stof(const wstring& str, size_t* idx)  #endif  // _LIBCPP_NO_EXCEPTIONS      if (idx)          *idx = static_cast<size_t>(ptr - p); -    return static_cast<float>(r); +    return r;  }  double @@ -265,7 +273,7 @@ stod(const string& str, size_t* idx)  {      char* ptr;      const char* const p = str.c_str(); -    int errno_save = errno; +    typename remove_reference<decltype(errno)>::type errno_save = errno;      errno = 0;      double r = strtod(p, &ptr);      swap(errno, errno_save); @@ -285,7 +293,7 @@ stod(const wstring& str, size_t* idx)  {      wchar_t* ptr;      const wchar_t* const p = str.c_str(); -    int errno_save = errno; +    typename remove_reference<decltype(errno)>::type errno_save = errno;      errno = 0;      double r = wcstod(p, &ptr);      swap(errno, errno_save); @@ -305,7 +313,7 @@ stold(const string& str, size_t* idx)  {      char* ptr;      const char* const p = str.c_str(); -    int errno_save = errno; +    typename remove_reference<decltype(errno)>::type errno_save = errno;      errno = 0;      long double r = strtold(p, &ptr);      swap(errno, errno_save); @@ -325,7 +333,7 @@ stold(const wstring& str, size_t* idx)  {      wchar_t* ptr;      const wchar_t* const p = str.c_str(); -    int errno_save = errno; +    typename remove_reference<decltype(errno)>::type errno_save = errno;      errno = 0;      long double r = wcstold(p, &ptr);      swap(errno, errno_save); diff --git a/contrib/libc++/src/thread.cpp b/contrib/libc++/src/thread.cpp index 8747adf0b595..b2bd07e9d3ba 100644 --- a/contrib/libc++/src/thread.cpp +++ b/contrib/libc++/src/thread.cpp @@ -67,8 +67,10 @@ thread::hardware_concurrency() _NOEXCEPT      return n;  #elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) && defined(_SC_NPROCESSORS_ONLN)      long result = sysconf(_SC_NPROCESSORS_ONLN); -    if (result < 0 || result > UINT_MAX) -        result = 0; +    // sysconf returns -1 if the name is invalid, the option does not exist or +    // does not have a definite limit. +    if (result == -1) +        return 0;      return result;  #else  // defined(CTL_HW) && defined(HW_NCPU)      // TODO: grovel through /proc or check cpuid on x86 and similar | 
