From 213c2316b697c78344ba7d03b2e922c8229e8b35 Mon Sep 17 00:00:00 2001 From: Benjamin Kosnik Date: Mon, 2 Jul 2001 23:08:28 +0000 Subject: [PATCH] locale.cc (locale::locale(const char*)): Make sure global locales are initialized. 2001-07-02 Benjamin Kosnik * src/locale.cc (locale::locale(const char*)): Make sure global locales are initialized. * include/bits/locale_facets.tcc (locale::combine): Refcout should be zero, not one as it's return-by-value. * testsuite/27_io/ios_base_callbacks.cc (test01): Don't check for named locales here. * testsuite/22_locale/ctor_copy_dtor.cc (test01): Instead, check for it here. (test02): Add test. * libsupc++/eh_alloc.cc: Use climits, not limits.h. From-SVN: r43713 --- libstdc++-v3/ChangeLog | 20 ++++++++++++------- libstdc++-v3/include/bits/locale_facets.tcc | 2 +- libstdc++-v3/libsupc++/eh_alloc.cc | 2 +- libstdc++-v3/src/locale.cc | 1 + .../testsuite/22_locale/ctor_copy_dtor.cc | 17 ++++++++++++++++ .../testsuite/27_io/ios_base_callbacks.cc | 5 +++-- 6 files changed, 36 insertions(+), 11 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index da17d682111..6c582e2959e 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,10 +1,16 @@ -2001-07-02 Loren J. Rittle - - libstdc++/3284 - * acinclude.m4 (GLIBCPP_ENABLE_THREADS): Portability enhancement. - * aclocal.m4: Regenerate. - * configure: Regenerate. - +2001-07-02 Benjamin Kosnik + + * src/locale.cc (locale::locale(const char*)): Make sure global + locales are initialized. + * include/bits/locale_facets.tcc (locale::combine): Refcout should + be zero, not one as it's return-by-value. + * testsuite/27_io/ios_base_callbacks.cc (test01): Don't check for + named locales here. + * testsuite/22_locale/ctor_copy_dtor.cc (test01): Instead, check + for it here. + (test02): Add test. + * libsupc++/eh_alloc.cc: Use climits, not limits.h. + 2001-07-02 Loren J. Rittle libstdc++/3243 diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index 982914fb5f4..6eceed1ea59 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -48,7 +48,7 @@ namespace std locale locale::combine(const locale& __other) { - _Impl* __tmp = new _Impl(*_M_impl, 1); + _Impl* __tmp = new _Impl(*_M_impl, 0); __tmp->_M_replace_facet(__other._M_impl, &_Facet::id); return locale(__tmp); } diff --git a/libstdc++-v3/libsupc++/eh_alloc.cc b/libstdc++-v3/libsupc++/eh_alloc.cc index 8b55d6c6083..1f59ec46394 100644 --- a/libstdc++-v3/libsupc++/eh_alloc.cc +++ b/libstdc++-v3/libsupc++/eh_alloc.cc @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include "unwind-cxx.h" #include "bits/c++config.h" #include "bits/gthr.h" diff --git a/libstdc++-v3/src/locale.cc b/libstdc++-v3/src/locale.cc index de4f9838148..fb0b406eed4 100644 --- a/libstdc++-v3/src/locale.cc +++ b/libstdc++-v3/src/locale.cc @@ -371,6 +371,7 @@ namespace std { if (__s) { + _S_initialize(); if (strcmp(__s, "C") == 0 || strcmp(__s, "POSIX") == 0) (_M_impl = _S_classic)->_M_add_reference(); else diff --git a/libstdc++-v3/testsuite/22_locale/ctor_copy_dtor.cc b/libstdc++-v3/testsuite/22_locale/ctor_copy_dtor.cc index cbac8843187..7269d231da3 100644 --- a/libstdc++-v3/testsuite/22_locale/ctor_copy_dtor.cc +++ b/libstdc++-v3/testsuite/22_locale/ctor_copy_dtor.cc @@ -25,6 +25,14 @@ #include #include + +void test00() +{ + // Should be able to do this as the first thing that happens in a + // file and have it not crash. + std::locale loc("C"); +} + #if _GLIBCPP_USE_WCHAR_T typedef std::codecvt c_codecvt; typedef std::codecvt_byname c_codecvt_byname; @@ -126,6 +134,13 @@ void test01() catch(...) { VERIFY (false); } + try + { locale loc08("saturn_SUN*RA"); } + catch(runtime_error& obj) + { VERIFY (true); } + catch(...) + { VERIFY (false); } + // 4 // locale(const locale& other, const char* std_name, category) { @@ -226,6 +241,8 @@ void test01() int main () { + test00(); + #if _GLIBCPP_USE_WCHAR_T test01(); #endif diff --git a/libstdc++-v3/testsuite/27_io/ios_base_callbacks.cc b/libstdc++-v3/testsuite/27_io/ios_base_callbacks.cc index 236e9eb6715..84ca815e356 100644 --- a/libstdc++-v3/testsuite/27_io/ios_base_callbacks.cc +++ b/libstdc++-v3/testsuite/27_io/ios_base_callbacks.cc @@ -42,14 +42,14 @@ callb03(std::ios_base::event e, std::ios_base& b, int i) bool test01() { bool test = true; - std::locale locco("saturn_SUN*RA"); + std::locale loc("C"); std::stringbuf strbuf01; std::ios ios01(&strbuf01); ios01.register_callback(callb03, 1); ios01.register_callback(callb02, 1); ios01.register_callback(callb01, 1); - ios01.imbue(locco); + ios01.imbue(loc); VERIFY( str01 == str02 ); #ifdef DEBUG_ASSERT @@ -66,3 +66,4 @@ int main(void) return 0; } +