Const correctness issue: http://gcc.gnu.org/ml/libstdc++/2003-01/msg00370.html
authorPaolo Carlini <pcarlini@unitus.it>
Sat, 1 Feb 2003 16:37:20 +0000 (17:37 +0100)
committerPaolo Carlini <paolo@gcc.gnu.org>
Sat, 1 Feb 2003 16:37:20 +0000 (16:37 +0000)
2003-02-01  Paolo Carlini  <pcarlini@unitus.it>
    Benjamin Kosnik  <bkoz@redhat.com>

Const correctness issue:
http://gcc.gnu.org/ml/libstdc++/2003-01/msg00370.html
* include/bits/locale_classes.h
(locale::_Impl::_M_facets): Change type to const facet**.
(locale::_Impl::_M_install_facet): Change declaration to
take const facet*.
(locale::facet::_M_references): Make mutable.
(locale::facet::_M_add_reference): Declare const.
(locale::facet::_M_remove_reference): Likewise.
* include/bits/locale_facets.tcc
(use_facet(const locale&)): Tweak for const facet** _M_facets.
(has_facet(const locale&)): Likewise.
* src/locale.cc
(locale::facet::_M_add_reference): Adjust definition.
(locale::facet::_M_remove_reference): Likewise.
* src/localename.cc
(locale::_Impl::_Impl(const _Impl&, size_t)): Tweak for
const facet** _M_facets.
(locale::_Impl::_Impl(const char*, size_t)): Likewise.
(locale::_Impl::_Impl(facet**, size_t, bool)): Likewise.
(locale::_Impl::_M_install_facet): Adjust definition to take
const facet* and for const facet** _M_facets.
* testsuite/22_locale/locale/cons/8.cc: Add.

Co-Authored-By: Benjamin Kosnik <bkoz@redhat.com>
From-SVN: r62248

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/locale_classes.h
libstdc++-v3/include/bits/locale_facets.tcc
libstdc++-v3/src/locale.cc
libstdc++-v3/src/localename.cc
libstdc++-v3/testsuite/22_locale/locale/cons/8.cc [new file with mode: 0644]

index fd0d93fa2e7e0c6c5fe4b71aae74a41d2e666224..58e008e6838d5a814d8c87c7a2bd0e06b7d3b3cd 100644 (file)
@@ -1,3 +1,30 @@
+2003-02-01  Paolo Carlini  <pcarlini@unitus.it>
+            Benjamin Kosnik  <bkoz@redhat.com>
+
+       Const correctness issue:
+       http://gcc.gnu.org/ml/libstdc++/2003-01/msg00370.html
+       * include/bits/locale_classes.h
+       (locale::_Impl::_M_facets): Change type to const facet**.
+       (locale::_Impl::_M_install_facet): Change declaration to
+       take const facet*.
+       (locale::facet::_M_references): Make mutable.
+       (locale::facet::_M_add_reference): Declare const.
+       (locale::facet::_M_remove_reference): Likewise.
+       * include/bits/locale_facets.tcc
+       (use_facet(const locale&)): Tweak for const facet** _M_facets.
+       (has_facet(const locale&)): Likewise.
+       * src/locale.cc
+       (locale::facet::_M_add_reference): Adjust definition.
+       (locale::facet::_M_remove_reference): Likewise.
+       * src/localename.cc
+       (locale::_Impl::_Impl(const _Impl&, size_t)): Tweak for
+       const facet** _M_facets.
+       (locale::_Impl::_Impl(const char*, size_t)): Likewise.
+       (locale::_Impl::_Impl(facet**, size_t, bool)): Likewise.
+       (locale::_Impl::_M_install_facet): Adjust definition to take
+       const facet* and for const facet** _M_facets.
+       * testsuite/22_locale/locale/cons/8.cc: Add.
+
 2003-01-29  Mark Mitchell  <mark@codesourcery.com>
 
        * include/std/std_limits.h (numeric_limits<float>::has_infinity):
index f36c8d4dea4953927217791517a058e35540621d..5e6d5f1f868b7e8662b1708b7ce65ab1ea05f224 100644 (file)
@@ -199,7 +199,7 @@ namespace std
   private:
     // Data Members.
     _Atomic_word                       _M_references;
-    facet**                            _M_facets;
+    const facet**                      _M_facets;
     size_t                             _M_facets_size;
 
     char*                              _M_names[_S_categories_size
@@ -260,7 +260,7 @@ namespace std
     _M_replace_facet(const _Impl*, const locale::id*);
 
     void 
-    _M_install_facet(const locale::id*, facet*);
+    _M_install_facet(const locale::id*, const facet*);
 
     template<typename _Facet>
       inline void 
@@ -291,7 +291,7 @@ namespace std
     friend class locale;
     friend class locale::_Impl;
 
-    _Atomic_word                       _M_references;
+    mutable _Atomic_word               _M_references;
 
   protected:
     // Contains data from the underlying "C" library for the classic locale.
@@ -318,10 +318,10 @@ namespace std
 
   private:
     void 
-    _M_add_reference() throw();
+    _M_add_reference() const throw();
 
     void 
-    _M_remove_reference() throw();
+    _M_remove_reference() const throw();
 
     facet(const facet&);  // Not defined.
 
index 20c75751c6ccc1dfde7b16399069afef70f112e8..c5263a1ed5a2c955acdd84e7bf1c1e00fc40da34 100644 (file)
@@ -71,7 +71,7 @@ namespace std
     use_facet(const locale& __loc)
     {
       size_t __i = _Facet::id._M_id();
-      locale::facet** __facets = __loc._M_impl->_M_facets;
+      const locale::facet** __facets = __loc._M_impl->_M_facets;
       if (!(__i < __loc._M_impl->_M_facets_size && __facets[__i]))
         __throw_bad_cast();
       return static_cast<const _Facet&>(*__facets[__i]);
@@ -82,7 +82,7 @@ namespace std
     has_facet(const locale& __loc) throw()
     {
       size_t __i = _Facet::id._M_id();
-      locale::facet** __facets = __loc._M_impl->_M_facets;
+      const locale::facet** __facets = __loc._M_impl->_M_facets;
       return (__i < __loc._M_impl->_M_facets_size && __facets[__i]);
     }
 
index 8246f4a5f475a448f86ae09d0695f61c1df3dd2e..42972e9de40c56ebc5674686e7243fa2b485ddc0 100644 (file)
@@ -461,12 +461,12 @@ namespace std
 
   void  
   locale::facet::
-  _M_add_reference() throw()
+  _M_add_reference() const throw()
   { __atomic_add(&_M_references, 1); }
 
   void  
   locale::facet::
-  _M_remove_reference() throw()
+  _M_remove_reference() const throw()
   {
     if (__exchange_and_add(&_M_references, -1) == 1)
       {
index 8a30b897f07eff3349e9dc97ea75497d986d3e21..c9528d00c9879fd7bf219cdd09292eb3c605ac49 100644 (file)
@@ -94,7 +94,7 @@ namespace std
   {
     try
       { 
-       _M_facets = new facet*[_M_facets_size]; 
+       _M_facets = new const facet*[_M_facets_size]; 
        for (size_t __i = 0; __i < _M_facets_size; ++__i)
          _M_facets[__i] = 0;
       }
@@ -130,7 +130,7 @@ namespace std
 
     try
       { 
-       _M_facets = new facet*[_M_facets_size]; 
+       _M_facets = new const facet*[_M_facets_size]; 
        for (size_t __i = 0; __i < _M_facets_size; ++__i)
          _M_facets[__i] = 0;
       }
@@ -214,7 +214,7 @@ namespace std
     locale::facet::_S_create_c_locale(locale::facet::_S_c_locale, 
                                      locale::facet::_S_c_name);
 
-    _M_facets = new(&facet_vec) facet*[_M_facets_size];
+    _M_facets = new(&facet_vec) const facet*[_M_facets_size];
     for (size_t __i = 0; __i < _M_facets_size; ++__i)
       _M_facets[__i] = 0;
 
@@ -310,7 +310,7 @@ namespace std
 
   void
   locale::_Impl::
-  _M_install_facet(const locale::id* __idp, facet* __fp)
+  _M_install_facet(const locale::id* __idp, const facet* __fp)
   {
     if (__fp)
       {
@@ -319,10 +319,10 @@ namespace std
        // Check size of facet vector to ensure adequate room.
        if (__index > _M_facets_size - 1)
          {
-           facet** __old = _M_facets;
-           facet** __new;
+           const facet** __old = _M_facets;
+           const facet** __new;
            const size_t __new_size = __index + 4;
-           __new = new facet*[__new_size]; 
+           __new = new const facet*[__new_size]; 
            for (size_t __i = 0; __i < _M_facets_size; ++__i)
              __new[__i] = _M_facets[__i];
            for (size_t __i2 = _M_facets_size; __i2 < __new_size; ++__i2)
@@ -334,7 +334,7 @@ namespace std
          }
 
        __fp->_M_add_reference();
-       facet*& __fpr = _M_facets[__index];
+       const facet*& __fpr = _M_facets[__index];
        if (__fpr)
          {
            // Replacing an existing facet. Order matters.
diff --git a/libstdc++-v3/testsuite/22_locale/locale/cons/8.cc b/libstdc++-v3/testsuite/22_locale/locale/cons/8.cc
new file mode 100644 (file)
index 0000000..433fc1f
--- /dev/null
@@ -0,0 +1,43 @@
+// 2003-02-01 Paolo Carlini <pcarlini@unitus.it>
+
+// Copyright (C) 2003 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 22.1.1.2 locale constructors and destructors [lib.locale.cons]
+
+#include <locale>
+
+// Const correctness issue:
+// http://gcc.gnu.org/ml/libstdc++/2003-01/msg00370.html
+void
+test01()
+{
+  using namespace std;
+  bool test = true;
+
+  const locale l1("C");
+  const locale l2 =
+    locale(locale::classic(), &use_facet<time_get<char> >(l1));
+}
+
+
+int main()
+{
+  test01();
+  return 0;
+}