diff options
-rw-r--r-- | libstdc++-v3/ChangeLog | 16 | ||||
-rw-r--r-- | libstdc++-v3/src/locale.cc | 28 | ||||
-rw-r--r-- | libstdc++-v3/src/localename.cc | 2 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/22_locale/ctor_copy_dtor.cc | 25 |
4 files changed, 61 insertions, 10 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 5547d6cc640..4de4ac33f46 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,19 @@ +2000-09-15 Benjamin Kosnik <bkoz@purist.soma.redhat.com> + + * src/locale.cc (locale::locale(const char* __name)): Consolidate + name setting. Add checks for NULL __name pointers. Remove calls to + _S_initialize() as initial locale initialization can either be + assumed, or needs to be made consistent throughout locale + constructors. + (locale::locale(const locale& __other, const char* __name, + category __cat): Add checks for NULL name. Add checks for + assignment to self. + * src/localename.cc (locale::_Impl:: _Impl(const _Impl& __other, + const string& __name, category __cat, size_t __refs)): Set correct + name, has_name values. + * testsuite/22_locale/ctor_copy_dtor.cc (test01): More tests. + * docs/22_locale/locale.html: New file, more unfinished docs... + 2000-09-14 Benjamin Kosnik <bkoz@purist.soma.redhat.com> * src/locale.cc (locale::name()): Implement. diff --git a/libstdc++-v3/src/locale.cc b/libstdc++-v3/src/locale.cc index c5f4fcf789f..f3966ab2497 100644 --- a/libstdc++-v3/src/locale.cc +++ b/libstdc++-v3/src/locale.cc @@ -554,20 +554,32 @@ namespace std { locale::locale(const char* __name) { - _S_initialize(); - if (strcmp(__name, "C") == 0 || strcmp(__name, "POSIX") == 0) - (_M_impl = _S_classic)->_M_add_reference(); - else + if (__name) { + if (strcmp(__name, "C") == 0 || strcmp(__name, "POSIX") == 0) + (_M_impl = _S_classic)->_M_add_reference(); // Might throw: - _M_impl = new _Impl(*_S_classic, __name, all, 1); - _M_impl->_M_has_name = true; + else + _M_impl = new _Impl(*_S_classic, __name, all, 1); } + else + throw runtime_error("attempt to create named locale from NULL name"); } locale::locale(const locale& __other, const char* __name, category __cat) - : _M_impl(new _Impl(*__other._M_impl, __name, _S_normalize_category(__cat), 1)) - { } + { + if (__name) + { + if (__other.name() == __name) + (_M_impl = __other._M_impl)->_M_add_reference(); + // Might throw: + else + _M_impl = new _Impl(*__other._M_impl, __name, + _S_normalize_category(__cat), 1); + } + else + throw runtime_error("attempt to create locale from NULL named locale"); + } bool locale::operator==(const locale& __rhs) const throw() diff --git a/libstdc++-v3/src/localename.cc b/libstdc++-v3/src/localename.cc index baa3bee7799..51872d8a154 100644 --- a/libstdc++-v3/src/localename.cc +++ b/libstdc++-v3/src/localename.cc @@ -92,7 +92,7 @@ namespace std { : _M_references(__refs - 1) // , _M_facets(other._M_facets) // , _M_category_names(other._M_category_names) - , _M_has_name(__other._M_has_name), _M_name(__other._M_name) + , _M_has_name(__name != "*"), _M_name(__name) { #if 1 typedef vector<facet*, allocator<facet*> > __vec_facet; diff --git a/libstdc++-v3/testsuite/22_locale/ctor_copy_dtor.cc b/libstdc++-v3/testsuite/22_locale/ctor_copy_dtor.cc index d276dc875ea..5a9a42acd02 100644 --- a/libstdc++-v3/testsuite/22_locale/ctor_copy_dtor.cc +++ b/libstdc++-v3/testsuite/22_locale/ctor_copy_dtor.cc @@ -63,7 +63,7 @@ void test01() locale loc07(""); VERIFY (loc07 != loc01); VERIFY (loc07 != loc02); - VERIFY (loc06.name() == ""); + VERIFY (loc07.name() == ""); try { locale loc08(static_cast<const char*>(NULL)); } catch(runtime_error& obj) @@ -73,6 +73,29 @@ void test01() // 4 // locale(const locale& other, const char* std_name, category) + locale loc09(loc06, "C", locale::ctype); + VERIFY (loc09.name() == "fr_FR"); + VERIFY (loc09 != loc01); + VERIFY (loc09 != loc06); + // XXX somehow check that the ctype, codecvt facets have "C" locale bits... + + locale loc10(loc02, "C", locale::ctype); + VERIFY (loc10.name() == "*"); + VERIFY (loc10 != loc01); // As not named, even tho facets same... + VERIFY (loc10 != loc02); + // XXX somehow check that the ctype, codecvt facets have "C" locale bits... + + locale loc11(loc01, "C", locale::ctype); + VERIFY (loc11.name() == "C"); + VERIFY (loc11 == loc01); + // XXX somehow check that the ctype, codecvt facets have "C" locale bits... + + try + { locale loc12(loc01, static_cast<const char*>(NULL), locale::ctype); } + catch(runtime_error& obj) + { VERIFY (true); } + catch(...) + { VERIFY (false); } |