summaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>2001-06-30 04:35:49 +0000
committerbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>2001-06-30 04:35:49 +0000
commit23e98236d68486406594078cd901d36508878139 (patch)
tree995ded702483dea4d437f12cb2404f0b4cc96c79 /libstdc++-v3
parentd6afc2422f11c5fa802c6e43e3a6b722a99a72be (diff)
downloadgcc-23e98236d68486406594078cd901d36508878139.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@43661 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog15
-rw-r--r--libstdc++-v3/include/bits/locale_facets.tcc7
-rw-r--r--libstdc++-v3/include/bits/localefwd.h2
-rw-r--r--libstdc++-v3/src/locale.cc1
-rw-r--r--libstdc++-v3/src/localename.cc8
-rw-r--r--libstdc++-v3/testsuite/22_locale/members.cc63
-rw-r--r--libstdc++-v3/testsuite/22_locale/numpunct.cc18
-rw-r--r--libstdc++-v3/testsuite/22_locale/numpunct_char_members.cc40
8 files changed, 98 insertions, 56 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 1e2fdbca215..a5af915002e 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -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
diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc
index 192ec816177..982914fb5f4 100644
--- a/libstdc++-v3/include/bits/locale_facets.tcc
+++ b/libstdc++-v3/include/bits/locale_facets.tcc
@@ -42,16 +42,15 @@
#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>
diff --git a/libstdc++-v3/include/bits/localefwd.h b/libstdc++-v3/include/bits/localefwd.h
index dd5cddc44b9..da84110746e 100644
--- a/libstdc++-v3/include/bits/localefwd.h
+++ b/libstdc++-v3/include/bits/localefwd.h
@@ -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; }
diff --git a/libstdc++-v3/src/locale.cc b/libstdc++-v3/src/locale.cc
index b72d7ffe0b6..de4f9838148 100644
--- a/libstdc++-v3/src/locale.cc
+++ b/libstdc++-v3/src/locale.cc
@@ -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(); }
diff --git a/libstdc++-v3/src/localename.cc b/libstdc++-v3/src/localename.cc
index e4bc18fefe6..ff98ee3202f 100644
--- a/libstdc++-v3/src/localename.cc
+++ b/libstdc++-v3/src/localename.cc
@@ -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
-
diff --git a/libstdc++-v3/testsuite/22_locale/members.cc b/libstdc++-v3/testsuite/22_locale/members.cc
index f7395d37631..adee6196ae9 100644
--- a/libstdc++-v3/testsuite/22_locale/members.cc
+++ b/libstdc++-v3/testsuite/22_locale/members.cc
@@ -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 );
}
diff --git a/libstdc++-v3/testsuite/22_locale/numpunct.cc b/libstdc++-v3/testsuite/22_locale/numpunct.cc
index f50e99bffc9..6e281b023ed 100644
--- a/libstdc++-v3/testsuite/22_locale/numpunct.cc
+++ b/libstdc++-v3/testsuite/22_locale/numpunct.cc
@@ -22,13 +22,27 @@
#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;
}
diff --git a/libstdc++-v3/testsuite/22_locale/numpunct_char_members.cc b/libstdc++-v3/testsuite/22_locale/numpunct_char_members.cc
index 77d716fc05c..803097710be 100644
--- a/libstdc++-v3/testsuite/22_locale/numpunct_char_members.cc
+++ b/libstdc++-v3/testsuite/22_locale/numpunct_char_members.cc
@@ -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()