Commit 064994a3 by Paolo Carlini Committed by Paolo Carlini

Const correctness issue: http://gcc.gnu.org/ml/libstdc++/2003-01/msg00370.html

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
parent 434c87d4
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> 2003-01-29 Mark Mitchell <mark@codesourcery.com>
* include/std/std_limits.h (numeric_limits<float>::has_infinity): * include/std/std_limits.h (numeric_limits<float>::has_infinity):
......
...@@ -199,7 +199,7 @@ namespace std ...@@ -199,7 +199,7 @@ namespace std
private: private:
// Data Members. // Data Members.
_Atomic_word _M_references; _Atomic_word _M_references;
facet** _M_facets; const facet** _M_facets;
size_t _M_facets_size; size_t _M_facets_size;
char* _M_names[_S_categories_size char* _M_names[_S_categories_size
...@@ -260,7 +260,7 @@ namespace std ...@@ -260,7 +260,7 @@ namespace std
_M_replace_facet(const _Impl*, const locale::id*); _M_replace_facet(const _Impl*, const locale::id*);
void void
_M_install_facet(const locale::id*, facet*); _M_install_facet(const locale::id*, const facet*);
template<typename _Facet> template<typename _Facet>
inline void inline void
...@@ -291,7 +291,7 @@ namespace std ...@@ -291,7 +291,7 @@ namespace std
friend class locale; friend class locale;
friend class locale::_Impl; friend class locale::_Impl;
_Atomic_word _M_references; mutable _Atomic_word _M_references;
protected: protected:
// Contains data from the underlying "C" library for the classic locale. // Contains data from the underlying "C" library for the classic locale.
...@@ -318,10 +318,10 @@ namespace std ...@@ -318,10 +318,10 @@ namespace std
private: private:
void void
_M_add_reference() throw(); _M_add_reference() const throw();
void void
_M_remove_reference() throw(); _M_remove_reference() const throw();
facet(const facet&); // Not defined. facet(const facet&); // Not defined.
......
...@@ -71,7 +71,7 @@ namespace std ...@@ -71,7 +71,7 @@ namespace std
use_facet(const locale& __loc) use_facet(const locale& __loc)
{ {
size_t __i = _Facet::id._M_id(); 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])) if (!(__i < __loc._M_impl->_M_facets_size && __facets[__i]))
__throw_bad_cast(); __throw_bad_cast();
return static_cast<const _Facet&>(*__facets[__i]); return static_cast<const _Facet&>(*__facets[__i]);
...@@ -82,7 +82,7 @@ namespace std ...@@ -82,7 +82,7 @@ namespace std
has_facet(const locale& __loc) throw() has_facet(const locale& __loc) throw()
{ {
size_t __i = _Facet::id._M_id(); 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]); return (__i < __loc._M_impl->_M_facets_size && __facets[__i]);
} }
......
...@@ -461,12 +461,12 @@ namespace std ...@@ -461,12 +461,12 @@ namespace std
void void
locale::facet:: locale::facet::
_M_add_reference() throw() _M_add_reference() const throw()
{ __atomic_add(&_M_references, 1); } { __atomic_add(&_M_references, 1); }
void void
locale::facet:: locale::facet::
_M_remove_reference() throw() _M_remove_reference() const throw()
{ {
if (__exchange_and_add(&_M_references, -1) == 1) if (__exchange_and_add(&_M_references, -1) == 1)
{ {
......
...@@ -94,7 +94,7 @@ namespace std ...@@ -94,7 +94,7 @@ namespace std
{ {
try 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) for (size_t __i = 0; __i < _M_facets_size; ++__i)
_M_facets[__i] = 0; _M_facets[__i] = 0;
} }
...@@ -130,7 +130,7 @@ namespace std ...@@ -130,7 +130,7 @@ namespace std
try 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) for (size_t __i = 0; __i < _M_facets_size; ++__i)
_M_facets[__i] = 0; _M_facets[__i] = 0;
} }
...@@ -214,7 +214,7 @@ namespace std ...@@ -214,7 +214,7 @@ namespace std
locale::facet::_S_create_c_locale(locale::facet::_S_c_locale, locale::facet::_S_create_c_locale(locale::facet::_S_c_locale,
locale::facet::_S_c_name); 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) for (size_t __i = 0; __i < _M_facets_size; ++__i)
_M_facets[__i] = 0; _M_facets[__i] = 0;
...@@ -310,7 +310,7 @@ namespace std ...@@ -310,7 +310,7 @@ namespace std
void void
locale::_Impl:: locale::_Impl::
_M_install_facet(const locale::id* __idp, facet* __fp) _M_install_facet(const locale::id* __idp, const facet* __fp)
{ {
if (__fp) if (__fp)
{ {
...@@ -319,10 +319,10 @@ namespace std ...@@ -319,10 +319,10 @@ namespace std
// Check size of facet vector to ensure adequate room. // Check size of facet vector to ensure adequate room.
if (__index > _M_facets_size - 1) if (__index > _M_facets_size - 1)
{ {
facet** __old = _M_facets; const facet** __old = _M_facets;
facet** __new; const facet** __new;
const size_t __new_size = __index + 4; 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) for (size_t __i = 0; __i < _M_facets_size; ++__i)
__new[__i] = _M_facets[__i]; __new[__i] = _M_facets[__i];
for (size_t __i2 = _M_facets_size; __i2 < __new_size; ++__i2) for (size_t __i2 = _M_facets_size; __i2 < __new_size; ++__i2)
...@@ -334,7 +334,7 @@ namespace std ...@@ -334,7 +334,7 @@ namespace std
} }
__fp->_M_add_reference(); __fp->_M_add_reference();
facet*& __fpr = _M_facets[__index]; const facet*& __fpr = _M_facets[__index];
if (__fpr) if (__fpr)
{ {
// Replacing an existing facet. Order matters. // Replacing an existing facet. Order matters.
......
// 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment