aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Chisnall <theraven@FreeBSD.org>2012-03-13 14:09:15 +0000
committerDavid Chisnall <theraven@FreeBSD.org>2012-03-13 14:09:15 +0000
commit362d815b81e2b4b66c33b99203d821b8928607e1 (patch)
tree491848d33dbdf1751fd52f321d3fbf70a8e616f2 /src
parent1828c5696f7bf5850943ea6c660a493a5e648669 (diff)
downloadsrc-362d815b81e2b4b66c33b99203d821b8928607e1.tar.gz
src-362d815b81e2b4b66c33b99203d821b8928607e1.zip
Import new version of libc++ into vendor branch.vendor/libc++/r152501
Approved by: dim (mentor)
Notes
Notes: svn path=/vendor/libc++/dist/; revision=232924 svn path=/vendor/libc++/r152501/; revision=232925; tag=vendor/libc++/r152501
Diffstat (limited to 'src')
-rw-r--r--src/chrono.cpp2
-rw-r--r--src/condition_variable.cpp3
-rw-r--r--src/debug.cpp34
-rw-r--r--src/exception.cpp73
-rw-r--r--src/future.cpp6
-rw-r--r--src/hash.cpp3
-rw-r--r--src/locale.cpp584
-rw-r--r--src/memory.cpp5
-rw-r--r--src/mutex.cpp3
-rw-r--r--src/new.cpp24
-rw-r--r--src/random.cpp3
-rw-r--r--src/regex.cpp10
-rw-r--r--src/stdexcept.cpp9
-rw-r--r--src/string.cpp36
-rw-r--r--src/strstream.cpp8
-rw-r--r--src/thread.cpp4
-rw-r--r--src/typeinfo.cpp3
17 files changed, 522 insertions, 288 deletions
diff --git a/src/chrono.cpp b/src/chrono.cpp
index 416b95013ef2..73c83ee084e9 100644
--- a/src/chrono.cpp
+++ b/src/chrono.cpp
@@ -61,7 +61,7 @@ static
steady_clock::rep
steady_simplified()
{
- return mach_absolute_time();
+ return static_cast<steady_clock::rep>(mach_absolute_time());
}
static
diff --git a/src/condition_variable.cpp b/src/condition_variable.cpp
index ca1dca3280e9..b53b836bfe7f 100644
--- a/src/condition_variable.cpp
+++ b/src/condition_variable.cpp
@@ -16,8 +16,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
condition_variable::~condition_variable()
{
- int e = pthread_cond_destroy(&__cv_);
-// assert(e == 0);
+ pthread_cond_destroy(&__cv_);
}
void
diff --git a/src/debug.cpp b/src/debug.cpp
index 8b660f5f39ab..406b247b7fec 100644
--- a/src/debug.cpp
+++ b/src/debug.cpp
@@ -125,7 +125,7 @@ __libcpp_db::__insert_ic(void* __i, const void* __c)
" But it is being used in a translation unit with debug mode enabled."
" Enable it in the other translation unit with #define _LIBCPP_DEBUG2 1";
_LIBCPP_ASSERT(__cbeg_ != __cend_, errmsg);
- size_t hc = hash<const void*>()(__c) % (__cend_ - __cbeg_);
+ size_t hc = hash<const void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
__c_node* c = __cbeg_[hc];
_LIBCPP_ASSERT(c != nullptr, errmsg);
while (c->__c_ != __c)
@@ -141,9 +141,9 @@ __c_node*
__libcpp_db::__insert_c(void* __c)
{
WLock _(mut());
- if (__csz_ + 1 > __cend_ - __cbeg_)
+ if (__csz_ + 1 > static_cast<size_t>(__cend_ - __cbeg_))
{
- size_t nc = __next_prime(2*(__cend_ - __cbeg_) + 1);
+ size_t nc = __next_prime(2*static_cast<size_t>(__cend_ - __cbeg_) + 1);
__c_node** cbeg = (__c_node**)calloc(nc, sizeof(void*));
if (cbeg == nullptr)
throw bad_alloc();
@@ -163,7 +163,7 @@ __libcpp_db::__insert_c(void* __c)
__cbeg_ = cbeg;
__cend_ = __cbeg_ + nc;
}
- size_t hc = hash<void*>()(__c) % (__cend_ - __cbeg_);
+ size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
__c_node* p = __cbeg_[hc];
__c_node* r = __cbeg_[hc] = (__c_node*)malloc(sizeof(__c_node));
if (__cbeg_[hc] == nullptr)
@@ -180,7 +180,7 @@ __libcpp_db::__erase_i(void* __i)
WLock _(mut());
if (__ibeg_ != __iend_)
{
- size_t hi = hash<void*>()(__i) % (__iend_ - __ibeg_);
+ size_t hi = hash<void*>()(__i) % static_cast<size_t>(__iend_ - __ibeg_);
__i_node* p = __ibeg_[hi];
if (p != nullptr)
{
@@ -209,7 +209,7 @@ void
__libcpp_db::__invalidate_all(void* __c)
{
WLock _(mut());
- size_t hc = hash<void*>()(__c) % (__cend_ - __cbeg_);
+ size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
__c_node* p = __cbeg_[hc];
_LIBCPP_ASSERT(p != nullptr, "debug mode internal logic error __invalidate_all A");
while (p->__c_ != __c)
@@ -228,7 +228,7 @@ __c_node*
__libcpp_db::__find_c_and_lock(void* __c) const
{
mut().lock();
- size_t hc = hash<void*>()(__c) % (__cend_ - __cbeg_);
+ size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
__c_node* p = __cbeg_[hc];
_LIBCPP_ASSERT(p != nullptr, "debug mode internal logic error __find_c_and_lock A");
while (p->__c_ != __c)
@@ -242,7 +242,7 @@ __libcpp_db::__find_c_and_lock(void* __c) const
__c_node*
__libcpp_db::__find_c(void* __c) const
{
- size_t hc = hash<void*>()(__c) % (__cend_ - __cbeg_);
+ size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
__c_node* p = __cbeg_[hc];
_LIBCPP_ASSERT(p != nullptr, "debug mode internal logic error __find_c A");
while (p->__c_ != __c)
@@ -263,7 +263,7 @@ void
__libcpp_db::__erase_c(void* __c)
{
WLock _(mut());
- size_t hc = hash<void*>()(__c) % (__cend_ - __cbeg_);
+ size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
__c_node* p = __cbeg_[hc];
__c_node* q = nullptr;
_LIBCPP_ASSERT(p != nullptr, "debug mode internal logic error __erase_c A");
@@ -360,7 +360,7 @@ void
__libcpp_db::swap(void* c1, void* c2)
{
WLock _(mut());
- size_t hc = hash<void*>()(c1) % (__cend_ - __cbeg_);
+ size_t hc = hash<void*>()(c1) % static_cast<size_t>(__cend_ - __cbeg_);
__c_node* p1 = __cbeg_[hc];
_LIBCPP_ASSERT(p1 != nullptr, "debug mode internal logic error swap A");
while (p1->__c_ != c1)
@@ -368,7 +368,7 @@ __libcpp_db::swap(void* c1, void* c2)
p1 = p1->__next_;
_LIBCPP_ASSERT(p1 != nullptr, "debug mode internal logic error swap B");
}
- hc = hash<void*>()(c2) % (__cend_ - __cbeg_);
+ hc = hash<void*>()(c2) % static_cast<size_t>(__cend_ - __cbeg_);
__c_node* p2 = __cbeg_[hc];
_LIBCPP_ASSERT(p2 != nullptr, "debug mode internal logic error swap C");
while (p2->__c_ != c2)
@@ -397,7 +397,7 @@ __c_node::__add(__i_node* i)
{
if (end_ == cap_)
{
- size_t nc = 2*(cap_ - beg_);
+ size_t nc = 2*static_cast<size_t>(cap_ - beg_);
if (nc == 0)
nc = 1;
__i_node** beg = (__i_node**)malloc(nc * sizeof(__i_node*));
@@ -419,9 +419,9 @@ _LIBCPP_HIDDEN
__i_node*
__libcpp_db::__insert_iterator(void* __i)
{
- if (__isz_ + 1 > __iend_ - __ibeg_)
+ if (__isz_ + 1 > static_cast<size_t>(__iend_ - __ibeg_))
{
- size_t nc = __next_prime(2*(__iend_ - __ibeg_) + 1);
+ size_t nc = __next_prime(2*static_cast<size_t>(__iend_ - __ibeg_) + 1);
__i_node** ibeg = (__i_node**)calloc(nc, sizeof(void*));
if (ibeg == nullptr)
throw bad_alloc();
@@ -441,7 +441,7 @@ __libcpp_db::__insert_iterator(void* __i)
__ibeg_ = ibeg;
__iend_ = __ibeg_ + nc;
}
- size_t hi = hash<void*>()(__i) % (__iend_ - __ibeg_);
+ size_t hi = hash<void*>()(__i) % static_cast<size_t>(__iend_ - __ibeg_);
__i_node* p = __ibeg_[hi];
__i_node* r = __ibeg_[hi] = (__i_node*)malloc(sizeof(__i_node));
if (r == nullptr)
@@ -458,7 +458,7 @@ __libcpp_db::__find_iterator(const void* __i) const
__i_node* r = nullptr;
if (__ibeg_ != __iend_)
{
- size_t h = hash<const void*>()(__i) % (__iend_ - __ibeg_);
+ size_t h = hash<const void*>()(__i) % static_cast<size_t>(__iend_ - __ibeg_);
for (__i_node* nd = __ibeg_[h]; nd != nullptr; nd = nd->__next_)
{
if (nd->__i_ == __i)
@@ -478,7 +478,7 @@ __c_node::__remove(__i_node* p)
__i_node** r = find(beg_, end_, p);
_LIBCPP_ASSERT(r != end_, "debug mode internal logic error __c_node::__remove");
if (--end_ != r)
- memmove(r, r+1, (end_ - r)*sizeof(__i_node*));
+ memmove(r, r+1, static_cast<size_t>(end_ - r)*sizeof(__i_node*));
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/src/exception.cpp b/src/exception.cpp
index 26d97a960825..6b5e6984a606 100644
--- a/src/exception.cpp
+++ b/src/exception.cpp
@@ -12,14 +12,17 @@
#if __APPLE__
#include <cxxabi.h>
+
using namespace __cxxabiv1;
- using namespace __cxxabiapple;
- // On Darwin, there are two STL shared libraries and a lower level ABI
- // shared libray. The globals holding the current terminate handler and
- // current unexpected handler are in the ABI library.
- #define __terminate_handler __cxxabiapple::__cxa_terminate_handler
- #define __unexpected_handler __cxxabiapple::__cxa_unexpected_handler
#define HAVE_DEPENDENT_EH_ABI 1
+ #ifndef _LIBCPPABI_VERSION
+ using namespace __cxxabiapple;
+ // On Darwin, there are two STL shared libraries and a lower level ABI
+ // shared libray. The globals holding the current terminate handler and
+ // current unexpected handler are in the ABI library.
+ #define __terminate_handler __cxxabiapple::__cxa_terminate_handler
+ #define __unexpected_handler __cxxabiapple::__cxa_unexpected_handler
+ #endif // _LIBCPPABI_VERSION
#elif defined(LIBCXXRT)
#include <cxxabi.h>
using namespace __cxxabiv1;
@@ -29,50 +32,54 @@
static std::unexpected_handler __unexpected_handler;
#endif // __APPLE__
-#ifndef LIBCXXRT
+namespace std
+{
+
+#if !defined(LIBCXXRT) && !defined(_LIBCPPABI_VERSION)
+
// libcxxrt provides implementations of these functions itself.
-std::unexpected_handler
-std::set_unexpected(std::unexpected_handler func) _NOEXCEPT
+unexpected_handler
+set_unexpected(unexpected_handler func) _NOEXCEPT
{
return __sync_lock_test_and_set(&__unexpected_handler, func);
}
-std::unexpected_handler
-std::get_unexpected() _NOEXCEPT
+unexpected_handler
+get_unexpected() _NOEXCEPT
{
- return __sync_fetch_and_add(&__unexpected_handler, (std::unexpected_handler)0);
+ return __sync_fetch_and_add(&__unexpected_handler, (unexpected_handler)0);
}
_ATTRIBUTE(noreturn)
void
-std::unexpected()
+unexpected()
{
- (*std::get_unexpected())();
+ (*get_unexpected())();
// unexpected handler should not return
- std::terminate();
+ terminate();
}
-std::terminate_handler
-std::set_terminate(std::terminate_handler func) _NOEXCEPT
+terminate_handler
+set_terminate(terminate_handler func) _NOEXCEPT
{
return __sync_lock_test_and_set(&__terminate_handler, func);
}
-std::terminate_handler
-std::get_terminate() _NOEXCEPT
+terminate_handler
+get_terminate() _NOEXCEPT
{
- return __sync_fetch_and_add(&__terminate_handler, (std::terminate_handler)0);
+ return __sync_fetch_and_add(&__terminate_handler, (terminate_handler)0);
}
_ATTRIBUTE(noreturn)
void
-std::terminate() _NOEXCEPT
+terminate() _NOEXCEPT
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
- (*std::get_terminate())();
+ (*get_terminate())();
// handler should not return
::abort ();
#ifndef _LIBCPP_NO_EXCEPTIONS
@@ -84,13 +91,14 @@ std::terminate() _NOEXCEPT
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
-#endif // LIBCXXRT
+#endif // !defined(LIBCXXRT) && !defined(_LIBCPPABI_VERSION)
-bool std::uncaught_exception() _NOEXCEPT
+#ifndef LIBCXXRT
+bool uncaught_exception() _NOEXCEPT
{
#if __APPLE__
// on Darwin, there is a helper function so __cxa_get_globals is private
- return __cxxabiapple::__cxa_uncaught_exception();
+ return __cxa_uncaught_exception();
#elif LIBCXXRT
__cxa_eh_globals * globals = __cxa_get_globals();
return (globals->uncaughtExceptions != 0);
@@ -100,8 +108,7 @@ bool std::uncaught_exception() _NOEXCEPT
#endif // __APPLE__
}
-namespace std
-{
+#ifndef _LIBCPPABI_VERSION
exception::~exception() _NOEXCEPT
{
@@ -121,6 +128,9 @@ const char* bad_exception::what() const _NOEXCEPT
return "std::bad_exception";
}
+#endif // _LIBCPPABI_VERSION
+#endif //LIBCXXRT
+
exception_ptr::~exception_ptr() _NOEXCEPT
{
#if HAVE_DEPENDENT_EH_ABI
@@ -176,15 +186,14 @@ nested_exception::rethrow_nested() const
rethrow_exception(__ptr_);
}
-} // std
-std::exception_ptr std::current_exception() _NOEXCEPT
+exception_ptr current_exception() _NOEXCEPT
{
#if HAVE_DEPENDENT_EH_ABI
// be nicer if there was a constructor that took a ptr, then
// this whole function would be just:
// return exception_ptr(__cxa_current_primary_exception());
- std::exception_ptr ptr;
+ exception_ptr ptr;
ptr.__ptr_ = __cxa_current_primary_exception();
return ptr;
#else // __APPLE__
@@ -193,7 +202,8 @@ std::exception_ptr std::current_exception() _NOEXCEPT
#endif // __APPLE__
}
-void std::rethrow_exception(exception_ptr p)
+_ATTRIBUTE(noreturn)
+void rethrow_exception(exception_ptr p)
{
#if HAVE_DEPENDENT_EH_ABI
__cxa_rethrow_primary_exception(p.__ptr_);
@@ -204,3 +214,4 @@ void std::rethrow_exception(exception_ptr p)
::abort();
#endif // __APPLE__
}
+} // std
diff --git a/src/future.cpp b/src/future.cpp
index ff59110593b2..29357112df98 100644
--- a/src/future.cpp
+++ b/src/future.cpp
@@ -29,7 +29,7 @@ __future_error_category::name() const _NOEXCEPT
string
__future_error_category::message(int ev) const
{
- switch (ev)
+ switch (static_cast<future_errc>(ev))
{
case future_errc::broken_promise:
return string("The associated promise has been destructed prior "
@@ -152,9 +152,9 @@ __assoc_sub_state::__sub_wait(unique_lock<mutex>& __lk)
{
if (!__is_ready())
{
- if (__state_ & deferred)
+ if (__state_ & static_cast<unsigned>(deferred))
{
- __state_ &= ~deferred;
+ __state_ &= ~static_cast<unsigned>(deferred);
__lk.unlock();
__execute();
}
diff --git a/src/hash.cpp b/src/hash.cpp
index 728b9bd3831b..6f30d5a60581 100644
--- a/src/hash.cpp
+++ b/src/hash.cpp
@@ -181,7 +181,8 @@ __next_prime(size_t n)
// Select first potential prime >= n
// Known a-priori n >= L
size_t k0 = n / L;
- size_t in = std::lower_bound(indices, indices + M, n - k0 * L) - indices;
+ size_t in = static_cast<size_t>(std::lower_bound(indices, indices + M, n - k0 * L)
+ - indices);
n = L * k0 + indices[in];
while (true)
{
diff --git a/src/locale.cpp b/src/locale.cpp
index b90e163a02a9..fe994881d462 100644
--- a/src/locale.cpp
+++ b/src/locale.cpp
@@ -7,6 +7,12 @@
//
//===----------------------------------------------------------------------===//
+// On Solaris, we need to define something to make the C99 parts of localeconv
+// visible.
+#ifdef __sun__
+#define _LCONV_C99
+#endif
+
#include "string"
#include "locale"
#include "codecvt"
@@ -77,12 +83,15 @@ make(A0 a0, A1 a1, A2 a2)
}
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wpadded"
+
class _LIBCPP_HIDDEN locale::__imp
: public facet
{
enum {N = 28};
- string name_;
vector<facet*, __sso_allocator<facet*, N> > facets_;
+ string name_;
public:
explicit __imp(size_t refs = 0);
explicit __imp(const string& name, size_t refs = 0);
@@ -93,7 +102,8 @@ public:
~__imp();
const string& name() const {return name_;}
- bool has_facet(long id) const {return id < facets_.size() && facets_[id];}
+ bool has_facet(long id) const
+ {return static_cast<size_t>(id) < facets_.size() && facets_[static_cast<size_t>(id)];}
const locale::facet* use_facet(long id) const;
static const locale& make_classic();
@@ -104,46 +114,48 @@ private:
template <class F> void install_from(const __imp& other);
};
+#pragma clang diagnostic pop
+
locale::__imp::__imp(size_t refs)
: facet(refs),
- name_("C"),
- facets_(N)
+ facets_(N),
+ name_("C")
{
facets_.clear();
- install(&make<_VSTD::collate<char> >(1));
- install(&make<_VSTD::collate<wchar_t> >(1));
- install(&make<_VSTD::ctype<char> >((ctype_base::mask*)0, false, 1));
- install(&make<_VSTD::ctype<wchar_t> >(1));
- install(&make<codecvt<char, char, mbstate_t> >(1));
- install(&make<codecvt<wchar_t, char, mbstate_t> >(1));
- install(&make<codecvt<char16_t, char, mbstate_t> >(1));
- install(&make<codecvt<char32_t, char, mbstate_t> >(1));
- install(&make<numpunct<char> >(1));
- install(&make<numpunct<wchar_t> >(1));
- install(&make<num_get<char> >(1));
- install(&make<num_get<wchar_t> >(1));
- install(&make<num_put<char> >(1));
- install(&make<num_put<wchar_t> >(1));
- install(&make<moneypunct<char, false> >(1));
- install(&make<moneypunct<char, true> >(1));
- install(&make<moneypunct<wchar_t, false> >(1));
- install(&make<moneypunct<wchar_t, true> >(1));
- install(&make<money_get<char> >(1));
- install(&make<money_get<wchar_t> >(1));
- install(&make<money_put<char> >(1));
- install(&make<money_put<wchar_t> >(1));
- install(&make<time_get<char> >(1));
- install(&make<time_get<wchar_t> >(1));
- install(&make<time_put<char> >(1));
- install(&make<time_put<wchar_t> >(1));
- install(&make<_VSTD::messages<char> >(1));
- install(&make<_VSTD::messages<wchar_t> >(1));
+ install(&make<_VSTD::collate<char> >(1u));
+ install(&make<_VSTD::collate<wchar_t> >(1u));
+ install(&make<_VSTD::ctype<char> >((ctype_base::mask*)0, false, 1u));
+ install(&make<_VSTD::ctype<wchar_t> >(1u));
+ install(&make<codecvt<char, char, mbstate_t> >(1u));
+ install(&make<codecvt<wchar_t, char, mbstate_t> >(1u));
+ install(&make<codecvt<char16_t, char, mbstate_t> >(1u));
+ install(&make<codecvt<char32_t, char, mbstate_t> >(1u));
+ install(&make<numpunct<char> >(1u));
+ install(&make<numpunct<wchar_t> >(1u));
+ install(&make<num_get<char> >(1u));
+ install(&make<num_get<wchar_t> >(1u));
+ install(&make<num_put<char> >(1u));
+ install(&make<num_put<wchar_t> >(1u));
+ install(&make<moneypunct<char, false> >(1u));
+ install(&make<moneypunct<char, true> >(1u));
+ install(&make<moneypunct<wchar_t, false> >(1u));
+ install(&make<moneypunct<wchar_t, true> >(1u));
+ install(&make<money_get<char> >(1u));
+ install(&make<money_get<wchar_t> >(1u));
+ install(&make<money_put<char> >(1u));
+ install(&make<money_put<wchar_t> >(1u));
+ install(&make<time_get<char> >(1u));
+ install(&make<time_get<wchar_t> >(1u));
+ install(&make<time_put<char> >(1u));
+ install(&make<time_put<wchar_t> >(1u));
+ install(&make<_VSTD::messages<char> >(1u));
+ install(&make<_VSTD::messages<wchar_t> >(1u));
}
locale::__imp::__imp(const string& name, size_t refs)
: facet(refs),
- name_(name),
- facets_(N)
+ facets_(N),
+ name_(name)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
@@ -186,8 +198,8 @@ locale::__imp::__imp(const string& name, size_t refs)
}
locale::__imp::__imp(const __imp& other)
- : name_(other.name_),
- facets_(max<size_t>(N, other.facets_.size()))
+ : facets_(max<size_t>(N, other.facets_.size())),
+ name_(other.name_)
{
facets_ = other.facets_;
for (unsigned i = 0; i < facets_.size(); ++i)
@@ -196,8 +208,8 @@ locale::__imp::__imp(const __imp& other)
}
locale::__imp::__imp(const __imp& other, const string& name, locale::category c)
- : name_("*"),
- facets_(N)
+ : facets_(N),
+ name_("*")
{
facets_ = other.facets_;
for (unsigned i = 0; i < facets_.size(); ++i)
@@ -267,8 +279,8 @@ locale::__imp::install_from(const locale::__imp& one)
}
locale::__imp::__imp(const __imp& other, const __imp& one, locale::category c)
- : name_("*"),
- facets_(N)
+ : facets_(N),
+ name_("*")
{
facets_ = other.facets_;
for (unsigned i = 0; i < facets_.size(); ++i)
@@ -337,8 +349,8 @@ locale::__imp::__imp(const __imp& other, const __imp& one, locale::category c)
}
locale::__imp::__imp(const __imp& other, facet* f, long id)
- : name_("*"),
- facets_(max<size_t>(N, other.facets_.size()+1))
+ : facets_(max<size_t>(N, other.facets_.size()+1)),
+ name_("*")
{
f->__add_shared();
unique_ptr<facet, release> hold(f);
@@ -361,11 +373,11 @@ locale::__imp::install(facet* f, long id)
{
f->__add_shared();
unique_ptr<facet, release> hold(f);
- if (id >= facets_.size())
- facets_.resize(id+1);
- if (facets_[id])
- facets_[id]->__release_shared();
- facets_[id] = hold.release();
+ if (static_cast<size_t>(id) >= facets_.size())
+ facets_.resize(static_cast<size_t>(id+1));
+ if (facets_[static_cast<size_t>(id)])
+ facets_[static_cast<size_t>(id)]->__release_shared();
+ facets_[static_cast<size_t>(id)] = hold.release();
}
const locale::facet*
@@ -375,7 +387,7 @@ locale::__imp::use_facet(long id) const
if (!has_facet(id))
throw bad_cast();
#endif // _LIBCPP_NO_EXCEPTIONS
- return facets_[id];
+ return facets_[static_cast<size_t>(id)];
}
// locale
@@ -386,7 +398,7 @@ locale::__imp::make_classic()
// only one thread can get in here and it only gets in once
static aligned_storage<sizeof(locale)>::type buf;
locale* c = (locale*)&buf;
- c->__locale_ = &make<__imp>(1);
+ c->__locale_ = &make<__imp>(1u);
return *c;
}
@@ -402,7 +414,6 @@ locale::__imp::make_global()
{
// only one thread can get in here and it only gets in once
static aligned_storage<sizeof(locale)>::type buf;
- locale* g = (locale*)&buf;
::new (&buf) locale(locale::classic());
return *(locale*)&buf;
}
@@ -800,7 +811,7 @@ ctype<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfau
{
for (; low != high; ++low, ++dest)
if (isascii(*low))
- *dest = *low;
+ *dest = static_cast<char>(*low);
else
*dest = dfault;
return low;
@@ -829,7 +840,8 @@ char
ctype<char>::do_toupper(char_type c) const
{
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
- return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
+ 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;
#else
@@ -842,7 +854,8 @@ ctype<char>::do_toupper(char_type* low, const char_type* high) const
{
for (; low != high; ++low)
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
- *low = isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low;
+ *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;
#else
@@ -855,7 +868,8 @@ char
ctype<char>::do_tolower(char_type c) const
{
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
- return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c;
+ 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;
#else
@@ -868,7 +882,7 @@ ctype<char>::do_tolower(char_type* low, const char_type* high) const
{
for (; low != high; ++low)
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
- *low = isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low;
+ *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;
#else
@@ -917,11 +931,17 @@ ctype<char>::classic_table() _NOEXCEPT
return _DefaultRuneLocale.__runetype;
#elif defined(__GLIBC__)
return __cloc()->__ctype_b;
+#elif __sun__
+ return __ctype_mask;
#elif _WIN32
return _ctype+1; // internal ctype mask table defined in msvcrt.dll
// This is assumed to be safe, which is a nonsense assumption because we're
// going to end up dereferencing it later...
#else
+ // Platform not supported: abort so the person doing the port knows what to
+ // fix
+# warning ctype<char>::classic_table() is not implemented
+ abort();
return NULL;
#endif
}
@@ -972,28 +992,28 @@ ctype_byname<char>::~ctype_byname()
char
ctype_byname<char>::do_toupper(char_type c) const
{
- return toupper_l(c, __l);
+ return static_cast<char>(toupper_l(c, __l));
}
const char*
ctype_byname<char>::do_toupper(char_type* low, const char_type* high) const
{
for (; low != high; ++low)
- *low = toupper_l(*low, __l);
+ *low = static_cast<char>(toupper_l(*low, __l));
return low;
}
char
ctype_byname<char>::do_tolower(char_type c) const
{
- return tolower_l(c, __l);
+ return static_cast<char>(tolower_l(c, __l));
}
const char*
ctype_byname<char>::do_tolower(char_type* low, const char_type* high) const
{
for (; low != high; ++low)
- *low = tolower_l(*low, __l);
+ *low = static_cast<char>(tolower_l(*low, __l));
return low;
}
@@ -1258,7 +1278,7 @@ int
codecvt<char, char, mbstate_t>::do_length(state_type&,
const extern_type* frm, const extern_type* end, size_t mx) const
{
- return static_cast<int>(min<size_t>(mx, end-frm));
+ return static_cast<int>(min<size_t>(mx, static_cast<size_t>(end-frm)));
}
int
@@ -1311,7 +1331,8 @@ codecvt<wchar_t, char, mbstate_t>::do_out(state_type& st,
// save state in case needed to reover to_nxt on error
mbstate_t save_state = st;
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
- size_t n = wcsnrtombs_l(to, &frm_nxt, fend-frm, to_end-to, &st, __l);
+ size_t n = wcsnrtombs_l(to, &frm_nxt, static_cast<size_t>(fend-frm),
+ static_cast<size_t>(to_end-to), &st, __l);
#else
size_t n = __wcsnrtombs_l(to, &frm_nxt, fend-frm, to_end-to, &st, __l);
#endif
@@ -1348,7 +1369,7 @@ codecvt<wchar_t, char, mbstate_t>::do_out(state_type& st,
#endif
if (n == size_t(-1)) // on error
return error;
- if (n > to_end-to_nxt) // is there room?
+ if (n > static_cast<size_t>(to_end-to_nxt)) // is there room?
return partial;
for (extern_type* p = tmp; n; --n) // write it
*to_nxt++ = *p++;
@@ -1379,7 +1400,8 @@ codecvt<wchar_t, char, mbstate_t>::do_in(state_type& st,
// save state in case needed to reover to_nxt on error
mbstate_t save_state = st;
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
- size_t n = mbsnrtowcs_l(to, &frm_nxt, fend-frm, to_end-to, &st, __l);
+ size_t n = mbsnrtowcs_l(to, &frm_nxt, static_cast<size_t>(fend-frm),
+ static_cast<size_t>(to_end-to), &st, __l);
#else
size_t n = __mbsnrtowcs_l(to, &frm_nxt, fend-frm, to_end-to, &st, __l);
#endif
@@ -1389,7 +1411,8 @@ codecvt<wchar_t, char, mbstate_t>::do_in(state_type& st,
for (to_nxt = to; frm != frm_nxt; ++to_nxt)
{
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
- n = mbrtowc_l(to_nxt, frm, fend-frm, &save_state, __l);
+ n = mbrtowc_l(to_nxt, frm, static_cast<size_t>(fend-frm),
+ &save_state, __l);
#else
n = __mbrtowc_l(to_nxt, frm, fend-frm, &save_state, __l);
#endif
@@ -1398,10 +1421,10 @@ codecvt<wchar_t, char, mbstate_t>::do_in(state_type& st,
case 0:
++frm;
break;
- case -1:
+ case size_t(-1):
frm_nxt = frm;
return error;
- case -2:
+ case size_t(-2):
frm_nxt = frm;
return partial;
default:
@@ -1452,7 +1475,7 @@ codecvt<wchar_t, char, mbstate_t>::do_unshift(state_type& st,
if (n == size_t(-1) || n == 0) // on error
return error;
--n;
- if (n > to_end-to_nxt) // is there room?
+ if (n > static_cast<size_t>(to_end-to_nxt)) // is there room?
return partial;
for (extern_type* p = tmp; n; --n) // write it
*to_nxt++ = *p++;
@@ -1494,7 +1517,7 @@ codecvt<wchar_t, char, mbstate_t>::do_length(state_type& st,
for (size_t nwchar_t = 0; nwchar_t < mx && frm != frm_end; ++nwchar_t)
{
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
- size_t n = mbrlen_l(frm, frm_end-frm, &st, __l);
+ size_t n = mbrlen_l(frm, static_cast<size_t>(frm_end-frm), &st, __l);
#else
size_t n = __mbrlen_l(frm, frm_end-frm, &st, __l);
#endif
@@ -1504,8 +1527,8 @@ codecvt<wchar_t, char, mbstate_t>::do_length(state_type& st,
++nbytes;
++frm;
break;
- case -1:
- case -2:
+ case size_t(-1):
+ case size_t(-2):
return nbytes;
default:
nbytes += n;
@@ -1977,9 +2000,6 @@ utf8_to_utf16_length(const uint8_t* frm, const uint8_t* frm_end,
break;
uint8_t c2 = frm_nxt[1];
uint8_t c3 = frm_nxt[2];
- uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
- | ((c2 & 0x3F) << 6)
- | (c3 & 0x3F));
switch (c1)
{
case 0xE0:
@@ -1997,7 +2017,7 @@ utf8_to_utf16_length(const uint8_t* frm, const uint8_t* frm_end,
}
if ((c3 & 0xC0) != 0x80)
break;
- if ((((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F)) > Maxcode)
+ if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
break;
frm_nxt += 3;
}
@@ -2239,7 +2259,7 @@ utf8_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
{
if ((frm_end-frm_nxt < 2) || ((frm_nxt[1] & 0xC0) != 0x80))
break;
- if ((((c1 & 0x1F) << 6) | (frm_nxt[1] & 0x3F)) > Maxcode)
+ if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode)
break;
frm_nxt += 2;
}
@@ -2266,7 +2286,7 @@ utf8_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
}
if ((c3 & 0xC0) != 0x80)
break;
- if ((((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F)) > Maxcode)
+ if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
break;
frm_nxt += 3;
}
@@ -2294,12 +2314,8 @@ utf8_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
}
if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
break;
- uint32_t t = static_cast<uint32_t>(((c1 & 0x07) << 18)
- | ((c2 & 0x3F) << 12)
- | ((c3 & 0x3F) << 6)
- | (c4 & 0x3F));
- if ((((c1 & 0x07) << 18) | ((c2 & 0x3F) << 12) |
- ((c3 & 0x3F) << 6) | (c4 & 0x3F)) > Maxcode)
+ if ((((c1 & 0x07u) << 18) | ((c2 & 0x3Fu) << 12) |
+ ((c3 & 0x3Fu) << 6) | (c4 & 0x3Fu)) > Maxcode)
break;
frm_nxt += 4;
}
@@ -2468,7 +2484,7 @@ utf8_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
{
if ((frm_end-frm_nxt < 2) || ((frm_nxt[1] & 0xC0) != 0x80))
break;
- if ((((c1 & 0x1F) << 6) | (frm_nxt[1] & 0x3F)) > Maxcode)
+ if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode)
break;
frm_nxt += 2;
}
@@ -2495,7 +2511,7 @@ utf8_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
}
if ((c3 & 0xC0) != 0x80)
break;
- if ((((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F)) > Maxcode)
+ if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
break;
frm_nxt += 3;
}
@@ -2567,7 +2583,7 @@ utf16be_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_
}
for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
{
- uint16_t c1 = frm_nxt[0] << 8 | frm_nxt[1];
+ uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
if ((c1 & 0xFC00) == 0xDC00)
return codecvt_base::error;
if ((c1 & 0xFC00) != 0xD800)
@@ -2581,7 +2597,7 @@ utf16be_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_
{
if (frm_end-frm_nxt < 4)
return codecvt_base::partial;
- uint16_t c2 = frm_nxt[2] << 8 | frm_nxt[3];
+ uint16_t c2 = static_cast<uint16_t>(frm_nxt[2] << 8 | frm_nxt[3]);
if ((c2 & 0xFC00) != 0xDC00)
return codecvt_base::error;
uint32_t t = static_cast<uint32_t>(
@@ -2612,7 +2628,7 @@ utf16be_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
}
for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t)
{
- uint16_t c1 = frm_nxt[0] << 8 | frm_nxt[1];
+ uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
if ((c1 & 0xFC00) == 0xDC00)
break;
if ((c1 & 0xFC00) != 0xD800)
@@ -2625,7 +2641,7 @@ utf16be_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
{
if (frm_end-frm_nxt < 4)
break;
- uint16_t c2 = frm_nxt[2] << 8 | frm_nxt[3];
+ uint16_t c2 = static_cast<uint16_t>(frm_nxt[2] << 8 | frm_nxt[3]);
if ((c2 & 0xFC00) != 0xDC00)
break;
uint32_t t = static_cast<uint32_t>(
@@ -2700,7 +2716,7 @@ utf16le_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_
}
for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
{
- uint16_t c1 = frm_nxt[1] << 8 | frm_nxt[0];
+ uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
if ((c1 & 0xFC00) == 0xDC00)
return codecvt_base::error;
if ((c1 & 0xFC00) != 0xD800)
@@ -2714,7 +2730,7 @@ utf16le_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_
{
if (frm_end-frm_nxt < 4)
return codecvt_base::partial;
- uint16_t c2 = frm_nxt[3] << 8 | frm_nxt[2];
+ uint16_t c2 = static_cast<uint16_t>(frm_nxt[3] << 8 | frm_nxt[2]);
if ((c2 & 0xFC00) != 0xDC00)
return codecvt_base::error;
uint32_t t = static_cast<uint32_t>(
@@ -2745,7 +2761,7 @@ utf16le_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
}
for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t)
{
- uint16_t c1 = frm_nxt[1] << 8 | frm_nxt[0];
+ uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
if ((c1 & 0xFC00) == 0xDC00)
break;
if ((c1 & 0xFC00) != 0xD800)
@@ -2758,7 +2774,7 @@ utf16le_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
{
if (frm_end-frm_nxt < 4)
break;
- uint16_t c2 = frm_nxt[3] << 8 | frm_nxt[2];
+ uint16_t c2 = static_cast<uint16_t>(frm_nxt[3] << 8 | frm_nxt[2]);
if ((c2 & 0xFC00) != 0xDC00)
break;
uint32_t t = static_cast<uint32_t>(
@@ -2816,7 +2832,7 @@ utf16be_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_
}
for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
{
- uint16_t c1 = frm_nxt[0] << 8 | frm_nxt[1];
+ uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
return codecvt_base::error;
*to_nxt = c1;
@@ -2840,7 +2856,7 @@ utf16be_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
}
for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t)
{
- uint16_t c1 = frm_nxt[0] << 8 | frm_nxt[1];
+ uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
break;
frm_nxt += 2;
@@ -2891,7 +2907,7 @@ utf16le_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_
}
for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
{
- uint16_t c1 = frm_nxt[1] << 8 | frm_nxt[0];
+ uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
return codecvt_base::error;
*to_nxt = c1;
@@ -2915,7 +2931,7 @@ utf16le_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
}
for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t)
{
- uint16_t c1 = frm_nxt[1] << 8 | frm_nxt[0];
+ uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
break;
frm_nxt += 2;
@@ -4068,7 +4084,7 @@ numpunct_byname<char>::__init(const char* nm)
{
__locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
#ifndef _LIBCPP_NO_EXCEPTIONS
- if (loc == 0)
+ if (loc == nullptr)
throw runtime_error("numpunct_byname<char>::numpunct_byname"
" failed to construct for " + string(nm));
#endif // _LIBCPP_NO_EXCEPTIONS
@@ -4111,7 +4127,7 @@ numpunct_byname<wchar_t>::__init(const char* nm)
{
__locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
#ifndef _LIBCPP_NO_EXCEPTIONS
- if (loc == 0)
+ if (loc == nullptr)
throw runtime_error("numpunct_byname<char>::numpunct_byname"
" failed to construct for " + string(nm));
#endif // _LIBCPP_NO_EXCEPTIONS
@@ -4159,7 +4175,7 @@ __check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end,
{
if (0 < *__ig && *__ig < numeric_limits<char>::max())
{
- if (*__ig != *__r)
+ if (static_cast<unsigned>(*__ig) != *__r)
{
__err = ios_base::failbit;
return;
@@ -4170,7 +4186,7 @@ __check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end,
}
if (0 < *__ig && *__ig < numeric_limits<char>::max())
{
- if (*__ig < __g_end[-1] || __g_end[-1] == 0)
+ if (static_cast<unsigned>(*__ig) < __g_end[-1] || __g_end[-1] == 0)
__err = ios_base::failbit;
}
}
@@ -4543,11 +4559,13 @@ __time_get::~__time_get()
freelocale(__loc_);
}
+#pragma clang diagnostic ignored "-Wmissing-field-initializers"
+
template <>
string
__time_get_storage<char>::__analyze(char fmt, const ctype<char>& ct)
{
- tm t;
+ tm t = {0};
t.tm_sec = 59;
t.tm_min = 55;
t.tm_hour = 23;
@@ -4576,7 +4594,7 @@ __time_get_storage<char>::__analyze(char fmt, const ctype<char>& ct)
}
char* w = bb;
ios_base::iostate err = ios_base::goodbit;
- int i = __scan_keyword(w, be, this->__weeks_, this->__weeks_+14,
+ ptrdiff_t i = __scan_keyword(w, be, this->__weeks_, this->__weeks_+14,
ct, err, false)
- this->__weeks_;
if (i < 14)
@@ -4687,11 +4705,13 @@ __time_get_storage<char>::__analyze(char fmt, const ctype<char>& ct)
return result;
}
+#pragma clang diagnostic ignored "-Wmissing-braces"
+
template <>
wstring
__time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct)
{
- tm t;
+ tm t = {0};
t.tm_sec = 59;
t.tm_min = 55;
t.tm_hour = 23;
@@ -4705,19 +4725,19 @@ __time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct)
char f[3] = {0};
f[0] = '%';
f[1] = fmt;
- size_t be = strftime_l(buf, 100, f, &t, __loc_);
+ strftime_l(buf, 100, 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 i = mbsrtowcs_l( wbb, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+ size_t j = mbsrtowcs_l( wbb, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
#else
- size_t i = __mbsrtowcs_l( wbb, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+ size_t j = __mbsrtowcs_l( wbb, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
#endif
- if (i == -1)
+ if (j == size_t(-1))
__throw_runtime_error("locale not supported");
- wchar_t* wbe = wbb + i;
+ wchar_t* wbe = wbb + j;
wstring result;
while (wbb != wbe)
{
@@ -4730,7 +4750,7 @@ __time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct)
}
wchar_t* w = wbb;
ios_base::iostate err = ios_base::goodbit;
- int i = __scan_keyword(w, wbe, this->__weeks_, this->__weeks_+14,
+ ptrdiff_t i = __scan_keyword(w, wbe, this->__weeks_, this->__weeks_+14,
ct, err, false)
- this->__weeks_;
if (i < 14)
@@ -4900,7 +4920,7 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
#else
size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
#endif
- if (j == -1)
+ if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wbe = wbuf + j;
__weeks_[i].assign(wbuf, wbe);
@@ -4912,7 +4932,7 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
#else
j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
#endif
- if (j == -1)
+ if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wbe = wbuf + j;
__weeks_[i+7].assign(wbuf, wbe);
@@ -4929,7 +4949,7 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
#else
size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
#endif
- if (j == -1)
+ if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wbe = wbuf + j;
__months_[i].assign(wbuf, wbe);
@@ -4941,7 +4961,7 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
#else
j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
#endif
- if (j == -1)
+ if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wbe = wbuf + j;
__months_[i+12].assign(wbuf, wbe);
@@ -4956,7 +4976,7 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
#else
size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
#endif
- if (j == -1)
+ if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wbe = wbuf + j;
__am_pm_[0].assign(wbuf, wbe);
@@ -4969,7 +4989,7 @@ __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
#else
j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
#endif
- if (j == -1)
+ if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wbe = wbuf + j;
__am_pm_[1].assign(wbuf, wbe);
@@ -5230,7 +5250,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, __ne-__nb, fmt, __tm, __loc_);
+ size_t n = strftime_l(__nb, static_cast<size_t>(__ne-__nb), fmt, __tm, __loc_);
__ne = __nb + n;
}
@@ -5248,123 +5268,207 @@ __time_put::__do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm,
#else
size_t j = __mbsrtowcs_l(__wb, &__nb, 100, &mb, __loc_);
#endif
- if (j == -1)
+ if (j == size_t(-1))
__throw_runtime_error("locale not supported");
__we = __wb + j;
}
// moneypunct_byname
+template <class charT>
static
void
-__init_pat(money_base::pattern& pat, char cs_precedes, char sep_by_space, char sign_posn)
+__init_pat(money_base::pattern& pat, basic_string<charT>& __curr_symbol_,
+ bool intl, char cs_precedes, char sep_by_space, char sign_posn,
+ charT space_char)
{
const char sign = static_cast<char>(money_base::sign);
const char space = static_cast<char>(money_base::space);
const char none = static_cast<char>(money_base::none);
const char symbol = static_cast<char>(money_base::symbol);
const char value = static_cast<char>(money_base::value);
+ const bool symbol_contains_sep = intl && __curr_symbol_.size() == 4;
+
+ // Comments on case branches reflect 'C11 7.11.2.1 The localeconv
+ // function'. "Space between sign and symbol or value" means that
+ // if the sign is adjacent to the symbol, there's a space between
+ // them, and otherwise there's a space between the sign and value.
+ //
+ // C11's localeconv specifies that the fourth character of an
+ // international curr_symbol is used to separate the sign and
+ // value when sep_by_space says to do so. C++ can't represent
+ // that, so we just use a space. When sep_by_space says to
+ // separate the symbol and value-or-sign with a space, we rearrange the
+ // curr_symbol to put its spacing character on the correct side of
+ // the symbol.
+ //
+ // We also need to avoid adding an extra space between the sign
+ // and value when the currency symbol is suppressed (by not
+ // setting showbase). We match glibc's strfmon by interpreting
+ // sep_by_space==1 as "omit the space when the currency symbol is
+ // absent".
+ //
+ // Users who want to get this right should use ICU instead.
+
switch (cs_precedes)
{
- case 0:
+ case 0: // value before curr_symbol
+ if (symbol_contains_sep) {
+ // Move the separator to before the symbol, to place it
+ // between the value and symbol.
+ rotate(__curr_symbol_.begin(), __curr_symbol_.begin() + 3,
+ __curr_symbol_.end());
+ }
switch (sign_posn)
{
- case 0:
+ case 0: // Parentheses surround the quantity and currency symbol.
pat.field[0] = sign;
pat.field[1] = value;
+ pat.field[2] = none; // Any space appears in the symbol.
pat.field[3] = symbol;
switch (sep_by_space)
{
- case 0:
- pat.field[2] = none;
+ case 0: // No space separates the currency symbol and value.
+ // This case may have changed between C99 and C11;
+ // assume the currency symbol matches the intention.
+ case 2: // Space between sign and currency or value.
+ // The "sign" is two parentheses, so no space here either.
return;
- case 1:
- case 2:
- pat.field[2] = space;
+ case 1: // Space between currency-and-sign or currency and value.
+ if (!symbol_contains_sep) {
+ // We insert the space into the symbol instead of
+ // setting pat.field[2]=space so that when
+ // showbase is not set, the space goes away too.
+ __curr_symbol_.insert(0, 1, space_char);
+ }
return;
default:
break;
}
break;
- case 1:
+ case 1: // The sign string precedes the quantity and currency symbol.
pat.field[0] = sign;
pat.field[3] = symbol;
switch (sep_by_space)
{
- case 0:
+ case 0: // No space separates the currency symbol and value.
pat.field[1] = value;
pat.field[2] = none;
return;
- case 1:
+ case 1: // Space between currency-and-sign or currency and value.
pat.field[1] = value;
- pat.field[2] = space;
+ pat.field[2] = none;
+ if (!symbol_contains_sep) {
+ // We insert the space into the symbol instead of
+ // setting pat.field[2]=space so that when
+ // showbase is not set, the space goes away too.
+ __curr_symbol_.insert(0, 1, space_char);
+ }
return;
- case 2:
+ case 2: // Space between sign and currency or value.
pat.field[1] = space;
pat.field[2] = value;
+ if (symbol_contains_sep) {
+ // Remove the separator from the symbol, since it
+ // has already appeared after the sign.
+ __curr_symbol_.erase(__curr_symbol_.begin());
+ }
return;
default:
break;
}
break;
- case 2:
+ case 2: // The sign string succeeds the quantity and currency symbol.
pat.field[0] = value;
pat.field[3] = sign;
switch (sep_by_space)
{
- case 0:
+ case 0: // No space separates the currency symbol and value.
pat.field[1] = none;
pat.field[2] = symbol;
return;
- case 1:
- pat.field[1] = space;
+ case 1: // Space between currency-and-sign or currency and value.
+ if (!symbol_contains_sep) {
+ // We insert the space into the symbol instead of
+ // setting pat.field[1]=space so that when
+ // showbase is not set, the space goes away too.
+ __curr_symbol_.insert(0, 1, space_char);
+ }
+ pat.field[1] = none;
pat.field[2] = symbol;
return;
- case 2:
+ case 2: // Space between sign and currency or value.
pat.field[1] = symbol;
pat.field[2] = space;
+ if (symbol_contains_sep) {
+ // Remove the separator from the symbol, since it
+ // should not be removed if showbase is absent.
+ __curr_symbol_.erase(__curr_symbol_.begin());
+ }
return;
default:
break;
}
break;
- case 3:
+ case 3: // The sign string immediately precedes the currency symbol.
pat.field[0] = value;
pat.field[3] = symbol;
switch (sep_by_space)
{
- case 0:
+ case 0: // No space separates the currency symbol and value.
pat.field[1] = none;
pat.field[2] = sign;
return;
- case 1:
+ case 1: // Space between currency-and-sign or currency and value.
pat.field[1] = space;
pat.field[2] = sign;
+ if (symbol_contains_sep) {
+ // Remove the separator from the symbol, since it
+ // has already appeared before the sign.
+ __curr_symbol_.erase(__curr_symbol_.begin());
+ }
return;
- case 2:
+ case 2: // Space between sign and currency or value.
pat.field[1] = sign;
- pat.field[2] = space;
+ pat.field[2] = none;
+ if (!symbol_contains_sep) {
+ // We insert the space into the symbol instead of
+ // setting pat.field[2]=space so that when
+ // showbase is not set, the space goes away too.
+ __curr_symbol_.insert(0, 1, space_char);
+ }
return;
default:
break;
}
break;
- case 4:
+ case 4: // The sign string immediately succeeds the currency symbol.
pat.field[0] = value;
pat.field[3] = sign;
switch (sep_by_space)
{
- case 0:
+ case 0: // No space separates the currency symbol and value.
pat.field[1] = none;
pat.field[2] = symbol;
return;
- case 1:
- pat.field[1] = space;
+ case 1: // Space between currency-and-sign or currency and value.
+ pat.field[1] = none;
pat.field[2] = symbol;
+ if (!symbol_contains_sep) {
+ // We insert the space into the symbol instead of
+ // setting pat.field[1]=space so that when
+ // showbase is not set, the space goes away too.
+ __curr_symbol_.insert(0, 1, space_char);
+ }
return;
- case 2:
+ case 2: // Space between sign and currency or value.
pat.field[1] = symbol;
pat.field[2] = space;
+ if (symbol_contains_sep) {
+ // Remove the separator from the symbol, since it
+ // should not disappear when showbase is absent.
+ __curr_symbol_.erase(__curr_symbol_.begin());
+ }
return;
default:
break;
@@ -5374,105 +5478,157 @@ __init_pat(money_base::pattern& pat, char cs_precedes, char sep_by_space, char s
break;
}
break;
- case 1:
+ case 1: // curr_symbol before value
switch (sign_posn)
{
- case 0:
+ case 0: // Parentheses surround the quantity and currency symbol.
pat.field[0] = sign;
pat.field[1] = symbol;
+ pat.field[2] = none; // Any space appears in the symbol.
pat.field[3] = value;
switch (sep_by_space)
{
- case 0:
- pat.field[2] = none;
+ case 0: // No space separates the currency symbol and value.
+ // This case may have changed between C99 and C11;
+ // assume the currency symbol matches the intention.
+ case 2: // Space between sign and currency or value.
+ // The "sign" is two parentheses, so no space here either.
return;
- case 1:
- case 2:
- pat.field[2] = space;
+ case 1: // Space between currency-and-sign or currency and value.
+ if (!symbol_contains_sep) {
+ // We insert the space into the symbol instead of
+ // setting pat.field[2]=space so that when
+ // showbase is not set, the space goes away too.
+ __curr_symbol_.insert(0, 1, space_char);
+ }
return;
default:
break;
}
break;
- case 1:
+ case 1: // The sign string precedes the quantity and currency symbol.
pat.field[0] = sign;
pat.field[3] = value;
switch (sep_by_space)
{
- case 0:
+ case 0: // No space separates the currency symbol and value.
pat.field[1] = symbol;
pat.field[2] = none;
return;
- case 1:
+ case 1: // Space between currency-and-sign or currency and value.
pat.field[1] = symbol;
- pat.field[2] = space;
+ pat.field[2] = none;
+ if (!symbol_contains_sep) {
+ // We insert the space into the symbol instead of
+ // setting pat.field[2]=space so that when
+ // showbase is not set, the space goes away too.
+ __curr_symbol_.push_back(space_char);
+ }
return;
- case 2:
+ case 2: // Space between sign and currency or value.
pat.field[1] = space;
pat.field[2] = symbol;
+ if (symbol_contains_sep) {
+ // Remove the separator from the symbol, since it
+ // has already appeared after the sign.
+ __curr_symbol_.pop_back();
+ }
return;
default:
break;
}
break;
- case 2:
+ case 2: // The sign string succeeds the quantity and currency symbol.
pat.field[0] = symbol;
pat.field[3] = sign;
switch (sep_by_space)
{
- case 0:
+ case 0: // No space separates the currency symbol and value.
pat.field[1] = none;
pat.field[2] = value;
return;
- case 1:
- pat.field[1] = space;
+ case 1: // Space between currency-and-sign or currency and value.
+ pat.field[1] = none;
pat.field[2] = value;
+ if (!symbol_contains_sep) {
+ // We insert the space into the symbol instead of
+ // setting pat.field[1]=space so that when
+ // showbase is not set, the space goes away too.
+ __curr_symbol_.push_back(space_char);
+ }
return;
- case 2:
+ case 2: // Space between sign and currency or value.
pat.field[1] = value;
pat.field[2] = space;
+ if (symbol_contains_sep) {
+ // Remove the separator from the symbol, since it
+ // will appear before the sign.
+ __curr_symbol_.pop_back();
+ }
return;
default:
break;
}
break;
- case 3:
+ case 3: // The sign string immediately precedes the currency symbol.
pat.field[0] = sign;
pat.field[3] = value;
switch (sep_by_space)
{
- case 0:
+ case 0: // No space separates the currency symbol and value.
pat.field[1] = symbol;
pat.field[2] = none;
return;
- case 1:
+ case 1: // Space between currency-and-sign or currency and value.
pat.field[1] = symbol;
- pat.field[2] = space;
+ pat.field[2] = none;
+ if (!symbol_contains_sep) {
+ // We insert the space into the symbol instead of
+ // setting pat.field[2]=space so that when
+ // showbase is not set, the space goes away too.
+ __curr_symbol_.push_back(space_char);
+ }
return;
- case 2:
+ case 2: // Space between sign and currency or value.
pat.field[1] = space;
pat.field[2] = symbol;
+ if (symbol_contains_sep) {
+ // Remove the separator from the symbol, since it
+ // has already appeared after the sign.
+ __curr_symbol_.pop_back();
+ }
return;
default:
break;
}
break;
- case 4:
+ case 4: // The sign string immediately succeeds the currency symbol.
pat.field[0] = symbol;
pat.field[3] = value;
switch (sep_by_space)
{
- case 0:
+ case 0: // No space separates the currency symbol and value.
pat.field[1] = sign;
pat.field[2] = none;
return;
- case 1:
+ case 1: // Space between currency-and-sign or currency and value.
pat.field[1] = sign;
pat.field[2] = space;
+ if (symbol_contains_sep) {
+ // Remove the separator from the symbol, since it
+ // should not disappear when showbase is absent.
+ __curr_symbol_.pop_back();
+ }
return;
- case 2:
- pat.field[1] = space;
+ case 2: // Space between sign and currency or value.
+ pat.field[1] = none;
pat.field[2] = sign;
+ if (!symbol_contains_sep) {
+ // We insert the space into the symbol instead of
+ // setting pat.field[1]=space so that when
+ // showbase is not set, the space goes away too.
+ __curr_symbol_.push_back(space_char);
+ }
return;
default:
break;
@@ -5498,7 +5654,7 @@ moneypunct_byname<char, false>::init(const char* nm)
typedef moneypunct<char, false> base;
__locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
#ifndef _LIBCPP_NO_EXCEPTIONS
- if (loc == 0)
+ if (loc == nullptr)
throw runtime_error("moneypunct_byname"
" failed to construct for " + string(nm));
#endif // _LIBCPP_NO_EXCEPTIONS
@@ -5529,8 +5685,14 @@ moneypunct_byname<char, false>::init(const char* nm)
__negative_sign_ = "()";
else
__negative_sign_ = lc->negative_sign;
- __init_pat(__pos_format_, lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn);
- __init_pat(__neg_format_, lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn);
+ // Assume the positive and negative formats will want spaces in
+ // the same places in curr_symbol since there's no way to
+ // represent anything else.
+ string_type __dummy_curr_symbol = __curr_symbol_;
+ __init_pat(__pos_format_, __dummy_curr_symbol, false,
+ lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, ' ');
+ __init_pat(__neg_format_, __curr_symbol_, false,
+ lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, ' ');
}
template<>
@@ -5540,7 +5702,7 @@ moneypunct_byname<char, true>::init(const char* nm)
typedef moneypunct<char, true> base;
__locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
#ifndef _LIBCPP_NO_EXCEPTIONS
- if (loc == 0)
+ if (loc == nullptr)
throw runtime_error("moneypunct_byname"
" failed to construct for " + string(nm));
#endif // _LIBCPP_NO_EXCEPTIONS
@@ -5579,12 +5741,22 @@ moneypunct_byname<char, true>::init(const char* nm)
__negative_sign_ = "()";
else
__negative_sign_ = lc->negative_sign;
+ // Assume the positive and negative formats will want spaces in
+ // the same places in curr_symbol since there's no way to
+ // represent anything else.
+ string_type __dummy_curr_symbol = __curr_symbol_;
#if _WIN32
- __init_pat(__pos_format_, lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn);
- __init_pat(__neg_format_, lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn);
+ __init_pat(__pos_format_, __dummy_curr_symbol, true,
+ lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, ' ');
+ __init_pat(__neg_format_, __curr_symbol_, true,
+ lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, ' ');
#else
- __init_pat(__pos_format_, lc->int_p_cs_precedes, lc->int_p_sep_by_space, lc->int_p_sign_posn);
- __init_pat(__neg_format_, lc->int_n_cs_precedes, lc->int_n_sep_by_space, lc->int_n_sign_posn);
+ __init_pat(__pos_format_, __dummy_curr_symbol, true,
+ lc->int_p_cs_precedes, lc->int_p_sep_by_space,
+ lc->int_p_sign_posn, ' ');
+ __init_pat(__neg_format_, __curr_symbol_, true,
+ lc->int_n_cs_precedes, lc->int_n_sep_by_space,
+ lc->int_n_sign_posn, ' ');
#endif // _WIN32
}
@@ -5595,7 +5767,7 @@ moneypunct_byname<wchar_t, false>::init(const char* nm)
typedef moneypunct<wchar_t, false> base;
__locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
#ifndef _LIBCPP_NO_EXCEPTIONS
- if (loc == 0)
+ if (loc == nullptr)
throw runtime_error("moneypunct_byname"
" failed to construct for " + string(nm));
#endif // _LIBCPP_NO_EXCEPTIONS
@@ -5621,7 +5793,7 @@ moneypunct_byname<wchar_t, false>::init(const char* nm)
#else
size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
#endif
- if (j == -1)
+ if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wchar_t* wbe = wbuf + j;
__curr_symbol_.assign(wbuf, wbe);
@@ -5640,7 +5812,7 @@ moneypunct_byname<wchar_t, false>::init(const char* nm)
#else
j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
#endif
- if (j == -1)
+ if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wbe = wbuf + j;
__positive_sign_.assign(wbuf, wbe);
@@ -5656,13 +5828,19 @@ moneypunct_byname<wchar_t, false>::init(const char* nm)
#else
j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
#endif
- if (j == -1)
+ if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wbe = wbuf + j;
__negative_sign_.assign(wbuf, wbe);
}
- __init_pat(__pos_format_, lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn);
- __init_pat(__neg_format_, lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn);
+ // Assume the positive and negative formats will want spaces in
+ // the same places in curr_symbol since there's no way to
+ // represent anything else.
+ string_type __dummy_curr_symbol = __curr_symbol_;
+ __init_pat(__pos_format_, __dummy_curr_symbol, false,
+ lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, L' ');
+ __init_pat(__neg_format_, __curr_symbol_, false,
+ lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, L' ');
}
template<>
@@ -5672,7 +5850,7 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
typedef moneypunct<wchar_t, true> base;
__locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
#ifndef _LIBCPP_NO_EXCEPTIONS
- if (loc == 0)
+ if (loc == nullptr)
throw runtime_error("moneypunct_byname"
" failed to construct for " + string(nm));
#endif // _LIBCPP_NO_EXCEPTIONS
@@ -5698,7 +5876,7 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
#else
size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
#endif
- if (j == -1)
+ if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wchar_t* wbe = wbuf + j;
__curr_symbol_.assign(wbuf, wbe);
@@ -5721,7 +5899,7 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
#else
j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
#endif
- if (j == -1)
+ if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wbe = wbuf + j;
__positive_sign_.assign(wbuf, wbe);
@@ -5741,17 +5919,27 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
#else
j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
#endif
- if (j == -1)
+ if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wbe = wbuf + j;
__negative_sign_.assign(wbuf, wbe);
}
+ // Assume the positive and negative formats will want spaces in
+ // the same places in curr_symbol since there's no way to
+ // represent anything else.
+ string_type __dummy_curr_symbol = __curr_symbol_;
#if _WIN32
- __init_pat(__pos_format_, lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn);
- __init_pat(__neg_format_, lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn);
+ __init_pat(__pos_format_, __dummy_curr_symbol, true,
+ lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, L' ');
+ __init_pat(__neg_format_, __curr_symbol_, true,
+ lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, L' ');
#else // _WIN32
- __init_pat(__pos_format_, lc->int_p_cs_precedes, lc->int_p_sep_by_space, lc->int_p_sign_posn);
- __init_pat(__neg_format_, lc->int_n_cs_precedes, lc->int_n_sep_by_space, lc->int_n_sign_posn);
+ __init_pat(__pos_format_, __dummy_curr_symbol, true,
+ lc->int_p_cs_precedes, lc->int_p_sep_by_space,
+ lc->int_p_sign_posn, L' ');
+ __init_pat(__neg_format_, __curr_symbol_, true,
+ lc->int_n_cs_precedes, lc->int_n_sep_by_space,
+ lc->int_n_sign_posn, L' ');
#endif // _WIN32
}
@@ -5770,14 +5958,14 @@ template class collate<wchar_t>;
template class num_get<char>;
template class num_get<wchar_t>;
-template class __num_get<char>;
-template class __num_get<wchar_t>;
+template struct __num_get<char>;
+template struct __num_get<wchar_t>;
template class num_put<char>;
template class num_put<wchar_t>;
-template class __num_put<char>;
-template class __num_put<wchar_t>;
+template struct __num_put<char>;
+template struct __num_put<wchar_t>;
template class time_get<char>;
template class time_get<wchar_t>;
diff --git a/src/memory.cpp b/src/memory.cpp
index cb5e5e7b06ad..a892e75c86d0 100644
--- a/src/memory.cpp
+++ b/src/memory.cpp
@@ -100,10 +100,7 @@ __shared_weak_count::lock() _NOEXCEPT
if (__sync_bool_compare_and_swap(&__shared_owners_,
object_owners,
object_owners+1))
- {
- __add_weak();
return this;
- }
object_owners = __shared_owners_;
}
return 0;
@@ -154,7 +151,7 @@ align(size_t alignment, size_t size, void*& ptr, size_t& space)
{
char* p1 = static_cast<char*>(ptr);
char* p2 = (char*)((size_t)(p1 + (alignment - 1)) & -alignment);
- ptrdiff_t d = p2 - p1;
+ size_t d = static_cast<size_t>(p2 - p1);
if (d <= space - size)
{
r = p2;
diff --git a/src/mutex.cpp b/src/mutex.cpp
index 16817198b37c..9aa051be37f2 100644
--- a/src/mutex.cpp
+++ b/src/mutex.cpp
@@ -20,8 +20,7 @@ const adopt_lock_t adopt_lock = {};
mutex::~mutex()
{
- int e = pthread_mutex_destroy(&__m_);
-// assert(e == 0);
+ pthread_mutex_destroy(&__m_);
}
void
diff --git a/src/new.cpp b/src/new.cpp
index 1e8ed88dc4c1..1c171a871b9b 100644
--- a/src/new.cpp
+++ b/src/new.cpp
@@ -13,14 +13,19 @@
#if __APPLE__
#include <cxxabi.h>
- // On Darwin, there are two STL shared libraries and a lower level ABI
- // shared libray. The global holding the current new handler is
- // in the ABI library and named __cxa_new_handler.
- #define __new_handler __cxxabiapple::__cxa_new_handler
+
+ #ifndef _LIBCPPABI_VERSION
+ // On Darwin, there are two STL shared libraries and a lower level ABI
+ // shared libray. The global holding the current new handler is
+ // in the ABI library and named __cxa_new_handler.
+ #define __new_handler __cxxabiapple::__cxa_new_handler
+ #endif
#else // __APPLE__
static std::new_handler __new_handler;
#endif
+#if !defined (LIBCXXRT) // && !defined(_LIBCPPABI_VERSION)
+
// Implement all new and delete operators as weak definitions
// in this shared library, so that they can be overriden by programs
// that define non-weak copies of the functions.
@@ -83,7 +88,7 @@ operator new[](size_t size)
__attribute__((__weak__, __visibility__("default")))
void*
-operator new[](size_t size, const std::nothrow_t& nothrow) _NOEXCEPT
+operator new[](size_t size, const std::nothrow_t&) _NOEXCEPT
{
void* p = 0;
#ifndef _LIBCPP_NO_EXCEPTIONS
@@ -129,11 +134,15 @@ operator delete[] (void* ptr, const std::nothrow_t&) _NOEXCEPT
::operator delete[](ptr);
}
+#endif // !_LIBCPPABI_VERSION && !LIBCXXRT
+
namespace std
{
const nothrow_t nothrow = {};
+#ifndef _LIBCPPABI_VERSION
+
new_handler
set_new_handler(new_handler handler) _NOEXCEPT
{
@@ -146,6 +155,8 @@ get_new_handler() _NOEXCEPT
return __sync_fetch_and_add(&__new_handler, (new_handler)0);
}
+#ifndef LIBCXXRT
+
bad_alloc::bad_alloc() _NOEXCEPT
{
}
@@ -174,6 +185,9 @@ bad_array_new_length::what() const _NOEXCEPT
return "bad_array_new_length";
}
+#endif
+#endif //LIBCXXRT
+
void
__throw_bad_alloc()
{
diff --git a/src/random.cpp b/src/random.cpp
index eca97bc81943..6140b74ecb5f 100644
--- a/src/random.cpp
+++ b/src/random.cpp
@@ -10,6 +10,9 @@
#include "random"
#include "system_error"
+#ifdef __sun__
+#define rename solaris_headers_are_broken
+#endif
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
diff --git a/src/regex.cpp b/src/regex.cpp
index 65e9f886dfb8..e3ec2810c774 100644
--- a/src/regex.cpp
+++ b/src/regex.cpp
@@ -69,12 +69,17 @@ regex_error::~regex_error() throw() {}
namespace {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wpadded"
+
struct collationnames
{
const char* elem_;
char char_;
};
+#pragma clang diagnostic pop
+
const collationnames collatenames[] =
{
{"A", 0x41},
@@ -190,12 +195,17 @@ const collationnames collatenames[] =
{"zero", 0x30}
};
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wpadded"
+
struct classnames
{
const char* elem_;
ctype_base::mask mask_;
};
+#pragma clang diagnostic pop
+
const classnames ClassNames[] =
{
{"alnum", ctype_base::alnum},
diff --git a/src/stdexcept.cpp b/src/stdexcept.cpp
index 28917887587e..b516b0ca68b3 100644
--- a/src/stdexcept.cpp
+++ b/src/stdexcept.cpp
@@ -15,6 +15,7 @@
#include <cstdint>
#include <cstddef>
#include "system_error"
+#include <cxxabi.h>
// Note: optimize for size
@@ -113,6 +114,8 @@ logic_error::operator=(const logic_error& le) _NOEXCEPT
return *this;
}
+#ifndef _LIBCPPABI_VERSION
+
logic_error::~logic_error() _NOEXCEPT
{
__libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
@@ -126,6 +129,8 @@ logic_error::what() const _NOEXCEPT
return s.c_str();
}
+#endif
+
runtime_error::runtime_error(const string& msg)
{
__libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
@@ -153,6 +158,8 @@ runtime_error::operator=(const runtime_error& le) _NOEXCEPT
return *this;
}
+#ifndef _LIBCPPABI_VERSION
+
runtime_error::~runtime_error() _NOEXCEPT
{
__libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
@@ -175,4 +182,6 @@ range_error::~range_error() _NOEXCEPT {}
overflow_error::~overflow_error() _NOEXCEPT {}
underflow_error::~underflow_error() _NOEXCEPT {}
+#endif
+
} // std
diff --git a/src/string.cpp b/src/string.cpp
index 1f58e3657a89..750ba284e366 100644
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -346,7 +346,7 @@ string to_string(int val)
s.resize(s.capacity());
while (true)
{
- int n2 = snprintf(&s[0], s.size()+1, "%d", val);
+ size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%d", val));
if (n2 <= s.size())
{
s.resize(n2);
@@ -363,7 +363,7 @@ string to_string(unsigned val)
s.resize(s.capacity());
while (true)
{
- int n2 = snprintf(&s[0], s.size()+1, "%u", val);
+ size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%u", val));
if (n2 <= s.size())
{
s.resize(n2);
@@ -380,7 +380,7 @@ string to_string(long val)
s.resize(s.capacity());
while (true)
{
- int n2 = snprintf(&s[0], s.size()+1, "%ld", val);
+ size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%ld", val));
if (n2 <= s.size())
{
s.resize(n2);
@@ -397,7 +397,7 @@ string to_string(unsigned long val)
s.resize(s.capacity());
while (true)
{
- int n2 = snprintf(&s[0], s.size()+1, "%lu", val);
+ size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%lu", val));
if (n2 <= s.size())
{
s.resize(n2);
@@ -414,7 +414,7 @@ string to_string(long long val)
s.resize(s.capacity());
while (true)
{
- int n2 = snprintf(&s[0], s.size()+1, "%lld", val);
+ size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%lld", val));
if (n2 <= s.size())
{
s.resize(n2);
@@ -431,7 +431,7 @@ string to_string(unsigned long long val)
s.resize(s.capacity());
while (true)
{
- int n2 = snprintf(&s[0], s.size()+1, "%llu", val);
+ size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%llu", val));
if (n2 <= s.size())
{
s.resize(n2);
@@ -448,7 +448,7 @@ string to_string(float val)
s.resize(s.capacity());
while (true)
{
- int n2 = snprintf(&s[0], s.size()+1, "%f", val);
+ size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%f", val));
if (n2 <= s.size())
{
s.resize(n2);
@@ -465,7 +465,7 @@ string to_string(double val)
s.resize(s.capacity());
while (true)
{
- int n2 = snprintf(&s[0], s.size()+1, "%f", val);
+ size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%f", val));
if (n2 <= s.size())
{
s.resize(n2);
@@ -482,7 +482,7 @@ string to_string(long double val)
s.resize(s.capacity());
while (true)
{
- int n2 = snprintf(&s[0], s.size()+1, "%Lf", val);
+ size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%Lf", val));
if (n2 <= s.size())
{
s.resize(n2);
@@ -505,7 +505,7 @@ wstring to_wstring(int val)
int n2 = swprintf(&s[0], s.size()+1, L"%d", val);
if (n2 > 0)
{
- s.resize(n2);
+ s.resize(static_cast<size_t>(n2));
break;
}
s.resize(2*s.size());
@@ -526,7 +526,7 @@ wstring to_wstring(unsigned val)
int n2 = swprintf(&s[0], s.size()+1, L"%u", val);
if (n2 > 0)
{
- s.resize(n2);
+ s.resize(static_cast<size_t>(n2));
break;
}
s.resize(2*s.size());
@@ -547,7 +547,7 @@ wstring to_wstring(long val)
int n2 = swprintf(&s[0], s.size()+1, L"%ld", val);
if (n2 > 0)
{
- s.resize(n2);
+ s.resize(static_cast<size_t>(n2));
break;
}
s.resize(2*s.size());
@@ -568,7 +568,7 @@ wstring to_wstring(unsigned long val)
int n2 = swprintf(&s[0], s.size()+1, L"%lu", val);
if (n2 > 0)
{
- s.resize(n2);
+ s.resize(static_cast<size_t>(n2));
break;
}
s.resize(2*s.size());
@@ -589,7 +589,7 @@ wstring to_wstring(long long val)
int n2 = swprintf(&s[0], s.size()+1, L"%lld", val);
if (n2 > 0)
{
- s.resize(n2);
+ s.resize(static_cast<size_t>(n2));
break;
}
s.resize(2*s.size());
@@ -610,7 +610,7 @@ wstring to_wstring(unsigned long long val)
int n2 = swprintf(&s[0], s.size()+1, L"%llu", val);
if (n2 > 0)
{
- s.resize(n2);
+ s.resize(static_cast<size_t>(n2));
break;
}
s.resize(2*s.size());
@@ -629,7 +629,7 @@ wstring to_wstring(float val)
int n2 = swprintf(&s[0], s.size()+1, L"%f", val);
if (n2 > 0)
{
- s.resize(n2);
+ s.resize(static_cast<size_t>(n2));
break;
}
s.resize(2*s.size());
@@ -648,7 +648,7 @@ wstring to_wstring(double val)
int n2 = swprintf(&s[0], s.size()+1, L"%f", val);
if (n2 > 0)
{
- s.resize(n2);
+ s.resize(static_cast<size_t>(n2));
break;
}
s.resize(2*s.size());
@@ -667,7 +667,7 @@ wstring to_wstring(long double val)
int n2 = swprintf(&s[0], s.size()+1, L"%Lf", val);
if (n2 > 0)
{
- s.resize(n2);
+ s.resize(static_cast<size_t>(n2));
break;
}
s.resize(2*s.size());
diff --git a/src/strstream.cpp b/src/strstream.cpp
index 53139509edfa..8cd19e6a353c 100644
--- a/src/strstream.cpp
+++ b/src/strstream.cpp
@@ -34,7 +34,7 @@ void
strstreambuf::__init(char* __gnext, streamsize __n, char* __pbeg)
{
if (__n == 0)
- __n = strlen(__gnext);
+ __n = static_cast<streamsize>(strlen(__gnext));
else if (__n < 0)
__n = INT_MAX;
if (__pbeg == nullptr)
@@ -160,12 +160,12 @@ strstreambuf::overflow(int_type __c)
streamsize new_size = max<streamsize>(__alsize_, 2*old_size);
char* buf = nullptr;
if (__palloc_)
- buf = static_cast<char*>(__palloc_(new_size));
+ buf = static_cast<char*>(__palloc_(static_cast<size_t>(new_size)));
else
buf = new char[new_size];
if (buf == nullptr)
return int_type(EOF);
- memcpy(buf, eback(), old_size);
+ memcpy(buf, eback(), static_cast<size_t>(old_size));
ptrdiff_t ninp = gptr() - eback();
ptrdiff_t einp = egptr() - eback();
ptrdiff_t nout = pptr() - pbase();
@@ -179,7 +179,7 @@ strstreambuf::overflow(int_type __c)
}
setg(buf, buf + ninp, buf + einp);
setp(buf + einp, buf + einp + eout);
- pbump(nout);
+ pbump(static_cast<int>(nout));
__strmode_ |= __allocated;
}
*pptr() = static_cast<char>(__c);
diff --git a/src/thread.cpp b/src/thread.cpp
index b07f8f851072..f27136a53d05 100644
--- a/src/thread.cpp
+++ b/src/thread.cpp
@@ -12,7 +12,7 @@
#include "vector"
#include "future"
#include <sys/types.h>
-#if !_WIN32
+#if !_WIN32 && !__sun__
#include <sys/sysctl.h>
#endif // _WIN32
@@ -55,7 +55,7 @@ unsigned
thread::hardware_concurrency()
{
#if defined(CTL_HW) && defined(HW_NCPU)
- int n;
+ unsigned n;
int mib[2] = {CTL_HW, HW_NCPU};
std::size_t s = sizeof(n);
sysctl(mib, 2, &n, &s, 0, 0);
diff --git a/src/typeinfo.cpp b/src/typeinfo.cpp
index 9ca03a183e9c..cfc64ef57a61 100644
--- a/src/typeinfo.cpp
+++ b/src/typeinfo.cpp
@@ -13,6 +13,8 @@
#include "typeinfo"
+#if !(defined(_LIBCPPABI_VERSION) || defined(LIBCXXRT))
+
std::bad_cast::bad_cast() _NOEXCEPT
{
}
@@ -48,3 +50,4 @@ std::bad_typeid::what() const _NOEXCEPT
void __cxxabiv1::__cxa_bad_cast() { throw std::bad_cast(); }
#endif
+#endif // _LIBCPPABI_VERSION