diff options
Diffstat (limited to 'contrib/libstdc++/include/bits')
18 files changed, 430 insertions, 350 deletions
diff --git a/contrib/libstdc++/include/bits/basic_ios.tcc b/contrib/libstdc++/include/bits/basic_ios.tcc index 1e345dc211720..a38a95b58a0ff 100644 --- a/contrib/libstdc++/include/bits/basic_ios.tcc +++ b/contrib/libstdc++/include/bits/basic_ios.tcc @@ -156,7 +156,7 @@ namespace std // unformatted input and output with non-required basic_ios // instantiations is possible even without imbuing the expected // ctype<char_type> facet. - _M_fill = 0; + _M_fill = _CharT(); _M_fill_init = false; _M_exception = goodbit; diff --git a/contrib/libstdc++/include/bits/basic_string.h b/contrib/libstdc++/include/bits/basic_string.h index e05a1c6ef6143..a9c02ce37089a 100644 --- a/contrib/libstdc++/include/bits/basic_string.h +++ b/contrib/libstdc++/include/bits/basic_string.h @@ -650,8 +650,11 @@ namespace std || less<const _CharT*>()(_M_data() + __size, __s)) return _M_replace_safe(_M_ibegin() + __pos, _M_ibegin() + __pos + __foldn1, __s, __s + __n2); - else return this->replace(_M_check(__pos), _M_fold(__pos, __n1), - __s, __s + __n2); + // Todo: optimized in-place replace. + else return + _M_replace(_M_ibegin() + __pos, _M_ibegin() + __pos + __foldn1, + __s, __s + __n2, + typename iterator_traits<const _CharT*>::iterator_category()); } basic_string& @@ -685,6 +688,30 @@ namespace std { return _M_replace(__i1, __i2, __k1, __k2, typename iterator_traits<_InputIterator>::iterator_category()); } + // Specializations for the common case of pointer and iterator: + // useful to avoid the overhead of temporary buffering in _M_replace. + basic_string& + replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2) + { return this->replace(__i1 - _M_ibegin(), __i2 - __i1, + __k1, __k2 - __k1); } + + basic_string& + replace(iterator __i1, iterator __i2, const _CharT* __k1, const _CharT* __k2) + { return this->replace(__i1 - _M_ibegin(), __i2 - __i1, + __k1, __k2 - __k1); } + + basic_string& + replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2) + { return this->replace(__i1 - _M_ibegin(), __i2 - __i1, + __k1.base(), __k2 - __k1); + } + + basic_string& + replace(iterator __i1, iterator __i2, const_iterator __k1, const_iterator __k2) + { return this->replace(__i1 - _M_ibegin(), __i2 - __i1, + __k1.base(), __k2 - __k1); + } + private: template<class _InputIterator> basic_string& diff --git a/contrib/libstdc++/include/bits/basic_string.tcc b/contrib/libstdc++/include/bits/basic_string.tcc index 35a2f11f7e761..6d646ad2a1055 100644 --- a/contrib/libstdc++/include/bits/basic_string.tcc +++ b/contrib/libstdc++/include/bits/basic_string.tcc @@ -140,7 +140,7 @@ namespace std size_type __dnew = static_cast<size_type>(distance(__beg, __end)); // NB: Not required, but considered best practice. - if (__builtin_expect(__beg == _InIter(0), 0)) + if (__builtin_expect(__beg == _InIter(), 0)) __throw_logic_error("attempt to create string with null pointer"); if (__beg == __end && __a == _Alloc()) @@ -498,13 +498,10 @@ namespace std // else nothing (in particular, avoid calling _M_mutate() unnecessarily.) } - // This is the general replace helper, which gets instantiated both - // for input-iterators and forward-iterators. It buffers internally and - // then calls _M_replace_safe. For input-iterators this is almost the - // best we can do, but for forward-iterators many optimizations could be - // conceived: f.i., when source and destination ranges do not overlap - // buffering is not really needed. In order to easily implement them, it - // could become useful to add an _M_replace(forward_iterator_tag) + + // This is the general replace helper, which currently gets instantiated both + // for input iterators and reverse iterators. It buffers internally and then + // calls _M_replace_safe. template<typename _CharT, typename _Traits, typename _Alloc> template<typename _InputIter> basic_string<_CharT, _Traits, _Alloc>& @@ -518,10 +515,8 @@ namespace std } // This is a special replace helper, which does not buffer internally - // and can be used in the "safe" situations involving forward-iterators, + // and can be used in "safe" situations involving forward iterators, // i.e., when source and destination ranges are known to not overlap. - // Presently, is called by _M_replace, by the various append and by - // the assigns. template<typename _CharT, typename _Traits, typename _Alloc> template<typename _ForwardIter> basic_string<_CharT, _Traits, _Alloc>& diff --git a/contrib/libstdc++/include/bits/c++config b/contrib/libstdc++/include/bits/c++config index d5bf45841e583..831d35e885800 100644 --- a/contrib/libstdc++/include/bits/c++config +++ b/contrib/libstdc++/include/bits/c++config @@ -34,7 +34,7 @@ #include <bits/os_defines.h> // The current version of the C++ library in compressed ISO date format. -#define __GLIBCPP__ 20020513 +#define __GLIBCPP__ 20020831 // This is necessary until GCC supports separate template // compilation. @@ -69,7 +69,15 @@ // that threads are properly configured on your platform before // assigning blame to the STL container-memory allocator. After doing // so, please report any possible issues to libstdc++@gcc.gnu.org . -// Do not blindly #define __USE_MALLOC here or on the command line. +// Do not define __USE_MALLOC on the command line. Enforce it here: +#ifdef __USE_MALLOC +#error __USE_MALLOC should only be defined within \ +libstdc++-v3/include/bits/c++config before full recompilation of the library. +#endif +// Define __USE_MALLOC after this point in the file in order to aid debugging +// or globally change allocation policy. This breaks the ABI, thus +// completely recompile the library. A patch to better support +// changing the global allocator policy would be probably be accepted. // The remainder of the prewritten config is mostly automatic; all the // user hooks are listed above. diff --git a/contrib/libstdc++/include/bits/char_traits.h b/contrib/libstdc++/include/bits/char_traits.h index 7d14838ab2687..41f943d9a59b4 100644 --- a/contrib/libstdc++/include/bits/char_traits.h +++ b/contrib/libstdc++/include/bits/char_traits.h @@ -1,6 +1,7 @@ // Character Traits for use by standard string and iostream -*- C++ -*- -// Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 +// Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -53,82 +54,53 @@ namespace std struct char_traits { typedef _CharT char_type; - // Unsigned as wint_t in unsigned. + // Unsigned as wint_t is unsigned. typedef unsigned long int_type; typedef streampos pos_type; typedef streamoff off_type; typedef mbstate_t state_type; static void - assign(char_type& __c1, const char_type& __c2) - { __c1 = __c2; } + assign(char_type& __c1, const char_type& __c2); static bool - eq(const char_type& __c1, const char_type& __c2) - { return __c1 == __c2; } + eq(const char_type& __c1, const char_type& __c2); static bool - lt(const char_type& __c1, const char_type& __c2) - { return __c1 < __c2; } + lt(const char_type& __c1, const char_type& __c2); static int - compare(const char_type* __s1, const char_type* __s2, size_t __n) - { - for (size_t __i = 0; __i < __n; ++__i) - if (!eq(__s1[__i], __s2[__i])) - return lt(__s1[__i], __s2[__i]) ? -1 : 1; - return 0; - } + compare(const char_type* __s1, const char_type* __s2, size_t __n); static size_t - length(const char_type* __s) - { - const char_type* __p = __s; - while (*__p) ++__p; - return (__p - __s); - } + length(const char_type* __s); static const char_type* - find(const char_type* __s, size_t __n, const char_type& __a) - { - for (const char_type* __p = __s; size_t(__p - __s) < __n; ++__p) - if (*__p == __a) return __p; - return 0; - } + find(const char_type* __s, size_t __n, const char_type& __a); static char_type* - move(char_type* __s1, const char_type* __s2, size_t __n) - { return (char_type*) memmove(__s1, __s2, __n * sizeof(char_type)); } + move(char_type* __s1, const char_type* __s2, size_t __n); static char_type* - copy(char_type* __s1, const char_type* __s2, size_t __n) - { return (char_type*) memcpy(__s1, __s2, __n * sizeof(char_type)); } + copy(char_type* __s1, const char_type* __s2, size_t __n); static char_type* - assign(char_type* __s, size_t __n, char_type __a) - { - for (char_type* __p = __s; __p < __s + __n; ++__p) - assign(*__p, __a); - return __s; - } + assign(char_type* __s, size_t __n, char_type __a); static char_type - to_char_type(const int_type& __c) - { return char_type(__c); } + to_char_type(const int_type& __c); static int_type - to_int_type(const char_type& __c) { return int_type(__c); } + to_int_type(const char_type& __c); static bool - eq_int_type(const int_type& __c1, const int_type& __c2) - { return __c1 == __c2; } + eq_int_type(const int_type& __c1, const int_type& __c2); static int_type - eof() { return static_cast<int_type>(-1); } + eof(); static int_type - not_eof(const int_type& __c) - { return eq_int_type(__c, eof()) ? int_type(0) : __c; } + not_eof(const int_type& __c); }; diff --git a/contrib/libstdc++/include/bits/fpos.h b/contrib/libstdc++/include/bits/fpos.h index 3cb3e4b51a261..279e0ab16ba2e 100644 --- a/contrib/libstdc++/include/bits/fpos.h +++ b/contrib/libstdc++/include/bits/fpos.h @@ -105,7 +105,7 @@ namespace std bool operator!=(const fpos& __pos) const { return _M_off != __pos._M_off; } - + streamoff _M_position() const { return _M_off; } diff --git a/contrib/libstdc++/include/bits/fstream.tcc b/contrib/libstdc++/include/bits/fstream.tcc index 90850f54f0d70..18dbaf1caae8b 100644 --- a/contrib/libstdc++/include/bits/fstream.tcc +++ b/contrib/libstdc++/include/bits/fstream.tcc @@ -49,12 +49,7 @@ namespace std _M_buf_size = _M_buf_size_opt; // Allocate internal buffer. - try { _M_buf = new char_type[_M_buf_size]; } - catch(...) - { - delete [] _M_buf; - __throw_exception_again; - } + _M_buf = new char_type[_M_buf_size]; _M_buf_allocated = true; } } @@ -95,9 +90,8 @@ namespace std { _M_allocate_internal_buffer(); _M_mode = __mode; - - // For time being, set both (in/out) sets of pointers. _M_set_indeterminate(); + if ((__mode & ios_base::ate) && this->seekoff(0, ios_base::end, __mode) < 0) this->close(); @@ -117,7 +111,8 @@ namespace std { const int_type __eof = traits_type::eof(); bool __testput = _M_out_cur && _M_out_beg < _M_out_end; - if (__testput && _M_really_overflow(__eof) == __eof) + if (__testput + && traits_type::eq_int_type(_M_really_overflow(__eof), __eof)) return __ret; // NB: Do this here so that re-opened filebufs will be cool... @@ -151,102 +146,7 @@ namespace std bool __testin = _M_mode & ios_base::in; if (__testin && this->is_open()) - { - if (_M_in_cur < _M_in_end) - __ret = _M_in_end - _M_in_cur; - else - __ret = 0; - } - _M_last_overflowed = false; - return __ret; - } - - template<typename _CharT, typename _Traits> - typename basic_filebuf<_CharT, _Traits>::int_type - basic_filebuf<_CharT, _Traits>:: - _M_underflow_common(bool __bump) - { - int_type __ret = traits_type::eof(); - bool __testin = _M_mode & ios_base::in; - bool __testout = _M_mode & ios_base::out; - - if (__testin) - { - // Check for pback madness, and if so swich back to the - // normal buffers and jet outta here before expensive - // fileops happen... - if (_M_pback_init) - { - _M_pback_destroy(); - if (_M_in_cur < _M_in_end) - return traits_type::to_int_type(*_M_in_cur); - } - - // Sync internal and external buffers. - // NB: __testget -> __testput as _M_buf_unified here. - bool __testget = _M_in_cur && _M_in_beg < _M_in_cur; - bool __testinit = _M_is_indeterminate(); - if (__testget) - { - if (__testout) - _M_really_overflow(); - else if (_M_in_cur != _M_filepos) - _M_file.seekoff(_M_in_cur - _M_filepos, - ios_base::cur, ios_base::in); - } - - if (__testinit || __testget) - { - const locale __loc = this->getloc(); - const __codecvt_type& __cvt = use_facet<__codecvt_type>(__loc); - - streamsize __elen = 0; - streamsize __ilen = 0; - if (__cvt.always_noconv()) - { - __elen = _M_file.xsgetn(reinterpret_cast<char*>(_M_in_beg), - _M_buf_size); - __ilen = __elen; - } - else - { - char* __buf = static_cast<char*>(__builtin_alloca(_M_buf_size)); - __elen = _M_file.xsgetn(__buf, _M_buf_size); - - const char* __eend; - char_type* __iend; - __res_type __r = __cvt.in(_M_state_cur, __buf, - __buf + __elen, __eend, _M_in_beg, - _M_in_beg + _M_buf_size, __iend); - if (__r == codecvt_base::ok) - __ilen = __iend - _M_in_beg; - else - { - // Unwind. - __ilen = 0; - _M_file.seekoff(-__elen, ios_base::cur, ios_base::in); - } - } - - if (0 < __ilen) - { - _M_set_determinate(__ilen); - if (__testout) - _M_out_cur = _M_in_cur; - __ret = traits_type::to_int_type(*_M_in_cur); - if (__bump) - _M_in_cur_move(1); - else if (_M_buf_size == 1) - { - // If we are synced with stdio, we have to unget the - // character we just read so that the file pointer - // doesn't move. - _M_file.sys_ungetc(*_M_in_cur); - _M_set_indeterminate(); - } - } - } - } + __ret = _M_in_end - _M_in_cur; _M_last_overflowed = false; return __ret; } @@ -410,7 +310,7 @@ namespace std { int_type __ret = traits_type::eof(); bool __testput = _M_out_cur && _M_out_beg < _M_out_end; - bool __testunbuffered = _M_file.is_open() && !_M_buf_size; + bool __testunbuffered = _M_file.is_open() && !_M_buf_size_opt; if (__testput || __testunbuffered) { diff --git a/contrib/libstdc++/include/bits/istream.tcc b/contrib/libstdc++/include/bits/istream.tcc index 636a73863598d..58e2caf02cdfc 100644 --- a/contrib/libstdc++/include/bits/istream.tcc +++ b/contrib/libstdc++/include/bits/istream.tcc @@ -54,13 +54,14 @@ namespace std __int_type __c = __sb->sgetc(); if (__in._M_check_facet(__in._M_fctype)) - while (__c != __eof - && __in._M_fctype->is(ctype_base::space, __c)) + while (!traits_type::eq_int_type(__c, __eof) + && __in._M_fctype->is(ctype_base::space, + traits_type::to_char_type(__c))) __c = __sb->snextc(); #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS //195. Should basic_istream::sentry's constructor ever set eofbit? - if (__c == __eof) + if (traits_type::eq_int_type(__c, __eof)) __in.setstate(ios_base::eofbit); #endif } @@ -521,7 +522,7 @@ namespace std { __c = this->rdbuf()->sbumpc(); // 27.6.1.1 paragraph 3 - if (__c != __eof) + if (!traits_type::eq_int_type(__c, __eof)) _M_gcount = 1; else this->setstate(ios_base::eofbit | ios_base::failbit); @@ -552,7 +553,7 @@ namespace std const int_type __eof = traits_type::eof(); int_type __bufval = this->rdbuf()->sbumpc(); // 27.6.1.1 paragraph 3 - if (__bufval != __eof) + if (!traits_type::eq_int_type(__bufval, __eof)) { _M_gcount = 1; __c = traits_type::to_char_type(__bufval); @@ -588,13 +589,15 @@ namespace std __streambuf_type* __sb = this->rdbuf(); int_type __c = __sb->sgetc(); - while (_M_gcount + 1 < __n && __c != __eof && __c != __idelim) + while (_M_gcount + 1 < __n + && !traits_type::eq_int_type(__c, __eof) + && !traits_type::eq_int_type(__c, __idelim)) { *__s++ = traits_type::to_char_type(__c); __c = __sb->snextc(); ++_M_gcount; } - if (__c == __eof) + if (traits_type::eq_int_type(__c, __eof)) this->setstate(ios_base::eofbit); } catch(exception& __fail) @@ -627,14 +630,17 @@ namespace std const int_type __eof = traits_type::eof(); __streambuf_type* __this_sb = this->rdbuf(); int_type __c = __this_sb->sgetc(); + char_type __c2 = traits_type::to_char_type(__c); - while (__c != __eof && __c != __idelim - && (__sb.sputc(traits_type::to_char_type(__c)) != __eof)) + while (!traits_type::eq_int_type(__c, __eof) + && !traits_type::eq_int_type(__c, __idelim) + && !traits_type::eq_int_type(__sb.sputc(__c2), __eof)) { ++_M_gcount; __c = __this_sb->snextc(); + __c2 = traits_type::to_char_type(__c); } - if (__c == __eof) + if (traits_type::eq_int_type(__c, __eof)) this->setstate(ios_base::eofbit); } catch(exception& __fail) @@ -667,19 +673,21 @@ namespace std __streambuf_type* __sb = this->rdbuf(); int_type __c = __sb->sgetc(); - while (_M_gcount + 1 < __n && __c != __eof && __c != __idelim) + while (_M_gcount + 1 < __n + && !traits_type::eq_int_type(__c, __eof) + && !traits_type::eq_int_type(__c, __idelim)) { *__s++ = traits_type::to_char_type(__c); __c = __sb->snextc(); ++_M_gcount; } - if (__c == __eof) + if (traits_type::eq_int_type(__c, __eof)) this->setstate(ios_base::eofbit); else { - if (__c == __idelim) + if (traits_type::eq_int_type(__c, __idelim)) { - __sb->snextc(); + __sb->sbumpc(); ++_M_gcount; } else @@ -708,27 +716,24 @@ namespace std { _M_gcount = 0; sentry __cerb(*this, true); - if (__cerb) + if (__cerb && __n > 0) { try { const int_type __eof = traits_type::eof(); __streambuf_type* __sb = this->rdbuf(); - int_type __c = __sb->sgetc(); + int_type __c; __n = min(__n, numeric_limits<streamsize>::max()); - while (_M_gcount < __n && __c !=__eof && __c != __delim) + while (_M_gcount < __n + && !traits_type::eq_int_type(__c = __sb->sbumpc(), __eof)) { - __c = __sb->snextc(); ++_M_gcount; + if (traits_type::eq_int_type(__c, __delim)) + break; } - if (__c == __eof) + if (traits_type::eq_int_type(__c, __eof)) this->setstate(ios_base::eofbit); - else if (__c == __delim) - { - __sb->snextc(); - ++_M_gcount; - } } catch(exception& __fail) { @@ -806,9 +811,8 @@ namespace std { try { - const int_type __eof = traits_type::eof(); streamsize __num = this->rdbuf()->in_avail(); - if (__num != static_cast<streamsize>(__eof)) + if (__num > 0) { __num = min(__num, __n); if (__num) @@ -843,7 +847,8 @@ namespace std { const int_type __eof = traits_type::eof(); __streambuf_type* __sb = this->rdbuf(); - if (!__sb || __sb->sputbackc(__c) == __eof) + if (!__sb + || traits_type::eq_int_type(__sb->sputbackc(__c), __eof)) this->setstate(ios_base::badbit); } catch(exception& __fail) @@ -873,7 +878,8 @@ namespace std { const int_type __eof = traits_type::eof(); __streambuf_type* __sb = this->rdbuf(); - if (!__sb || __eof == __sb->sungetc()) + if (!__sb + || traits_type::eq_int_type(__sb->sungetc(), __eof)) this->setstate(ios_base::badbit); } catch(exception& __fail) @@ -895,7 +901,7 @@ namespace std basic_istream<_CharT, _Traits>:: sync(void) { - int __ret = traits_type::eof(); + int __ret = -1; _M_gcount = 0; sentry __cerb(*this, true); if (__cerb) @@ -903,10 +909,13 @@ namespace std try { __streambuf_type* __sb = this->rdbuf(); - if (!__sb || __ret == __sb->pubsync()) - this->setstate(ios_base::badbit); - else - __ret = 0; + if (__sb) + { + if (__sb->pubsync() == -1) + this->setstate(ios_base::badbit); + else + __ret = 0; + } } catch(exception& __fail) { @@ -1186,16 +1195,18 @@ namespace std __streambuf_type* __sb = __in.rdbuf(); __int_type __c = __sb->sbumpc(); const __int_type __eof = _Traits::eof(); - __testdelim = __c == __idelim; + __testdelim = _Traits::eq_int_type(__c, __idelim); - while (__extracted <= __n && __c != __eof && !__testdelim) + while (__extracted <= __n + && !_Traits::eq_int_type(__c, __eof) + && !__testdelim) { __str += _Traits::to_char_type(__c); ++__extracted; __c = __sb->sbumpc(); - __testdelim = __c == __idelim; + __testdelim = _Traits::eq_int_type(__c, __idelim); } - if (__c == __eof) + if (_Traits::eq_int_type(__c, __eof)) __in.setstate(ios_base::eofbit); } if (!__extracted && !__testdelim) @@ -1221,8 +1232,10 @@ namespace std extern template istream& operator>>(istream&, unsigned char*); extern template istream& operator>>(istream&, signed char*); +#ifdef _GLIBCPP_USE_WCHAR_T extern template class basic_istream<wchar_t>; extern template wistream& ws(wistream&); extern template wistream& operator>>(wistream&, wchar_t&); extern template wistream& operator>>(wistream&, wchar_t*); +#endif } // namespace std diff --git a/contrib/libstdc++/include/bits/locale_facets.h b/contrib/libstdc++/include/bits/locale_facets.h index d63eb5dd2d5f8..159cecccdcb1a 100644 --- a/contrib/libstdc++/include/bits/locale_facets.h +++ b/contrib/libstdc++/include/bits/locale_facets.h @@ -55,6 +55,9 @@ namespace std # define _GLIBCPP_NUM_FACETS 14 #endif + template<typename _CharT, typename _Traits> + struct __pad; + // 22.2.1.1 Template class ctype // Include host and configuration specific ctype enums for ctype_base. #include <bits/ctype_base.h> @@ -652,6 +655,7 @@ namespace std virtual iter_type do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, bool&) const; + virtual iter_type do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, long&) const; @@ -697,6 +701,23 @@ namespace std template<typename _CharT, typename _InIter> locale::id num_get<_CharT, _InIter>::id; +#if 0 + // Partial specialization for istreambuf_iterator, so can use traits_type. + template<typename _CharT> + class num_get<_CharT, istreambuf_iterator<_CharT> >; + + iter_type + _M_extract_float(iter_type, iter_type, ios_base&, ios_base::iostate&, + string& __xtrc) const; + + iter_type + _M_extract_int(iter_type, iter_type, ios_base&, ios_base::iostate&, + string& __xtrc, int& __base) const; + + virtual iter_type + do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, bool&) const; +#endif + template<typename _CharT, typename _OutIter> class num_put : public locale::facet, public __num_base { @@ -1357,8 +1378,9 @@ namespace std { _M_initialize_moneypunct(); } explicit - moneypunct(__c_locale __cloc, size_t __refs = 0) : locale::facet(__refs) - { _M_initialize_moneypunct(__cloc); } + moneypunct(__c_locale __cloc, const char* __s, size_t __refs = 0) + : locale::facet(__refs) + { _M_initialize_moneypunct(__cloc, __s); } char_type decimal_point() const @@ -1438,7 +1460,8 @@ namespace std // For use at construction time only. void - _M_initialize_moneypunct(__c_locale __cloc = _S_c_locale); + _M_initialize_moneypunct(__c_locale __cloc = _S_c_locale, + const char* __name = NULL); }; template<typename _CharT, bool _Intl> @@ -1455,11 +1478,11 @@ namespace std template<> void - moneypunct<char, true>::_M_initialize_moneypunct(__c_locale __cloc); + moneypunct<char, true>::_M_initialize_moneypunct(__c_locale, const char*); template<> void - moneypunct<char, false>::_M_initialize_moneypunct(__c_locale __cloc); + moneypunct<char, false>::_M_initialize_moneypunct(__c_locale, const char*); #ifdef _GLIBCPP_USE_WCHAR_T template<> @@ -1470,11 +1493,13 @@ namespace std template<> void - moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale __cloc); + moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale, + const char*); template<> void - moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale __cloc); + moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale, + const char*); #endif template<typename _CharT, bool _Intl> diff --git a/contrib/libstdc++/include/bits/locale_facets.tcc b/contrib/libstdc++/include/bits/locale_facets.tcc index d362c33f87fbc..63e52c0058511 100644 --- a/contrib/libstdc++/include/bits/locale_facets.tcc +++ b/contrib/libstdc++/include/bits/locale_facets.tcc @@ -94,6 +94,7 @@ namespace std _M_extract_float(_InIter __beg, _InIter __end, ios_base& __io, ios_base::iostate& __err, string& __xtrc) const { + typedef char_traits<_CharT> __traits_type; const locale __loc = __io.getloc(); const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc); @@ -103,7 +104,8 @@ namespace std const char_type __minus = __ctype.widen('-'); int __pos = 0; char_type __c = *__beg; - if ((__c == __plus || __c == __minus) && __beg != __end) + if ((__traits_type::eq(__c, __plus) || __traits_type::eq(__c, __minus)) + && __beg != __end) { __xtrc += __ctype.narrow(__c, char()); ++__pos; @@ -113,7 +115,7 @@ namespace std // Next, strip leading zeros. const char_type __zero = __ctype.widen(_S_atoms[_M_zero]); bool __found_zero = false; - while (__c == __zero && __beg != __end) + while (__traits_type::eq(__c, __zero) && __beg != __end) { __c = *(++__beg); __found_zero = true; @@ -141,11 +143,10 @@ namespace std while (__beg != __end) { // Only look in digits. - typedef char_traits<_CharT> __traits_type; const char_type* __p = __traits_type::find(__watoms, 10, __c); // NB: strchr returns true for __c == 0x0 - if (__p && __c) + if (__p && !__traits_type::eq(__c, char_type())) { // Try first for acceptable digit; record it if found. ++__pos; @@ -153,7 +154,8 @@ namespace std ++__sep_pos; __c = *(++__beg); } - else if (__c == __sep && __check_grouping && !__found_dec) + else if (__traits_type::eq(__c, __sep) + && __check_grouping && !__found_dec) { // NB: Thousands separator at the beginning of a string // is a no-no, as is two consecutive thousands separators. @@ -169,7 +171,7 @@ namespace std break; } } - else if (__c == __dec && !__found_dec) + else if (__traits_type::eq(__c, __dec) && !__found_dec) { // According to the standard, if no grouping chars are seen, // no grouping check is applied. Therefore __found_grouping @@ -181,7 +183,8 @@ namespace std __c = *(++__beg); __found_dec = true; } - else if ((__c == __watoms[_M_e] || __c == __watoms[_M_E]) + else if ((__traits_type::eq(__c, __watoms[_M_e]) + || __traits_type::eq(__c, __watoms[_M_E])) && !__found_sci && __pos) { // Scientific notation. @@ -190,7 +193,8 @@ namespace std __c = *(++__beg); // Remove optional plus or minus sign, if they exist. - if (__c == __plus || __c == __minus) + if (__traits_type::eq(__c, __plus) + || __traits_type::eq(__c, __minus)) { ++__pos; __xtrc += __ctype.narrow(__c, char()); @@ -228,6 +232,7 @@ namespace std _M_extract_int(_InIter __beg, _InIter __end, ios_base& __io, ios_base::iostate& __err, string& __xtrc, int& __base) const { + typedef char_traits<_CharT> __traits_type; const locale __loc = __io.getloc(); const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc); @@ -241,10 +246,13 @@ namespace std else __base = 10; - // First check for sign. + // First check for sign. int __pos = 0; char_type __c = *__beg; - if ((__c == __ctype.widen('+') || __c == __ctype.widen('-')) + const char_type __plus = __ctype.widen('+'); + const char_type __minus = __ctype.widen('-'); + + if ((__traits_type::eq(__c, __plus) || __traits_type::eq(__c, __minus)) && __beg != __end) { __xtrc += __ctype.narrow(__c, char()); @@ -259,7 +267,7 @@ namespace std if (__base == 10) { bool __found_zero = false; - while (__c == __zero && __beg != __end) + while (__traits_type::eq(__c, __zero) && __beg != __end) { __c = *(++__beg); __found_zero = true; @@ -270,7 +278,9 @@ namespace std ++__pos; if (__basefield == 0) { - if ((__c == __x || __c == __X) && __beg != __end) + if ((__traits_type::eq(__c, __x) + || __traits_type::eq(__c, __X)) + && __beg != __end) { __xtrc += __ctype.narrow(__c, char()); ++__pos; @@ -284,12 +294,13 @@ namespace std } else if (__base == 16) { - if (__c == __zero && __beg != __end) + if (__traits_type::eq(__c, __zero) && __beg != __end) { __xtrc += _S_atoms[_M_zero]; ++__pos; __c = *(++__beg); - if ((__c == __x || __c == __X) && __beg != __end) + if ((__traits_type::eq(__c, __x) || __traits_type::eq(__c, __X)) + && __beg != __end) { __xtrc += __ctype.narrow(__c, char()); ++__pos; @@ -316,11 +327,10 @@ namespace std const char_type __sep = __np.thousands_sep(); while (__beg != __end) { - typedef char_traits<_CharT> __traits_type; const char_type* __p = __traits_type::find(__watoms, __len, __c); // NB: strchr returns true for __c == 0x0 - if (__p && __c) + if (__p && !__traits_type::eq(__c, char_type())) { // Try first for acceptable digit; record it if found. __xtrc += _S_atoms[__p - __watoms]; @@ -328,7 +338,7 @@ namespace std ++__sep_pos; __c = *(++__beg); } - else if (__c == __sep && __check_grouping) + else if (__traits_type::eq(__c, __sep) && __check_grouping) { // NB: Thousands separator at the beginning of a string // is a no-no, as is two consecutive thousands separators. @@ -394,7 +404,9 @@ namespace std // Parse bool values as alphanumeric else { - typedef basic_string<_CharT> __string_type; + typedef char_traits<_CharT> __traits_type; + typedef basic_string<_CharT> __string_type; + locale __loc = __io.getloc(); const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc); const __string_type __true = __np.truename(); @@ -407,8 +419,10 @@ namespace std for (size_t __n = 0; __beg != __end; ++__n) { char_type __c = *__beg++; - bool __testf = __n <= __falsen ? __c == __falses[__n] : false; - bool __testt = __n <= __truen ? __c == __trues[__n] : false; + bool __testf = __n <= __falsen + ? __traits_type::eq(__c, __falses[__n]) : false; + bool __testt = __n <= __truen + ? __traits_type::eq(__c, __trues[__n]) : false; if (!(__testf || __testt)) { __err |= ios_base::failbit; @@ -708,6 +722,7 @@ namespace std _M_widen_float(_OutIter __s, ios_base& __io, _CharT __fill, char* __cs, int __len) const { + typedef char_traits<_CharT> __traits_type; // [22.2.2.2.2] Stage 2, convert to char_type, using correct // numpunct.decimal_point() values for '.' and adding grouping. const locale __loc = __io.getloc(); @@ -723,7 +738,7 @@ namespace std // Replace decimal point. const _CharT* __p; const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc); - if (__p = char_traits<_CharT>::find(__ws, __len, __ctype.widen('.'))) + if (__p = __traits_type::find(__ws, __len, __ctype.widen('.'))) __ws[__p - __ws] = __np.decimal_point(); #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS @@ -744,7 +759,7 @@ namespace std // Tack on decimal part. if (__p) { - char_traits<_CharT>::copy(__p2, __p, __len - __declen); + __traits_type::copy(__p2, __p, __len - __declen); __newlen += __len - __declen; } @@ -816,13 +831,15 @@ namespace std _M_insert(_OutIter __s, ios_base& __io, _CharT __fill, const _CharT* __ws, int __len) const { + typedef char_traits<_CharT> __traits_type; // [22.2.2.2.2] Stage 3. streamsize __w = __io.width(); _CharT* __ws2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w)); if (__w > static_cast<streamsize>(__len)) { - __pad(__io, __fill, __ws2, __ws, __w, __len, true); + __pad<_CharT, __traits_type>::_S_pad(__io, __fill, __ws2, __ws, + __w, __len, true); __len = static_cast<int>(__w); // Switch strings. __ws = __ws2; @@ -845,7 +862,7 @@ namespace std if ((__flags & ios_base::boolalpha) == 0) { unsigned long __uv = __v; - __s = _M_convert_int(__s, __io, __fill, 'u', char_type(), __uv); + __s = _M_convert_int(__s, __io, __fill, 'u', char(), __uv); } else { @@ -866,14 +883,14 @@ namespace std _OutIter num_put<_CharT, _OutIter>:: do_put(iter_type __s, ios_base& __io, char_type __fill, long __v) const - { return _M_convert_int(__s, __io, __fill, 'd', char_type(), __v); } + { return _M_convert_int(__s, __io, __fill, 'd', char(), __v); } template<typename _CharT, typename _OutIter> _OutIter num_put<_CharT, _OutIter>:: do_put(iter_type __s, ios_base& __io, char_type __fill, unsigned long __v) const - { return _M_convert_int(__s, __io, __fill, 'u', char_type(), __v); } + { return _M_convert_int(__s, __io, __fill, 'u', char(), __v); } #ifdef _GLIBCPP_USE_LONG_LONG template<typename _CharT, typename _OutIter> @@ -894,7 +911,7 @@ namespace std _OutIter num_put<_CharT, _OutIter>:: do_put(iter_type __s, ios_base& __io, char_type __fill, double __v) const - { return _M_convert_float(__s, __io, __fill, char_type(), __v); } + { return _M_convert_float(__s, __io, __fill, char(), __v); } template<typename _CharT, typename _OutIter> _OutIter @@ -915,7 +932,7 @@ namespace std __io.flags(__flags & __fmt | (ios_base::hex | ios_base::showbase)); try { - __s = _M_convert_int(__s, __io, __fill, 'u', char_type(), + __s = _M_convert_int(__s, __io, __fill, 'u', char(), reinterpret_cast<unsigned long>(__v)); __io.flags(__flags); } @@ -1591,7 +1608,7 @@ namespace std const _CharT** __names, size_t __indexlen, ios_base::iostate& __err) const { - typedef char_traits<char_type> __traits_type; + typedef char_traits<_CharT> __traits_type; int* __matches = static_cast<int*>(__builtin_alloca(sizeof(int) * __indexlen)); size_t __nmatches = 0; size_t __pos = 0; @@ -1686,7 +1703,7 @@ namespace std do_get_weekday(iter_type __beg, iter_type __end, ios_base& __io, ios_base::iostate& __err, tm* __tm) const { - typedef char_traits<char_type> __traits_type; + typedef char_traits<_CharT> __traits_type; locale __loc = __io.getloc(); __timepunct<_CharT> const& __tp = use_facet<__timepunct<_CharT> >(__loc); const char_type* __days[7]; @@ -1729,7 +1746,7 @@ namespace std do_get_monthname(iter_type __beg, iter_type __end, ios_base& __io, ios_base::iostate& __err, tm* __tm) const { - typedef char_traits<char_type> __traits_type; + typedef char_traits<_CharT> __traits_type; locale __loc = __io.getloc(); __timepunct<_CharT> const& __tp = use_facet<__timepunct<_CharT> >(__loc); const char_type* __months[12]; @@ -1959,12 +1976,14 @@ namespace std _Tv __v, const __c_locale&, int __prec = -1) { int __ret; - const char* __old = setlocale(LC_ALL, "C"); + char* __old = strdup(setlocale(LC_ALL, NULL)); + setlocale(LC_ALL, "C"); if (__prec >= 0) __ret = snprintf(__out, __size, __fmt, __prec, __v); else __ret = snprintf(__out, __size, __fmt, __v); setlocale(LC_ALL, __old); + free(__old); return __ret; } #else @@ -1974,12 +1993,14 @@ namespace std const __c_locale&, int __prec = -1) { int __ret; - const char* __old = setlocale(LC_ALL, "C"); + char* __old = strdup(setlocale(LC_ALL, NULL)); + setlocale(LC_ALL, "C"); if (__prec >= 0) __ret = sprintf(__out, __fmt, __prec, __v); else __ret = sprintf(__out, __fmt, __v); setlocale(LC_ALL, __old); + free(__old); return __ret; } #endif @@ -1992,22 +2013,31 @@ namespace std // internal-adjusted objects are padded according to the rules below // concerning 0[xX] and +-, otherwise, exactly as right-adjusted // ones are. + + // NB: Of the two parameters, _CharT can be deduced from the + // function arguments. The other (_Traits) has to be explicitly specified. template<typename _CharT, typename _Traits> - void - __pad(ios_base& __io, _CharT __fill, _CharT* __news, const _CharT* __olds, - const streamsize __newlen, const streamsize __oldlen, - const bool __num) + struct __pad { - typedef _CharT char_type; - typedef _Traits traits_type; - typedef typename traits_type::int_type int_type; - - int_type __plen = static_cast<size_t>(__newlen - __oldlen); - char_type* __pads = static_cast<char_type*>(__builtin_alloca(sizeof(char_type) * __plen)); - traits_type::assign(__pads, __plen, __fill); + static void + _S_pad(ios_base& __io, _CharT __fill, _CharT* __news, + const _CharT* __olds, const streamsize __newlen, + const streamsize __oldlen, const bool __num); + }; - char_type* __beg; - char_type* __end; + template<typename _CharT, typename _Traits> + void + __pad<_CharT, _Traits>::_S_pad(ios_base& __io, _CharT __fill, + _CharT* __news, const _CharT* __olds, + const streamsize __newlen, + const streamsize __oldlen, const bool __num) + { + size_t __plen = static_cast<size_t>(__newlen - __oldlen); + _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __plen)); + _Traits::assign(__pads, __plen, __fill); + + _CharT* __beg; + _CharT* __end; size_t __mod = 0; size_t __beglen; //either __plen or __oldlen ios_base::fmtflags __adjust = __io.flags() & ios_base::adjustfield; @@ -2015,7 +2045,7 @@ namespace std if (__adjust == ios_base::left) { // Padding last. - __beg = const_cast<char_type*>(__olds); + __beg = const_cast<_CharT*>(__olds); __beglen = __oldlen; __end = __pads; } @@ -2026,12 +2056,14 @@ namespace std // Who came up with these rules, anyway? Jeeze. locale __loc = __io.getloc(); const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); - const char_type __minus = __ctype.widen('-'); - const char_type __plus = __ctype.widen('+'); - bool __testsign = __olds[0] == __minus || __olds[0] == __plus; - bool __testhex = __ctype.widen('0') == __olds[0] - && (__ctype.widen('x') == __olds[1] - || __ctype.widen('X') == __olds[1]); + const _CharT __minus = __ctype.widen('-'); + const _CharT __plus = __ctype.widen('+'); + bool __testsign = _Traits::eq(__olds[0], __minus) + || _Traits::eq(__olds[0], __plus); + + bool __testhex = _Traits::eq(__ctype.widen('0'), __olds[0]) + && (_Traits::eq(__ctype.widen('x'), __olds[1]) + || _Traits::eq(__ctype.widen('X'), __olds[1])); if (__testhex) { __news[0] = __olds[0]; @@ -2040,23 +2072,23 @@ namespace std __news += 2; __beg = __pads; __beglen = __plen; - __end = const_cast<char_type*>(__olds + __mod); + __end = const_cast<_CharT*>(__olds + __mod); } else if (__testsign) { - __news[0] = __olds[0] == __plus ? __plus : __minus; + _Traits::eq((__news[0] = __olds[0]), __plus) ? __plus : __minus; ++__mod; ++__news; __beg = __pads; __beglen = __plen; - __end = const_cast<char_type*>(__olds + __mod); + __end = const_cast<_CharT*>(__olds + __mod); } else { // Padding first. __beg = __pads; __beglen = __plen; - __end = const_cast<char_type*>(__olds); + __end = const_cast<_CharT*>(__olds); } } else @@ -2064,23 +2096,11 @@ namespace std // Padding first. __beg = __pads; __beglen = __plen; - __end = const_cast<char_type*>(__olds); + __end = const_cast<_CharT*>(__olds); } - traits_type::copy(__news, __beg, __beglen); - traits_type::copy(__news + __beglen, __end, __newlen - __beglen - __mod); - } - - // NB: Can't have default argument on non-member template, and - // num_put doesn't have a _Traits template parameter, so this - // forwarding template adds in the default template argument. - template<typename _CharT> - void - __pad(ios_base& __io, _CharT __fill, _CharT* __news, const _CharT* __olds, - const streamsize __newlen, const streamsize __oldlen, - const bool __num) - { - return __pad<_CharT, char_traits<_CharT> >(__io, __fill, __news, __olds, - __newlen, __oldlen, __num); + _Traits::copy(__news, __beg, __beglen); + _Traits::copy(__news + __beglen, __end, + __newlen - __beglen - __mod); } // Used by both numeric and monetary facets. @@ -2397,5 +2417,3 @@ namespace std } // namespace std #endif - - diff --git a/contrib/libstdc++/include/bits/ostream.tcc b/contrib/libstdc++/include/bits/ostream.tcc index d15b9f2afa3c0..e42eca29192f2 100644 --- a/contrib/libstdc++/include/bits/ostream.tcc +++ b/contrib/libstdc++/include/bits/ostream.tcc @@ -119,19 +119,11 @@ namespace std basic_ostream<_CharT, _Traits>::operator<<(__streambuf_type* __sbin) { sentry __cerb(*this); - if (__cerb) + if (__cerb && __sbin) { try { - streamsize __xtrct = 0; - if (__sbin) - { - __streambuf_type* __sbout = this->rdbuf(); - __xtrct = __copy_streambufs(*this, __sbin, __sbout); - } - else - this->setstate(ios_base::badbit); - if (!__xtrct) + if (!__copy_streambufs(*this, __sbin, this->rdbuf())) this->setstate(ios_base::failbit); } catch(exception& __fail) @@ -143,6 +135,8 @@ namespace std __throw_exception_again; } } + else if (!__sbin) + this->setstate(ios_base::badbit); return *this; } @@ -480,7 +474,8 @@ namespace std streamsize __len = 1; if (__w > __len) { - __pad(__out, __out.fill(), __pads, &__c, __w, __len, false); + __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __pads, + &__c, __w, __len, false); __len = __w; } __out.write(__pads, __len); @@ -515,7 +510,8 @@ namespace std streamsize __len = 1; if (__w > __len) { - __pad(__out, __out.fill(), __pads, &__c, __w, __len, false); + __pad<char, _Traits>::_S_pad(__out, __out.fill(), __pads, + &__c, __w, __len, false); __len = __w; } __out.write(__pads, __len); @@ -539,7 +535,7 @@ namespace std { typedef basic_ostream<_CharT, _Traits> __ostream_type; typename __ostream_type::sentry __cerb(__out); - if (__cerb) + if (__cerb && __s) { try { @@ -548,7 +544,8 @@ namespace std streamsize __len = static_cast<streamsize>(_Traits::length(__s)); if (__w > __len) { - __pad(__out, __out.fill(), __pads, __s, __w, __len, false); + __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __pads, + __s, __w, __len, false); __s = __pads; __len = __w; } @@ -564,6 +561,8 @@ namespace std __throw_exception_again; } } + else if (!__s) + __out.setstate(ios_base::badbit); return __out; } @@ -575,14 +574,14 @@ namespace std #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS // 167. Improper use of traits_type::length() // Note that this is only in 'Review' status. - typedef char_traits<char> __ctraits_type; + typedef char_traits<char> __traits_type; #endif typename __ostream_type::sentry __cerb(__out); - if (__cerb) + if (__cerb && __s) { - size_t __clen = __ctraits_type::length(__s); + size_t __clen = __traits_type::length(__s); _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * (__clen + 1))); - for (size_t __i = 0; __i <= __clen; ++__i) + for (size_t __i = 0; __i < __clen; ++__i) __ws[__i] = __out.widen(__s[__i]); _CharT* __str = __ws; @@ -594,7 +593,8 @@ namespace std if (__w > __len) { - __pad(__out, __out.fill(), __pads, __ws, __w, __len, false); + __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __pads, + __ws, __w, __len, false); __str = __pads; __len = __w; } @@ -610,6 +610,8 @@ namespace std __throw_exception_again; } } + else if (!__s) + __out.setstate(ios_base::badbit); return __out; } @@ -620,16 +622,18 @@ namespace std { typedef basic_ostream<char, _Traits> __ostream_type; typename __ostream_type::sentry __cerb(__out); - if (__cerb) + if (__cerb && __s) { try { streamsize __w = __out.width(); char* __pads = static_cast<char*>(__builtin_alloca(__w)); streamsize __len = static_cast<streamsize>(_Traits::length(__s)); + if (__w > __len) { - __pad(__out, __out.fill(), __pads, __s, __w, __len, false); + __pad<char, _Traits>::_S_pad(__out, __out.fill(), __pads, + __s, __w, __len, false); __s = __pads; __len = __w; } @@ -645,6 +649,8 @@ namespace std __throw_exception_again; } } + else if (!__s) + __out.setstate(ios_base::badbit); return __out; } @@ -667,7 +673,8 @@ namespace std #endif if (__w > __len) { - __pad(__out, __out.fill(), __pads, __s, __w, __len, false); + __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __pads, __s, + __w, __len, false); __s = __pads; __len = __w; } @@ -693,6 +700,7 @@ namespace std extern template ostream& operator<<(ostream&, const unsigned char*); extern template ostream& operator<<(ostream&, const signed char*); +#ifdef _GLIBCPP_USE_WCHAR_T extern template class basic_ostream<wchar_t>; extern template wostream& endl(wostream&); extern template wostream& ends(wostream&); @@ -701,4 +709,5 @@ namespace std extern template wostream& operator<<(wostream&, char); extern template wostream& operator<<(wostream&, const wchar_t*); extern template wostream& operator<<(wostream&, const char*); +#endif } // namespace std diff --git a/contrib/libstdc++/include/bits/sstream.tcc b/contrib/libstdc++/include/bits/sstream.tcc index e7419504d3e54..99eb6af125f57 100644 --- a/contrib/libstdc++/include/bits/sstream.tcc +++ b/contrib/libstdc++/include/bits/sstream.tcc @@ -95,13 +95,13 @@ namespace std __len *= 2; if (__testwrite) - __ret = this->sputc(__c); + __ret = this->sputc(traits_type::to_char_type(__c)); else if (__len <= _M_string.max_size()) { // Force-allocate, re-sync. _M_string = this->str(); _M_string.reserve(__len); - _M_buf_size = static_cast<int_type>(__len); + _M_buf_size = __len; _M_really_sync(_M_in_cur - _M_in_beg, _M_out_cur - _M_out_beg); *_M_out_cur = traits_type::to_char_type(__c); @@ -184,7 +184,7 @@ namespace std if (_M_buf_size) { - off_type __pos = __sp._M_position(); + off_type __pos = __sp; // Use streamoff operator to do conversion. char_type* __beg = NULL; char_type* __end = NULL; bool __testin = (ios_base::in & _M_mode & __mode) != 0; diff --git a/contrib/libstdc++/include/bits/stl_bvector.h b/contrib/libstdc++/include/bits/stl_bvector.h index 6cb6d9caf36fe..e48ad7d63fdaf 100644 --- a/contrib/libstdc++/include/bits/stl_bvector.h +++ b/contrib/libstdc++/include/bits/stl_bvector.h @@ -166,7 +166,7 @@ struct _Bit_iterator : public _Bit_iterator_base _Bit_iterator(_Bit_type * __x, unsigned int __y) : _Bit_iterator_base(__x, __y) {} - reference operator*() const { return reference(_M_p, 1U << _M_offset); } + reference operator*() const { return reference(_M_p, 1UL << _M_offset); } iterator& operator++() { _M_bump_up(); return *this; @@ -223,7 +223,7 @@ struct _Bit_const_iterator : public _Bit_iterator_base : _Bit_iterator_base(__x._M_p, __x._M_offset) {} const_reference operator*() const { - return _Bit_reference(_M_p, 1U << _M_offset); + return _Bit_reference(_M_p, 1UL << _M_offset); } const_iterator& operator++() { _M_bump_up(); diff --git a/contrib/libstdc++/include/bits/stl_deque.h b/contrib/libstdc++/include/bits/stl_deque.h index 5fa8d125e7561..ce6be7e4ce2f5 100644 --- a/contrib/libstdc++/include/bits/stl_deque.h +++ b/contrib/libstdc++/include/bits/stl_deque.h @@ -130,11 +130,6 @@ struct _Deque_iterator reference operator*() const { return *_M_cur; } pointer operator->() const { return _M_cur; } - difference_type operator-(const _Self& __x) const { - return difference_type(_S_buffer_size()) * (_M_node - __x._M_node - 1) + - (_M_cur - _M_first) + (__x._M_last - __x._M_cur); - } - _Self& operator++() { ++_M_cur; if (_M_cur == _M_last) { @@ -194,16 +189,6 @@ struct _Deque_iterator reference operator[](difference_type __n) const { return *(*this + __n); } - bool operator==(const _Self& __x) const { return _M_cur == __x._M_cur; } - bool operator!=(const _Self& __x) const { return !(*this == __x); } - bool operator<(const _Self& __x) const { - return (_M_node == __x._M_node) ? - (_M_cur < __x._M_cur) : (_M_node < __x._M_node); - } - bool operator>(const _Self& __x) const { return __x < *this; } - bool operator<=(const _Self& __x) const { return !(__x < *this); } - bool operator>=(const _Self& __x) const { return !(*this < __x); } - /** @if maint * Prepares to traverse new_node. Sets everything except _M_cur, which * should therefore be set by the caller immediately afterwards, based on @@ -217,6 +202,123 @@ struct _Deque_iterator } }; +// Note: we also provide overloads whose operands are of the same type in +// order to avoid ambiguos overload resolution when std::rel_ops operators +// are in scope (for additional details, see libstdc++/3628) +template <class _Tp, class _Ref, class _Ptr> +inline bool +operator==(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, + const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) +{ + return __x._M_cur == __y._M_cur; +} + +template <class _Tp, class _RefL, class _PtrL, class _RefR, class _PtrR> +inline bool +operator==(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, + const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) +{ + return __x._M_cur == __y._M_cur; +} + +template <class _Tp, class _Ref, class _Ptr> +inline bool +operator!=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, + const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) +{ + return !(__x == __y); +} + +template <class _Tp, class _RefL, class _PtrL, class _RefR, class _PtrR> +inline bool +operator!=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, + const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) +{ + return !(__x == __y); +} + +template <class _Tp, class _Ref, class _Ptr> +inline bool +operator<(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, + const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) +{ + return (__x._M_node == __y._M_node) ? + (__x._M_cur < __y._M_cur) : (__x._M_node < __y._M_node); +} + +template <class _Tp, class _RefL, class _PtrL, class _RefR, class _PtrR> +inline bool +operator<(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, + const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) +{ + return (__x._M_node == __y._M_node) ? + (__x._M_cur < __y._M_cur) : (__x._M_node < __y._M_node); +} + +template <class _Tp, class _Ref, class _Ptr> +inline bool +operator>(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, + const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) +{ + return __y < __x; +} + +template <class _Tp, class _RefL, class _PtrL, class _RefR, class _PtrR> +inline bool +operator>(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, + const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) +{ + return __y < __x; +} + +template <class _Tp, class _Ref, class _Ptr> +inline bool +operator<=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, + const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) +{ + return !(__y < __x); +} + +template <class _Tp, class _RefL, class _PtrL, class _RefR, class _PtrR> +inline bool +operator<=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, + const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) +{ + return !(__y < __x); +} + +template <class _Tp, class _Ref, class _Ptr> +inline bool +operator>=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, + const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) +{ + return !(__x < __y); +} + +template <class _Tp, class _RefL, class _PtrL, class _RefR, class _PtrR> +inline bool +operator>=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, + const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) +{ + return !(__x < __y); +} + +// _GLIBCPP_RESOLVE_LIB_DEFECTS +// According to the resolution of DR179 not only the various comparison +// operators but also operator- must accept mixed iterator/const_iterator +// parameters. +template <typename _Tp, typename _RefL, typename _PtrL, + typename _RefR, typename _PtrR> +inline typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type +operator-(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, + const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) +{ + return _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type + (_Deque_iterator<_Tp, _RefL, _PtrL>::_S_buffer_size()) * + (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first) + + (__y._M_last - __y._M_cur); +} + template <class _Tp, class _Ref, class _Ptr> inline _Deque_iterator<_Tp, _Ref, _Ptr> operator+(ptrdiff_t __n, const _Deque_iterator<_Tp, _Ref, _Ptr>& __x) diff --git a/contrib/libstdc++/include/bits/stl_iterator.h b/contrib/libstdc++/include/bits/stl_iterator.h index d8a6d8ca374ae..6fb0d81339f04 100644 --- a/contrib/libstdc++/include/bits/stl_iterator.h +++ b/contrib/libstdc++/include/bits/stl_iterator.h @@ -629,10 +629,6 @@ namespace __gnu_cxx operator-(const difference_type& __n) const { return __normal_iterator(_M_current - __n); } - difference_type - operator-(const __normal_iterator& __i) const - { return _M_current - __i._M_current; } - const _Iterator& base() const { return _M_current; } }; @@ -719,6 +715,16 @@ namespace __gnu_cxx const __normal_iterator<_Iterator, _Container>& __rhs) { return __lhs.base() >= __rhs.base(); } + // _GLIBCPP_RESOLVE_LIB_DEFECTS + // According to the resolution of DR179 not only the various comparison + // operators but also operator- must accept mixed iterator/const_iterator + // parameters. + template<typename _IteratorL, typename _IteratorR, typename _Container> + inline typename __normal_iterator<_IteratorL, _Container>::difference_type + operator-(const __normal_iterator<_IteratorL, _Container>& __lhs, + const __normal_iterator<_IteratorR, _Container>& __rhs) + { return __lhs.base() - __rhs.base(); } + template<typename _Iterator, typename _Container> inline __normal_iterator<_Iterator, _Container> operator+(typename __normal_iterator<_Iterator, _Container>::difference_type __n, diff --git a/contrib/libstdc++/include/bits/stl_pair.h b/contrib/libstdc++/include/bits/stl_pair.h index d689ccc8d27d6..b0411b2becc9e 100644 --- a/contrib/libstdc++/include/bits/stl_pair.h +++ b/contrib/libstdc++/include/bits/stl_pair.h @@ -95,7 +95,7 @@ inline bool operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) return __x.first == __y.first && __x.second == __y.second; } -/// http://gcc.gnu.org/onlinedocs/libstdc++/20_util/howto.html#pairlt +/// <http://gcc.gnu.org/onlinedocs/libstdc++/20_util/howto.html#pairlt> template <class _T1, class _T2> inline bool operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) { diff --git a/contrib/libstdc++/include/bits/streambuf.tcc b/contrib/libstdc++/include/bits/streambuf.tcc index 292999cfba318..2f790e902cb7c 100644 --- a/contrib/libstdc++/include/bits/streambuf.tcc +++ b/contrib/libstdc++/include/bits/streambuf.tcc @@ -40,7 +40,7 @@ namespace std { template<typename _CharT, typename _Traits> - const typename basic_streambuf<_CharT, _Traits>::int_type + const size_t basic_streambuf<_CharT, _Traits>::_S_pback_size; template<typename _CharT, typename _Traits> @@ -138,7 +138,7 @@ namespace std if (__ret < __n) { int_type __c = this->uflow(); - if (__c != traits_type::eof()) + if (!traits_type::eq_int_type(__c, traits_type::eof())) { traits_type::assign(*__s++, traits_type::to_char_type(__c)); ++__ret; @@ -177,7 +177,7 @@ namespace std if (__ret < __n) { int_type __c = this->overflow(traits_type::to_int_type(*__s)); - if (__c != traits_type::eof()) + if (!traits_type::eq_int_type(__c, traits_type::eof())) { ++__ret; ++__s; @@ -214,7 +214,7 @@ namespace std __sbin->_M_in_cur_move(__xtrct); if (__xtrct == __bufsize) { - if (__sbin->sgetc() == _Traits::eof()) + if (_Traits::eq_int_type(__sbin->sgetc(), _Traits::eof())) break; __bufsize = __sbin->in_avail(); } diff --git a/contrib/libstdc++/include/bits/streambuf_iterator.h b/contrib/libstdc++/include/bits/streambuf_iterator.h index 659caecb2aff2..152df9c6e4b99 100644 --- a/contrib/libstdc++/include/bits/streambuf_iterator.h +++ b/contrib/libstdc++/include/bits/streambuf_iterator.h @@ -69,13 +69,13 @@ namespace std public: istreambuf_iterator() throw() - : _M_sbuf(0), _M_c(-2) { } + : _M_sbuf(0), _M_c(traits_type::eof()) { } istreambuf_iterator(istream_type& __s) throw() - : _M_sbuf(__s.rdbuf()), _M_c(-2) { } + : _M_sbuf(__s.rdbuf()), _M_c(traits_type::eof()) { } istreambuf_iterator(streambuf_type* __s) throw() - : _M_sbuf(__s), _M_c(-2) { } + : _M_sbuf(__s), _M_c(traits_type::eof()) { } // NB: The result of operator*() on an end of stream is undefined. char_type @@ -85,21 +85,25 @@ namespace std istreambuf_iterator& operator++() { - if (_M_sbuf && _M_sbuf->sbumpc() == traits_type::eof()) + const int_type __eof = traits_type::eof(); + if (_M_sbuf && traits_type::eq_int_type(_M_sbuf->sbumpc(), __eof)) _M_sbuf = 0; else - _M_c = -2; + _M_c = __eof; return *this; } istreambuf_iterator operator++(int) { + const int_type __eof = traits_type::eof(); istreambuf_iterator __old = *this; - if (_M_sbuf && (__old._M_c = _M_sbuf->sbumpc()) == traits_type::eof()) + if (_M_sbuf + && traits_type::eq_int_type((__old._M_c = _M_sbuf->sbumpc()), + __eof)) _M_sbuf = 0; else - _M_c = -2; + _M_c = __eof; return __old; } @@ -110,8 +114,8 @@ namespace std equal(const istreambuf_iterator& __b) const { const int_type __eof = traits_type::eof(); - bool __thiseof = _M_get() == __eof; - bool __beof = __b._M_get() == __eof; + bool __thiseof = traits_type::eq_int_type(_M_get(), __eof); + bool __beof = traits_type::eq_int_type(__b._M_get(), __eof); return (__thiseof && __beof || (!__thiseof && !__beof)); } #endif @@ -120,13 +124,14 @@ namespace std int_type _M_get() const { - int_type __ret = traits_type::eof(); + const int_type __eof = traits_type::eof(); + int_type __ret = __eof; if (_M_sbuf) { - if (_M_c != static_cast<int_type>(-2)) + if (!traits_type::eq_int_type(_M_c, __eof)) __ret = _M_c; else - if ((__ret = _M_sbuf->sgetc()) == traits_type::eof()) + if (traits_type::eq_int_type((__ret = _M_sbuf->sgetc()), __eof)) _M_sbuf = 0; } return __ret; |