locale_facets.tcc (locale::combine): Clone _Impl.
authorBenjamin Kosnik <bkoz@redhat.com>
Sat, 30 Jun 2001 04:35:49 +0000 (04:35 +0000)
committerBenjamin Kosnik <bkoz@gcc.gnu.org>
Sat, 30 Jun 2001 04:35:49 +0000 (04:35 +0000)
2001-06-29  Benjamin Kosnik  <bkoz@redhat.com>

* include/bits/locale_facets.tcc (locale::combine): Clone _Impl.
before replacing facet.
* include/bits/localefwd.h (locale::_Impl::_M_remove_reference):
Correct decrement.
* src/localename.cc (locale::_Impl): Correct ctor initialization
lists. Initialize ref count with one. Simplify.
* src/locale.cc: Add comment.
* testsuite/22_locale/numpunct.cc (test01): Add derivation test.
* testsuite/22_locale/numpunct_char_members.cc (test01): Add tests.
* testsuite/22_locale/members.cc (test02): Fix.

From-SVN: r43661

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/locale_facets.tcc
libstdc++-v3/include/bits/localefwd.h
libstdc++-v3/src/locale.cc
libstdc++-v3/src/localename.cc
libstdc++-v3/testsuite/22_locale/members.cc
libstdc++-v3/testsuite/22_locale/numpunct.cc
libstdc++-v3/testsuite/22_locale/numpunct_char_members.cc

index 1e2fdbca215e9b23ae450011317d55bd9adc4cdd..a5af915002e6720b2ffa890483f44eccdd77ceb6 100644 (file)
@@ -1,3 +1,16 @@
+2001-06-29  Benjamin Kosnik  <bkoz@redhat.com>
+
+       * include/bits/locale_facets.tcc (locale::combine): Clone _Impl.
+       before replacing facet.
+       * include/bits/localefwd.h (locale::_Impl::_M_remove_reference):
+       Correct decrement.
+       * src/localename.cc (locale::_Impl): Correct ctor initialization
+       lists. Initialize ref count with one. Simplify.
+       * src/locale.cc: Add comment.
+       * testsuite/22_locale/numpunct.cc (test01): Add derivation test.
+       * testsuite/22_locale/numpunct_char_members.cc (test01): Add tests.
+       * testsuite/22_locale/members.cc (test02): Fix.
+
 2001-06-27  Phil Edwards  <pme@sources.redhat.com>
 
        * include/backward/algo.h:  Add "GPL plus runtime exception" comment
@@ -81,7 +94,7 @@
        * src/bitset.cc:  Likewise.
        * src/strstream.cc:  Likewise.
 
-2001-06-26  Benjamin Kosnik  <bkoz@fillmore.constant.com>
+2001-06-26  Benjamin Kosnik  <bkoz@redhat.com>
                             <vakatov@ncbi.nlm.nih.gov>
 
        libstdc++/3272
index 192ec816177cccb8d349bf9848f46dd7ae8f58ee..982914fb5f46e0955f5ad001835c529fd9ef63ed 100644 (file)
 #include <typeinfo>            // For bad_cast
 #include <bits/std_vector.h>   
 
-
 namespace std
 {
   template<typename _Facet>
     locale
     locale::combine(const locale& __other)
     {
-      locale __copy(*this);
-      __copy._M_impl->_M_replace_facet(__other._M_impl, &_Facet::id);
-      return __copy;
+      _Impl* __tmp = new _Impl(*_M_impl, 1);
+      __tmp->_M_replace_facet(__other._M_impl, &_Facet::id);
+      return locale(__tmp);
     }
 
   template<typename _CharT, typename _Traits, typename _Alloc>
index dd5cddc44b995a5fd508c94f652db135ecb11fa4..da84110746ef515e05f6ff88575adccf948ee619 100644 (file)
@@ -326,7 +326,7 @@ namespace std
     inline void 
     _M_remove_reference() throw()
     {
-      if (_M_references-- == 0)  // XXX MT
+      if (--_M_references == 0)  // XXX MT
        {
          try 
            { delete this; } 
index b72d7ffe0b6d85ee1e813099c4fb6c084bafeba0..de4f983814886951d725d289c35fe7f88bc7b183 100644 (file)
@@ -362,6 +362,7 @@ namespace std
   locale::locale(const locale& __other) throw()
   { (_M_impl = __other._M_impl)->_M_add_reference(); }
 
+  // This is used to initialize global and classic locales.
   locale::locale(_Impl* __ip) throw()
   : _M_impl(__ip)
   { __ip->_M_add_reference(); }
index e4bc18fefe600a636ea93f39bc14d61f205bc54c..ff98ee3202f6667699aa96febbe4c641febd48f9 100644 (file)
@@ -47,7 +47,7 @@ namespace std
   // Clone existing _Impl object.
   locale::_Impl::
   _Impl(const _Impl& __imp, size_t __refs)
-  : _M_references(__refs - 1), _M_facets(0), _M_c_locale(0) // XXX
+  : _M_references(__refs), _M_facets(0), _M_c_locale(0) // XXX
   {
     try
       {  _M_facets = new __vec_facet(*(__imp._M_facets)); }
@@ -69,7 +69,7 @@ namespace std
   // Construct named _Impl, including the standard "C" locale.
   locale::_Impl::
   _Impl(string __str, size_t __refs)
-  : _M_references(__refs - 1), _M_facets(0)
+  : _M_references(__refs), _M_facets(0)
   {
     // Initialize the underlying locale model, which also checks to
     // see if the given name is valid.
@@ -184,8 +184,7 @@ namespace std
            // Replacing an existing facet.
            // Order matters, here:
            __fp->_M_add_reference();
-           if (__fpr) 
-             __fpr->_M_remove_reference();
+           __fpr->_M_remove_reference();
            __fpr = __fp;
          }
        else
@@ -198,4 +197,3 @@ namespace std
       }
   }
 } // namespace std
-
index f7395d376310fcde62c42d5d5a68e5a35c4c2717..adee6196ae9bf7a1137502a98815613b1eafc8c8 100644 (file)
@@ -86,46 +86,47 @@ test02()
   VERIFY( loc_2 != loc_c );
 
   // extract facet
-  const numpunct<char>&        f_nump_1 = use_facet<numpunct<char> >(loc_1); 
-  const numpunct<char>&        f_nump_2 = use_facet<numpunct<char> >(loc_2); 
-  const numpunct<char>&        f_nump_c = use_facet<numpunct<char> >(loc_c); 
-  const numpunct<char>&        f_nump_fr = use_facet<numpunct<char> >(loc_fr); 
+  const numpunct<char>&        nump_1 = use_facet<numpunct<char> >(loc_1); 
+  const numpunct<char>&        nump_2 = use_facet<numpunct<char> >(loc_2); 
+  const numpunct<char>&        nump_c = use_facet<numpunct<char> >(loc_c); 
+  const numpunct<char>&        nump_fr = use_facet<numpunct<char> >(loc_fr); 
 
   // sanity check the data is correct.
-  char dp1 = f_nump_c.decimal_point();
-  char th1 = f_nump_c.thousands_sep();
-  string g1 = f_nump_c.grouping();
-  string t1 = f_nump_c.truename();
-  string f1 = f_nump_c.falsename();
-
-  char dp2 = f_nump_1.decimal_point();
-  char th2 = f_nump_1.thousands_sep();
-  string g2 = f_nump_1.grouping();
-  string t2 = f_nump_1.truename();
-  string f2 = f_nump_1.falsename();
-
-  char dp3 = f_nump_2.decimal_point();
-  char th3 = f_nump_2.thousands_sep();
-  string g3 = f_nump_2.grouping();
-  string t3 = f_nump_2.truename();
-  string f3 = f_nump_2.falsename();
-
-  char dp4 = f_nump_fr.decimal_point();
-  char th4 = f_nump_fr.thousands_sep();
-  string g4 = f_nump_fr.grouping();
-  string t4 = f_nump_fr.truename();
-  string f4 = f_nump_fr.falsename();
-
-#if 0
-  // XXX these should not be the same if named locales are working correctly.
+  char dp1 = nump_c.decimal_point();
+  char th1 = nump_c.thousands_sep();
+  string g1 = nump_c.grouping();
+  string t1 = nump_c.truename();
+  string f1 = nump_c.falsename();
+
+  char dp2 = nump_1.decimal_point();
+  char th2 = nump_1.thousands_sep();
+  string g2 = nump_1.grouping();
+  string t2 = nump_1.truename();
+  string f2 = nump_1.falsename();
+
+  char dp3 = nump_2.decimal_point();
+  char th3 = nump_2.thousands_sep();
+  string g3 = nump_2.grouping();
+  string t3 = nump_2.truename();
+  string f3 = nump_2.falsename();
+
+  char dp4 = nump_fr.decimal_point();
+  char th4 = nump_fr.thousands_sep();
+  string g4 = nump_fr.grouping();
+  string t4 = nump_fr.truename();
+  string f4 = nump_fr.falsename();
   VERIFY( dp1 != dp2 );
   VERIFY( th1 != th2 );
-#endif
 
   VERIFY( dp1 == dp3 );
   VERIFY( th1 == th3 );
   VERIFY( t1 == t3 );
   VERIFY( f1 == f3 );
+
+  VERIFY( dp2 == dp4 );
+  VERIFY( th2 == th4 );
+  VERIFY( t2 == t4 );
+  VERIFY( f2 == f4 );
 }
 
 
index f50e99bffc9d5ae00dd0cc0b17e7f18f83c1d2e4..6e281b023edf729516212f611ead9fd5c710b486 100644 (file)
 
 #include <locale>
 
+void test01()
+{
+  // Check for required base class.
+  typedef std::numpunct<char> test_type;
+  typedef std::locale::facet base_type;
+  const test_type& obj = std::use_facet<test_type>(std::locale()); 
+  const base_type* base = &obj;
+}
+
 // Should be able to instantiate this for other types besides char, wchar_t
 class gnu_numpunct: public std::numpunct<unsigned char> 
 { };
 
-
-int main() 
+void test02()
 { 
   gnu_numpunct facet01;
+}
+
+int main()
+{
+  test01();
+  test02();
   return 0;
 }
index 77d716fc05c71c996093ec6182b6bf354a8e6a38..803097710be7cf64f9d0ccc7a9a6dd5b4232a636 100644 (file)
@@ -42,19 +42,19 @@ void test01()
   str = loc_fr.name();
   VERIFY( loc_c != loc_fr );
 
-  VERIFY( loc_us != loc_fr );
+  locale loc_de("de_DE");
+  str = loc_de.name();
+  VERIFY( loc_c != loc_de );
 
-  locale loc_combo(loc_us, loc_fr, locale::numeric);
-  str = loc_combo.name();
-  VERIFY( loc_combo != loc_fr );
-  VERIFY( loc_combo != loc_us );
-  VERIFY( loc_combo != loc_c );
+  VERIFY( loc_us != loc_fr );
+  VERIFY( loc_us != loc_de );
+  VERIFY( loc_de != loc_fr );
 
   // cache the numpunct facets
   const numpunct<char>& nump_c = use_facet<numpunct<char> >(loc_c); 
   const numpunct<char>& nump_us = use_facet<numpunct<char> >(loc_us); 
   const numpunct<char>& nump_fr = use_facet<numpunct<char> >(loc_fr); 
-  const numpunct<char>& nump_combo = use_facet<numpunct<char> >(loc_combo); 
+  const numpunct<char>& nump_de = use_facet<numpunct<char> >(loc_de); 
 
   // sanity check the data is correct.
   char dp1 = nump_c.decimal_point();
@@ -75,11 +75,27 @@ void test01()
   string t3 = nump_fr.truename();
   string f3 = nump_fr.falsename();
 
-  char dp4 = nump_combo.decimal_point();
-  char th4 = nump_combo.thousands_sep();
-  string g4 = nump_combo.grouping();
-  string t4 = nump_combo.truename();
-  string f4 = nump_combo.falsename();
+  char dp4 = nump_de.decimal_point();
+  char th4 = nump_de.thousands_sep();
+  string g4 = nump_de.grouping();
+  string t4 = nump_de.truename();
+  string f4 = nump_de.falsename();
+
+  VERIFY( dp2 != dp3 );
+  VERIFY( th2 != th3 );
+#if 0
+  // XXX isn't actually supported right now.
+  VERIFY( t2 != t3 );
+  VERIFY( f2 != f3 );
+#endif
+
+  VERIFY( dp2 != dp4 );
+  VERIFY( th2 != th4 );
+#if 0
+  // XXX isn't actually supported right now.
+  VERIFY( t2 != t3 );
+  VERIFY( f2 != f3 );
+#endif
 }
 
 int main()