locale.cc (locale::locale(const char* __name)): Consolidate name setting.
authorBenjamin Kosnik <bkoz@purist.soma.redhat.com>
Fri, 15 Sep 2000 22:52:52 +0000 (22:52 +0000)
committerBenjamin Kosnik <bkoz@gcc.gnu.org>
Fri, 15 Sep 2000 22:52:52 +0000 (22:52 +0000)
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...

From-SVN: r36451

libstdc++-v3/ChangeLog
libstdc++-v3/src/locale.cc
libstdc++-v3/src/localename.cc
libstdc++-v3/testsuite/22_locale/ctor_copy_dtor.cc

index 5547d6cc6406d84a0669c7f7d34c24968fe36003..4de4ac33f46b36cae3ff88c8f7015bcfc1acd1cc 100644 (file)
@@ -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.
index c5f4fcf789f26b3ec07042ed39f5e4dd8fbf0bdb..f3966ab2497eed513876078b976903c60b390fe2 100644 (file)
@@ -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()
index baa3bee7799b4090b12f3fcb531a9736969f2a90..51872d8a1549e79de297d2b7bab9594438fc2459 100644 (file)
@@ -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;
index d276dc875ea1e7d113ac26ce459c5acae6787c42..5a9a42acd02e4b3384868b9efc352a6839ffbbfd 100644 (file)
@@ -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); }