From 022ea294da39a09fa2157b830de3bbbe3044eff2 Mon Sep 17 00:00:00 2001 From: paolo Date: Tue, 24 Apr 2007 18:57:12 +0000 Subject: [PATCH] 2007-04-24 Paolo Carlini * include/bits/locale_facets.h (class collate, class collate_byname): Move... * include/bits/locale_classes.h: ... here. * include/bits/locale_facets.tcc (locale::combine, locale::operator(), has_facet, use_facet, collate::_M_compare, collate::_M_transform, collate::do_compare, collate::do_transform, collate::do_hash): Move... * include/bits/locale_classes.tcc: ... here, new. * include/Makefile.am: Add. * testsuite/util/testsuite_abi.h: Include . * include/std/locale: Tweak. * include/std/istream: Likewise. * include/std/ostream: Likewise. * include/bits/codecvt.h: Likewise. * include/Makefile.in: Regenerate. * include/bits/codecvt.h: Adjust extern template declarations. * include/bits/ostream_insert.h: Likewise. * include/bits/ostream.tcc: Likewise. * include/bits/locale_facets.h: Do not include . * include/std/fstream: Do it here. * include/bits/locale_facets_nonio.h: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@124114 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 25 ++ libstdc++-v3/include/Makefile.am | 1 + libstdc++-v3/include/Makefile.in | 1 + libstdc++-v3/include/bits/codecvt.h | 29 ++- libstdc++-v3/include/bits/locale_classes.h | 273 +++++++++++++++++++++- libstdc++-v3/include/bits/locale_classes.tcc | 243 +++++++++++++++++++ libstdc++-v3/include/bits/locale_facets.h | 221 +----------------- libstdc++-v3/include/bits/locale_facets.tcc | 231 ------------------ libstdc++-v3/include/bits/locale_facets_nonio.h | 11 +- libstdc++-v3/include/bits/locale_facets_nonio.tcc | 3 + libstdc++-v3/include/bits/ostream.tcc | 3 - libstdc++-v3/include/bits/ostream_insert.h | 12 + libstdc++-v3/include/std/fstream | 5 +- libstdc++-v3/include/std/istream | 1 - libstdc++-v3/include/std/locale | 8 +- libstdc++-v3/include/std/ostream | 1 - libstdc++-v3/testsuite/util/testsuite_abi.h | 3 +- 17 files changed, 595 insertions(+), 476 deletions(-) create mode 100644 libstdc++-v3/include/bits/locale_classes.tcc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 55b90855a5a..fb67e0c3b0c 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,28 @@ +2007-04-24 Paolo Carlini + + * include/bits/locale_facets.h (class collate, class collate_byname): + Move... + * include/bits/locale_classes.h: ... here. + * include/bits/locale_facets.tcc (locale::combine, locale::operator(), + has_facet, use_facet, collate::_M_compare, collate::_M_transform, + collate::do_compare, collate::do_transform, collate::do_hash): Move... + * include/bits/locale_classes.tcc: ... here, new. + * include/Makefile.am: Add. + * testsuite/util/testsuite_abi.h: Include . + * include/std/locale: Tweak. + * include/std/istream: Likewise. + * include/std/ostream: Likewise. + * include/bits/codecvt.h: Likewise. + * include/Makefile.in: Regenerate. + + * include/bits/codecvt.h: Adjust extern template declarations. + * include/bits/ostream_insert.h: Likewise. + * include/bits/ostream.tcc: Likewise. + + * include/bits/locale_facets.h: Do not include . + * include/std/fstream: Do it here. + * include/bits/locale_facets_nonio.h: Likewise. + 2007-04-23 Paolo Carlini * include/bits/locale_facets.h (class time_base, diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index 2ce67ab7eff..75be19a5f78 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -89,6 +89,7 @@ bits_headers = \ ${bits_srcdir}/istream.tcc \ ${bits_srcdir}/list.tcc \ ${bits_srcdir}/locale_classes.h \ + ${bits_srcdir}/locale_classes.tcc \ ${bits_srcdir}/locale_facets.h \ ${bits_srcdir}/locale_facets.tcc \ ${bits_srcdir}/locale_facets_nonio.h \ diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in index b382004914f..5b4ad599218 100644 --- a/libstdc++-v3/include/Makefile.in +++ b/libstdc++-v3/include/Makefile.in @@ -323,6 +323,7 @@ bits_headers = \ ${bits_srcdir}/istream.tcc \ ${bits_srcdir}/list.tcc \ ${bits_srcdir}/locale_classes.h \ + ${bits_srcdir}/locale_classes.tcc \ ${bits_srcdir}/locale_facets.h \ ${bits_srcdir}/locale_facets.tcc \ ${bits_srcdir}/locale_facets_nonio.h \ diff --git a/libstdc++-v3/include/bits/codecvt.h b/libstdc++-v3/include/bits/codecvt.h index d417a6ffcc4..930c798331a 100644 --- a/libstdc++-v3/include/bits/codecvt.h +++ b/libstdc++-v3/include/bits/codecvt.h @@ -1,6 +1,6 @@ // Locale support (codecvt) -*- C++ -*- -// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 +// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -469,6 +469,33 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ~codecvt_byname() { } }; + // Inhibit implicit instantiations for required instantiations, + // which are defined via explicit instantiations elsewhere. + // NB: This syntax is a GNU extension. +#if _GLIBCXX_EXTERN_TEMPLATE + extern template class codecvt_byname; + + extern template + const codecvt& + use_facet >(const locale&); + + extern template + bool + has_facet >(const locale&); + +#ifdef _GLIBCXX_USE_WCHAR_T + extern template class codecvt_byname; + + extern template + const codecvt& + use_facet >(const locale&); + + extern template + bool + has_facet >(const locale&); +#endif +#endif + _GLIBCXX_END_NAMESPACE #endif // _CODECVT_H diff --git a/libstdc++-v3/include/bits/locale_classes.h b/libstdc++-v3/include/bits/locale_classes.h index 547e21d9b43..8dc7d82219b 100644 --- a/libstdc++-v3/include/bits/locale_classes.h +++ b/libstdc++-v3/include/bits/locale_classes.h @@ -1,6 +1,7 @@ // Locale support -*- C++ -*- -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, +// 2006, 2007 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -561,22 +562,270 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _M_install_cache(const facet*, size_t); }; + + /** + * @brief Test for the presence of a facet. + * + * has_facet tests the locale argument for the presence of the facet type + * provided as the template parameter. Facets derived from the facet + * parameter will also return true. + * + * @param Facet The facet type to test the presence of. + * @param locale The locale to test. + * @return true if locale contains a facet of type Facet, else false. + */ template - locale::locale(const locale& __other, _Facet* __f) + inline bool + has_facet(const locale& __loc) throw() { - _M_impl = new _Impl(*__other._M_impl, 1); + const size_t __i = _Facet::id._M_id(); + const locale::facet** __facets = __loc._M_impl->_M_facets; + return (__i < __loc._M_impl->_M_facets_size && __facets[__i]); + } - try - { _M_impl->_M_install_facet(&_Facet::id, __f); } - catch(...) - { - _M_impl->_M_remove_reference(); - __throw_exception_again; - } - delete [] _M_impl->_M_names[0]; - _M_impl->_M_names[0] = 0; // Unnamed. + /** + * @brief Return a facet. + * + * use_facet looks for and returns a reference to a facet of type Facet + * where Facet is the template parameter. If has_facet(locale) is true, + * there is a suitable facet to return. It throws std::bad_cast if the + * locale doesn't contain a facet of type Facet. + * + * @param Facet The facet type to access. + * @param locale The locale to use. + * @return Reference to facet of type Facet. + * @throw std::bad_cast if locale doesn't contain a facet of type Facet. + */ + template + inline const _Facet& + use_facet(const locale& __loc) + { + const size_t __i = _Facet::id._M_id(); + const locale::facet** __facets = __loc._M_impl->_M_facets; + if (!(__i < __loc._M_impl->_M_facets_size && __facets[__i])) + __throw_bad_cast(); + return static_cast(*__facets[__i]); } + + /** + * @brief Facet for localized string comparison. + * + * This facet encapsulates the code to compare strings in a localized + * manner. + * + * The collate template uses protected virtual functions to provide + * the actual results. The public accessors forward the call to + * the virtual functions. These virtual functions are hooks for + * developers to implement the behavior they require from the + * collate facet. + */ + template + class collate : public locale::facet + { + public: + // Types: + //@{ + /// Public typedefs + typedef _CharT char_type; + typedef basic_string<_CharT> string_type; + //@} + + protected: + // Underlying "C" library locale information saved from + // initialization, needed by collate_byname as well. + __c_locale _M_c_locale_collate; + + public: + /// Numpunct facet id. + static locale::id id; + + /** + * @brief Constructor performs initialization. + * + * This is the constructor provided by the standard. + * + * @param refs Passed to the base facet class. + */ + explicit + collate(size_t __refs = 0) + : facet(__refs), _M_c_locale_collate(_S_get_c_locale()) + { } + + /** + * @brief Internal constructor. Not for general use. + * + * This is a constructor for use by the library itself to set up new + * locales. + * + * @param cloc The "C" locale. + * @param refs Passed to the base facet class. + */ + explicit + collate(__c_locale __cloc, size_t __refs = 0) + : facet(__refs), _M_c_locale_collate(_S_clone_c_locale(__cloc)) + { } + + /** + * @brief Compare two strings. + * + * This function compares two strings and returns the result by calling + * collate::do_compare(). + * + * @param lo1 Start of string 1. + * @param hi1 End of string 1. + * @param lo2 Start of string 2. + * @param hi2 End of string 2. + * @return 1 if string1 > string2, -1 if string1 < string2, else 0. + */ + int + compare(const _CharT* __lo1, const _CharT* __hi1, + const _CharT* __lo2, const _CharT* __hi2) const + { return this->do_compare(__lo1, __hi1, __lo2, __hi2); } + + /** + * @brief Transform string to comparable form. + * + * This function is a wrapper for strxfrm functionality. It takes the + * input string and returns a modified string that can be directly + * compared to other transformed strings. In the "C" locale, this + * function just returns a copy of the input string. In some other + * locales, it may replace two chars with one, change a char for + * another, etc. It does so by returning collate::do_transform(). + * + * @param lo Start of string. + * @param hi End of string. + * @return Transformed string_type. + */ + string_type + transform(const _CharT* __lo, const _CharT* __hi) const + { return this->do_transform(__lo, __hi); } + + /** + * @brief Return hash of a string. + * + * This function computes and returns a hash on the input string. It + * does so by returning collate::do_hash(). + * + * @param lo Start of string. + * @param hi End of string. + * @return Hash value. + */ + long + hash(const _CharT* __lo, const _CharT* __hi) const + { return this->do_hash(__lo, __hi); } + + // Used to abstract out _CharT bits in virtual member functions, below. + int + _M_compare(const _CharT*, const _CharT*) const; + + size_t + _M_transform(_CharT*, const _CharT*, size_t) const; + + protected: + /// Destructor. + virtual + ~collate() + { _S_destroy_c_locale(_M_c_locale_collate); } + + /** + * @brief Compare two strings. + * + * This function is a hook for derived classes to change the value + * returned. @see compare(). + * + * @param lo1 Start of string 1. + * @param hi1 End of string 1. + * @param lo2 Start of string 2. + * @param hi2 End of string 2. + * @return 1 if string1 > string2, -1 if string1 < string2, else 0. + */ + virtual int + do_compare(const _CharT* __lo1, const _CharT* __hi1, + const _CharT* __lo2, const _CharT* __hi2) const; + + /** + * @brief Transform string to comparable form. + * + * This function is a hook for derived classes to change the value + * returned. + * + * @param lo1 Start of string 1. + * @param hi1 End of string 1. + * @param lo2 Start of string 2. + * @param hi2 End of string 2. + * @return 1 if string1 > string2, -1 if string1 < string2, else 0. + */ + virtual string_type + do_transform(const _CharT* __lo, const _CharT* __hi) const; + + /** + * @brief Return hash of a string. + * + * This function computes and returns a hash on the input string. This + * function is a hook for derived classes to change the value returned. + * + * @param lo Start of string. + * @param hi End of string. + * @return Hash value. + */ + virtual long + do_hash(const _CharT* __lo, const _CharT* __hi) const; + }; + + template + locale::id collate<_CharT>::id; + + // Specializations. + template<> + int + collate::_M_compare(const char*, const char*) const; + + template<> + size_t + collate::_M_transform(char*, const char*, size_t) const; + +#ifdef _GLIBCXX_USE_WCHAR_T + template<> + int + collate::_M_compare(const wchar_t*, const wchar_t*) const; + + template<> + size_t + collate::_M_transform(wchar_t*, const wchar_t*, size_t) const; +#endif + + /// @brief class collate_byname [22.2.4.2]. + template + class collate_byname : public collate<_CharT> + { + public: + //@{ + /// Public typedefs + typedef _CharT char_type; + typedef basic_string<_CharT> string_type; + //@} + + explicit + collate_byname(const char* __s, size_t __refs = 0) + : collate<_CharT>(__refs) + { + if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0) + { + this->_S_destroy_c_locale(this->_M_c_locale_collate); + this->_S_create_c_locale(this->_M_c_locale_collate, __s); + } + } + + protected: + virtual + ~collate_byname() { } + }; + _GLIBCXX_END_NAMESPACE +#ifndef _GLIBCXX_EXPORT_TEMPLATE +# include +#endif + #endif diff --git a/libstdc++-v3/include/bits/locale_classes.tcc b/libstdc++-v3/include/bits/locale_classes.tcc new file mode 100644 index 00000000000..c1e698983cd --- /dev/null +++ b/libstdc++-v3/include/bits/locale_classes.tcc @@ -0,0 +1,243 @@ +// Locale support -*- C++ -*- + +// Copyright (C) 2007 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 +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file locale_classes.tcc + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +// +// ISO C++ 14882: 22.1 Locales +// + +#ifndef _LOCALE_CLASSES_TCC +#define _LOCALE_CLASSES_TCC 1 + +#pragma GCC system_header + +_GLIBCXX_BEGIN_NAMESPACE(std) + + template + locale::locale(const locale& __other, _Facet* __f) + { + _M_impl = new _Impl(*__other._M_impl, 1); + + try + { _M_impl->_M_install_facet(&_Facet::id, __f); } + catch(...) + { + _M_impl->_M_remove_reference(); + __throw_exception_again; + } + delete [] _M_impl->_M_names[0]; + _M_impl->_M_names[0] = 0; // Unnamed. + } + + template + locale + locale::combine(const locale& __other) const + { + _Impl* __tmp = new _Impl(*_M_impl, 1); + try + { + __tmp->_M_replace_facet(__other._M_impl, &_Facet::id); + } + catch(...) + { + __tmp->_M_remove_reference(); + __throw_exception_again; + } + return locale(__tmp); + } + + template + bool + locale::operator()(const basic_string<_CharT, _Traits, _Alloc>& __s1, + const basic_string<_CharT, _Traits, _Alloc>& __s2) const + { + typedef std::collate<_CharT> __collate_type; + const __collate_type& __collate = use_facet<__collate_type>(*this); + return (__collate.compare(__s1.data(), __s1.data() + __s1.length(), + __s2.data(), __s2.data() + __s2.length()) < 0); + } + + + // Generic version does nothing. + template + int + collate<_CharT>::_M_compare(const _CharT*, const _CharT*) const + { return 0; } + + // Generic version does nothing. + template + size_t + collate<_CharT>::_M_transform(_CharT*, const _CharT*, size_t) const + { return 0; } + + template + int + collate<_CharT>:: + do_compare(const _CharT* __lo1, const _CharT* __hi1, + const _CharT* __lo2, const _CharT* __hi2) const + { + // strcoll assumes zero-terminated strings so we make a copy + // and then put a zero at the end. + const string_type __one(__lo1, __hi1); + const string_type __two(__lo2, __hi2); + + const _CharT* __p = __one.c_str(); + const _CharT* __pend = __one.data() + __one.length(); + const _CharT* __q = __two.c_str(); + const _CharT* __qend = __two.data() + __two.length(); + + // strcoll stops when it sees a nul character so we break + // the strings into zero-terminated substrings and pass those + // to strcoll. + for (;;) + { + const int __res = _M_compare(__p, __q); + if (__res) + return __res; + + __p += char_traits<_CharT>::length(__p); + __q += char_traits<_CharT>::length(__q); + if (__p == __pend && __q == __qend) + return 0; + else if (__p == __pend) + return -1; + else if (__q == __qend) + return 1; + + __p++; + __q++; + } + } + + template + typename collate<_CharT>::string_type + collate<_CharT>:: + do_transform(const _CharT* __lo, const _CharT* __hi) const + { + string_type __ret; + + // strxfrm assumes zero-terminated strings so we make a copy + const string_type __str(__lo, __hi); + + const _CharT* __p = __str.c_str(); + const _CharT* __pend = __str.data() + __str.length(); + + size_t __len = (__hi - __lo) * 2; + + _CharT* __c = new _CharT[__len]; + + try + { + // strxfrm stops when it sees a nul character so we break + // the string into zero-terminated substrings and pass those + // to strxfrm. + for (;;) + { + // First try a buffer perhaps big enough. + size_t __res = _M_transform(__c, __p, __len); + // If the buffer was not large enough, try again with the + // correct size. + if (__res >= __len) + { + __len = __res + 1; + delete [] __c, __c = 0; + __c = new _CharT[__len]; + __res = _M_transform(__c, __p, __len); + } + + __ret.append(__c, __res); + __p += char_traits<_CharT>::length(__p); + if (__p == __pend) + break; + + __p++; + __ret.push_back(_CharT()); + } + } + catch(...) + { + delete [] __c; + __throw_exception_again; + } + + delete [] __c; + + return __ret; + } + + template + long + collate<_CharT>:: + do_hash(const _CharT* __lo, const _CharT* __hi) const + { + unsigned long __val = 0; + for (; __lo < __hi; ++__lo) + __val = + *__lo + ((__val << 7) + | (__val >> (__gnu_cxx::__numeric_traits:: + __digits - 7))); + return static_cast(__val); + } + + // Inhibit implicit instantiations for required instantiations, + // which are defined via explicit instantiations elsewhere. + // NB: This syntax is a GNU extension. +#if _GLIBCXX_EXTERN_TEMPLATE + extern template class collate; + extern template class collate_byname; + + extern template + const collate& + use_facet >(const locale&); + + extern template + bool + has_facet >(const locale&); + +#ifdef _GLIBCXX_USE_WCHAR_T + extern template class collate; + extern template class collate_byname; + + extern template + const collate& + use_facet >(const locale&); + + extern template + bool + has_facet >(const locale&); +#endif +#endif + +_GLIBCXX_END_NAMESPACE + +#endif diff --git a/libstdc++-v3/include/bits/locale_facets.h b/libstdc++-v3/include/bits/locale_facets.h index e5fa9ad939d..42865a69c37 100644 --- a/libstdc++-v3/include/bits/locale_facets.h +++ b/libstdc++-v3/include/bits/locale_facets.h @@ -1556,9 +1556,6 @@ _GLIBCXX_END_NAMESPACE // Include host and configuration specific ctype inlines. #include -// 22.2.1.5 Template class codecvt -#include - _GLIBCXX_BEGIN_NAMESPACE(std) // 22.2.2 The numeric category. @@ -2546,220 +2543,6 @@ _GLIBCXX_BEGIN_LDBL_NAMESPACE _GLIBCXX_END_LDBL_NAMESPACE - /** - * @brief Facet for localized string comparison. - * - * This facet encapsulates the code to compare strings in a localized - * manner. - * - * The collate template uses protected virtual functions to provide - * the actual results. The public accessors forward the call to - * the virtual functions. These virtual functions are hooks for - * developers to implement the behavior they require from the - * collate facet. - */ - template - class collate : public locale::facet - { - public: - // Types: - //@{ - /// Public typedefs - typedef _CharT char_type; - typedef basic_string<_CharT> string_type; - //@} - - protected: - // Underlying "C" library locale information saved from - // initialization, needed by collate_byname as well. - __c_locale _M_c_locale_collate; - - public: - /// Numpunct facet id. - static locale::id id; - - /** - * @brief Constructor performs initialization. - * - * This is the constructor provided by the standard. - * - * @param refs Passed to the base facet class. - */ - explicit - collate(size_t __refs = 0) - : facet(__refs), _M_c_locale_collate(_S_get_c_locale()) - { } - - /** - * @brief Internal constructor. Not for general use. - * - * This is a constructor for use by the library itself to set up new - * locales. - * - * @param cloc The "C" locale. - * @param refs Passed to the base facet class. - */ - explicit - collate(__c_locale __cloc, size_t __refs = 0) - : facet(__refs), _M_c_locale_collate(_S_clone_c_locale(__cloc)) - { } - - /** - * @brief Compare two strings. - * - * This function compares two strings and returns the result by calling - * collate::do_compare(). - * - * @param lo1 Start of string 1. - * @param hi1 End of string 1. - * @param lo2 Start of string 2. - * @param hi2 End of string 2. - * @return 1 if string1 > string2, -1 if string1 < string2, else 0. - */ - int - compare(const _CharT* __lo1, const _CharT* __hi1, - const _CharT* __lo2, const _CharT* __hi2) const - { return this->do_compare(__lo1, __hi1, __lo2, __hi2); } - - /** - * @brief Transform string to comparable form. - * - * This function is a wrapper for strxfrm functionality. It takes the - * input string and returns a modified string that can be directly - * compared to other transformed strings. In the "C" locale, this - * function just returns a copy of the input string. In some other - * locales, it may replace two chars with one, change a char for - * another, etc. It does so by returning collate::do_transform(). - * - * @param lo Start of string. - * @param hi End of string. - * @return Transformed string_type. - */ - string_type - transform(const _CharT* __lo, const _CharT* __hi) const - { return this->do_transform(__lo, __hi); } - - /** - * @brief Return hash of a string. - * - * This function computes and returns a hash on the input string. It - * does so by returning collate::do_hash(). - * - * @param lo Start of string. - * @param hi End of string. - * @return Hash value. - */ - long - hash(const _CharT* __lo, const _CharT* __hi) const - { return this->do_hash(__lo, __hi); } - - // Used to abstract out _CharT bits in virtual member functions, below. - int - _M_compare(const _CharT*, const _CharT*) const; - - size_t - _M_transform(_CharT*, const _CharT*, size_t) const; - - protected: - /// Destructor. - virtual - ~collate() - { _S_destroy_c_locale(_M_c_locale_collate); } - - /** - * @brief Compare two strings. - * - * This function is a hook for derived classes to change the value - * returned. @see compare(). - * - * @param lo1 Start of string 1. - * @param hi1 End of string 1. - * @param lo2 Start of string 2. - * @param hi2 End of string 2. - * @return 1 if string1 > string2, -1 if string1 < string2, else 0. - */ - virtual int - do_compare(const _CharT* __lo1, const _CharT* __hi1, - const _CharT* __lo2, const _CharT* __hi2) const; - - /** - * @brief Transform string to comparable form. - * - * This function is a hook for derived classes to change the value - * returned. - * - * @param lo1 Start of string 1. - * @param hi1 End of string 1. - * @param lo2 Start of string 2. - * @param hi2 End of string 2. - * @return 1 if string1 > string2, -1 if string1 < string2, else 0. - */ - virtual string_type - do_transform(const _CharT* __lo, const _CharT* __hi) const; - - /** - * @brief Return hash of a string. - * - * This function computes and returns a hash on the input string. This - * function is a hook for derived classes to change the value returned. - * - * @param lo Start of string. - * @param hi End of string. - * @return Hash value. - */ - virtual long - do_hash(const _CharT* __lo, const _CharT* __hi) const; - }; - - template - locale::id collate<_CharT>::id; - - // Specializations. - template<> - int - collate::_M_compare(const char*, const char*) const; - - template<> - size_t - collate::_M_transform(char*, const char*, size_t) const; - -#ifdef _GLIBCXX_USE_WCHAR_T - template<> - int - collate::_M_compare(const wchar_t*, const wchar_t*) const; - - template<> - size_t - collate::_M_transform(wchar_t*, const wchar_t*, size_t) const; -#endif - - /// @brief class collate_byname [22.2.4.2]. - template - class collate_byname : public collate<_CharT> - { - public: - //@{ - /// Public typedefs - typedef _CharT char_type; - typedef basic_string<_CharT> string_type; - //@} - - explicit - collate_byname(const char* __s, size_t __refs = 0) - : collate<_CharT>(__refs) - { - if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0) - { - this->_S_destroy_c_locale(this->_M_c_locale_collate); - this->_S_create_c_locale(this->_M_c_locale_collate, __s); - } - } - - protected: - virtual - ~collate_byname() { } - }; - // Subclause convenience interfaces, inlines. // NB: These are inline because, when used in a loop, some compilers // can hoist the body out of the loop; then it's just as fast as the @@ -2845,4 +2628,8 @@ _GLIBCXX_END_LDBL_NAMESPACE _GLIBCXX_END_NAMESPACE +#ifndef _GLIBCXX_EXPORT_TEMPLATE +# include +#endif + #endif diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index d0b0a96fadc..481362af15f 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -41,78 +41,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) - template - locale - locale::combine(const locale& __other) const - { - _Impl* __tmp = new _Impl(*_M_impl, 1); - try - { - __tmp->_M_replace_facet(__other._M_impl, &_Facet::id); - } - catch(...) - { - __tmp->_M_remove_reference(); - __throw_exception_again; - } - return locale(__tmp); - } - - template - bool - locale::operator()(const basic_string<_CharT, _Traits, _Alloc>& __s1, - const basic_string<_CharT, _Traits, _Alloc>& __s2) const - { - typedef std::collate<_CharT> __collate_type; - const __collate_type& __collate = use_facet<__collate_type>(*this); - return (__collate.compare(__s1.data(), __s1.data() + __s1.length(), - __s2.data(), __s2.data() + __s2.length()) < 0); - } - - /** - * @brief Test for the presence of a facet. - * - * has_facet tests the locale argument for the presence of the facet type - * provided as the template parameter. Facets derived from the facet - * parameter will also return true. - * - * @param Facet The facet type to test the presence of. - * @param locale The locale to test. - * @return true if locale contains a facet of type Facet, else false. - */ - template - inline bool - has_facet(const locale& __loc) throw() - { - const size_t __i = _Facet::id._M_id(); - const locale::facet** __facets = __loc._M_impl->_M_facets; - return (__i < __loc._M_impl->_M_facets_size && __facets[__i]); - } - - /** - * @brief Return a facet. - * - * use_facet looks for and returns a reference to a facet of type Facet - * where Facet is the template parameter. If has_facet(locale) is true, - * there is a suitable facet to return. It throws std::bad_cast if the - * locale doesn't contain a facet of type Facet. - * - * @param Facet The facet type to access. - * @param locale The locale to use. - * @return Reference to facet of type Facet. - * @throw std::bad_cast if locale doesn't contain a facet of type Facet. - */ - template - inline const _Facet& - use_facet(const locale& __loc) - { - const size_t __i = _Facet::id._M_id(); - const locale::facet** __facets = __loc._M_impl->_M_facets; - if (!(__i < __loc._M_impl->_M_facets_size && __facets[__i])) - __throw_bad_cast(); - return static_cast(*__facets[__i]); - } - // Routine to access a cache for the facet. If the cache didn't // exist before, it gets constructed on the fly. template @@ -1252,127 +1180,6 @@ _GLIBCXX_BEGIN_LDBL_NAMESPACE _GLIBCXX_END_LDBL_NAMESPACE - // Generic version does nothing. - template - int - collate<_CharT>::_M_compare(const _CharT*, const _CharT*) const - { return 0; } - - // Generic version does nothing. - template - size_t - collate<_CharT>::_M_transform(_CharT*, const _CharT*, size_t) const - { return 0; } - - template - int - collate<_CharT>:: - do_compare(const _CharT* __lo1, const _CharT* __hi1, - const _CharT* __lo2, const _CharT* __hi2) const - { - // strcoll assumes zero-terminated strings so we make a copy - // and then put a zero at the end. - const string_type __one(__lo1, __hi1); - const string_type __two(__lo2, __hi2); - - const _CharT* __p = __one.c_str(); - const _CharT* __pend = __one.data() + __one.length(); - const _CharT* __q = __two.c_str(); - const _CharT* __qend = __two.data() + __two.length(); - - // strcoll stops when it sees a nul character so we break - // the strings into zero-terminated substrings and pass those - // to strcoll. - for (;;) - { - const int __res = _M_compare(__p, __q); - if (__res) - return __res; - - __p += char_traits<_CharT>::length(__p); - __q += char_traits<_CharT>::length(__q); - if (__p == __pend && __q == __qend) - return 0; - else if (__p == __pend) - return -1; - else if (__q == __qend) - return 1; - - __p++; - __q++; - } - } - - template - typename collate<_CharT>::string_type - collate<_CharT>:: - do_transform(const _CharT* __lo, const _CharT* __hi) const - { - string_type __ret; - - // strxfrm assumes zero-terminated strings so we make a copy - const string_type __str(__lo, __hi); - - const _CharT* __p = __str.c_str(); - const _CharT* __pend = __str.data() + __str.length(); - - size_t __len = (__hi - __lo) * 2; - - _CharT* __c = new _CharT[__len]; - - try - { - // strxfrm stops when it sees a nul character so we break - // the string into zero-terminated substrings and pass those - // to strxfrm. - for (;;) - { - // First try a buffer perhaps big enough. - size_t __res = _M_transform(__c, __p, __len); - // If the buffer was not large enough, try again with the - // correct size. - if (__res >= __len) - { - __len = __res + 1; - delete [] __c, __c = 0; - __c = new _CharT[__len]; - __res = _M_transform(__c, __p, __len); - } - - __ret.append(__c, __res); - __p += char_traits<_CharT>::length(__p); - if (__p == __pend) - break; - - __p++; - __ret.push_back(_CharT()); - } - } - catch(...) - { - delete [] __c; - __throw_exception_again; - } - - delete [] __c; - - return __ret; - } - - template - long - collate<_CharT>:: - do_hash(const _CharT* __lo, const _CharT* __hi) const - { - unsigned long __val = 0; - for (; __lo < __hi; ++__lo) - __val = - *__lo + ((__val << 7) - | (__val >> (__gnu_cxx::__numeric_traits:: - __digits - 7))); - return static_cast(__val); - } - // Construct correctly padded string, as per 22.2.2.2.2 // Assumes // __newlen > __oldlen @@ -1502,17 +1309,6 @@ _GLIBCXX_END_LDBL_NAMESPACE extern template class _GLIBCXX_LDBL_NAMESPACE num_get; extern template class _GLIBCXX_LDBL_NAMESPACE num_put; extern template class ctype_byname; - extern template class codecvt_byname; - extern template class collate; - extern template class collate_byname; - - extern template - const codecvt& - use_facet >(const locale&); - - extern template - const collate& - use_facet >(const locale&); extern template const numpunct& @@ -1532,14 +1328,6 @@ _GLIBCXX_END_LDBL_NAMESPACE extern template bool - has_facet >(const locale&); - - extern template - bool - has_facet >(const locale&); - - extern template - bool has_facet >(const locale&); extern template @@ -1556,17 +1344,6 @@ _GLIBCXX_END_LDBL_NAMESPACE extern template class _GLIBCXX_LDBL_NAMESPACE num_get; extern template class _GLIBCXX_LDBL_NAMESPACE num_put; extern template class ctype_byname; - extern template class codecvt_byname; - extern template class collate; - extern template class collate_byname; - - extern template - const codecvt& - use_facet >(locale const&); - - extern template - const collate& - use_facet >(const locale&); extern template const numpunct& @@ -1586,14 +1363,6 @@ _GLIBCXX_END_LDBL_NAMESPACE extern template bool - has_facet >(const locale&); - - extern template - bool - has_facet >(const locale&); - - extern template - bool has_facet >(const locale&); extern template diff --git a/libstdc++-v3/include/bits/locale_facets_nonio.h b/libstdc++-v3/include/bits/locale_facets_nonio.h index 1fee4553bc6..15de0834fbe 100644 --- a/libstdc++-v3/include/bits/locale_facets_nonio.h +++ b/libstdc++-v3/include/bits/locale_facets_nonio.h @@ -39,6 +39,8 @@ #ifndef _LOCALE_FACETS_NONIO_H #define _LOCALE_FACETS_NONIO_H 1 +#pragma GCC system_header + #include // For struct tm _GLIBCXX_BEGIN_NAMESPACE(std) @@ -1903,7 +1905,14 @@ _GLIBCXX_END_LDBL_NAMESPACE _GLIBCXX_END_NAMESPACE - // Include host and configuration specific messages functions. +// Include host and configuration specific messages functions. #include +// 22.2.1.5 Template class codecvt +#include + +#ifndef _GLIBCXX_EXPORT_TEMPLATE +# include +#endif + #endif diff --git a/libstdc++-v3/include/bits/locale_facets_nonio.tcc b/libstdc++-v3/include/bits/locale_facets_nonio.tcc index 190caf37282..2db9e072423 100644 --- a/libstdc++-v3/include/bits/locale_facets_nonio.tcc +++ b/libstdc++-v3/include/bits/locale_facets_nonio.tcc @@ -35,6 +35,8 @@ #ifndef _LOCALE_FACETS_NONIO_TCC #define _LOCALE_FACETS_NONIO_TCC 1 +#pragma GCC system_header + _GLIBCXX_BEGIN_NAMESPACE(std) template @@ -1168,6 +1170,7 @@ _GLIBCXX_END_LDBL_NAMESPACE return std::__write(__s, __res, char_traits::length(__res)); } + // Inhibit implicit instantiations for required instantiations, // which are defined via explicit instantiations elsewhere. // NB: This syntax is a GNU extension. diff --git a/libstdc++-v3/include/bits/ostream.tcc b/libstdc++-v3/include/bits/ostream.tcc index 7788015158d..8ef9d89025b 100644 --- a/libstdc++-v3/include/bits/ostream.tcc +++ b/libstdc++-v3/include/bits/ostream.tcc @@ -332,7 +332,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) extern template ostream& operator<<(ostream&, const char*); extern template ostream& operator<<(ostream&, const unsigned char*); extern template ostream& operator<<(ostream&, const signed char*); - extern template ostream& __ostream_insert(ostream&, const char*, streamsize); extern template ostream& ostream::_M_insert(long); extern template ostream& ostream::_M_insert(unsigned long); @@ -354,8 +353,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) extern template wostream& operator<<(wostream&, char); extern template wostream& operator<<(wostream&, const wchar_t*); extern template wostream& operator<<(wostream&, const char*); - extern template wostream& __ostream_insert(wostream&, const wchar_t*, - streamsize); extern template wostream& wostream::_M_insert(long); extern template wostream& wostream::_M_insert(unsigned long); diff --git a/libstdc++-v3/include/bits/ostream_insert.h b/libstdc++-v3/include/bits/ostream_insert.h index f3ed801bbc3..e9e83fbc51f 100644 --- a/libstdc++-v3/include/bits/ostream_insert.h +++ b/libstdc++-v3/include/bits/ostream_insert.h @@ -109,6 +109,18 @@ _GLIBCXX_BEGIN_NAMESPACE(std) return __out; } + // Inhibit implicit instantiations for required instantiations, + // which are defined via explicit instantiations elsewhere. + // NB: This syntax is a GNU extension. +#if _GLIBCXX_EXTERN_TEMPLATE + extern template ostream& __ostream_insert(ostream&, const char*, streamsize); + +#ifdef _GLIBCXX_USE_WCHAR_T + extern template wostream& __ostream_insert(wostream&, const wchar_t*, + streamsize); +#endif +#endif + _GLIBCXX_END_NAMESPACE #endif /* _OSTREAM_INSERT_H */ diff --git a/libstdc++-v3/include/std/fstream b/libstdc++-v3/include/std/fstream index 170c6d66049..cab18c1fcb1 100644 --- a/libstdc++-v3/include/std/fstream +++ b/libstdc++-v3/include/std/fstream @@ -44,7 +44,8 @@ #include #include -#include // For BUFSIZ +#include +#include // For BUFSIZ #include // For __basic_file, __c_lock _GLIBCXX_BEGIN_NAMESPACE(std) @@ -61,7 +62,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // Requirements on traits_type, specific to this class: // traits_type::pos_type must be fpos // traits_type::off_type must be streamoff - // traits_type::state_type must be Assignable and DefaultConstructable, + // traits_type::state_type must be Assignable and DefaultConstructible, // and traits_type::state_type() must be the initial state for codecvt. template class basic_filebuf : public basic_streambuf<_CharT, _Traits> diff --git a/libstdc++-v3/include/std/istream b/libstdc++-v3/include/std/istream index a3e074a7b85..8b1666c10e3 100644 --- a/libstdc++-v3/include/std/istream +++ b/libstdc++-v3/include/std/istream @@ -836,7 +836,6 @@ _GLIBCXX_END_NAMESPACE #ifndef _GLIBCXX_EXPORT_TEMPLATE # include -# include #endif #endif /* _GLIBCXX_ISTREAM */ diff --git a/libstdc++-v3/include/std/locale b/libstdc++-v3/include/std/locale index 6bfd78d93e9..40a996d8438 100644 --- a/libstdc++-v3/include/std/locale +++ b/libstdc++-v3/include/std/locale @@ -1,7 +1,8 @@ // Locale support -*- C++ -*- // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 -// 2006, 2007 Free Software Foundation, Inc. +// 2006, 2007 +// 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 @@ -46,9 +47,4 @@ #include #include -#ifndef _GLIBCXX_EXPORT_TEMPLATE -# include -# include -#endif - #endif /* _GLIBCXX_LOCALE */ diff --git a/libstdc++-v3/include/std/ostream b/libstdc++-v3/include/std/ostream index a4019df8431..2287756513c 100644 --- a/libstdc++-v3/include/std/ostream +++ b/libstdc++-v3/include/std/ostream @@ -570,7 +570,6 @@ _GLIBCXX_END_NAMESPACE #ifndef _GLIBCXX_EXPORT_TEMPLATE # include -# include #endif #endif /* _GLIBCXX_OSTREAM */ diff --git a/libstdc++-v3/testsuite/util/testsuite_abi.h b/libstdc++-v3/testsuite/util/testsuite_abi.h index 935d95bd1fe..89825a875ab 100644 --- a/libstdc++-v3/testsuite/util/testsuite_abi.h +++ b/libstdc++-v3/testsuite/util/testsuite_abi.h @@ -1,6 +1,6 @@ // -*- C++ -*- -// Copyright (C) 2004, 2005 Free Software Foundation, Inc. +// Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc. // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as @@ -32,6 +32,7 @@ #include #include #include +#include #include #include -- 2.11.0