This is the mail archive of the
libstdc++@sources.redhat.com
mailing list for the libstdc++ project.
V3 PATCH: Static data members
- To: gcc-patches at gcc dot gnu dot org, libstdc++ at sources dot redhat dot com
- Subject: V3 PATCH: Static data members
- From: Mark Mitchell <mark at codesourcery dot com>
- Date: Wed, 15 Nov 2000 17:02:02 -0800
- Organization: CodeSourcery, LLC
G++ doesn't handle static data members well (they are not implicitly
instantiated) on AIX, and it may not do so in the near future. It
handles *const* static data members better, because it often doesn't
actually allocate storage for the constants.
That means that we should try to avoid non-const static data members
in V3, when possible. Here are a couple I zapped. This is also a
Good Thing because we will get better code on all platforms; G++ will
fold computations involving the static data members.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
2000-11-15 Mark Mitchell <mark@codesourcery.com>
* include/bits/basic_string.h (basic_string::_Rep::_S_max_size):
Make it const.
(basic_string::_Rep::_S_terminal): Likewise.
Index: include/bits/basic_string.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/include/bits/basic_string.h,v
retrieving revision 1.1
diff -c -p -r1.1 basic_string.h
*** basic_string.h 2000/10/05 11:27:01 1.1
--- basic_string.h 2000/11/16 00:55:08
*************** namespace std {
*** 131,138 ****
// Solving for m:
// m = ((npos - sizeof(_Rep))/sizeof(CharT)) - 1
// In addition, this implementation quarters this ammount.
! static size_type _S_max_size;
! static _CharT _S_terminal;
size_type _M_length;
size_type _M_capacity;
--- 131,138 ----
// Solving for m:
// m = ((npos - sizeof(_Rep))/sizeof(CharT)) - 1
// In addition, this implementation quarters this ammount.
! static const size_type _S_max_size;
! static const _CharT _S_terminal;
size_type _M_length;
size_type _M_capacity;
Index: include/bits/string.tcc
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/include/bits/string.tcc,v
retrieving revision 1.1
diff -c -p -r1.1 string.tcc
*** string.tcc 2000/10/05 11:27:01 1.1
--- string.tcc 2000/11/16 00:55:09
*************** namespace std
*** 44,66 ****
{
template<typename _CharT, typename _Traits, typename _Alloc>
! _CharT
basic_string<_CharT, _Traits, _Alloc>::
_Rep::_S_terminal = _CharT();
template<typename _CharT, typename _Traits, typename _Alloc>
! typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
_Rep::_S_max_size = (((npos - sizeof(_Rep))/sizeof(_CharT)) - 1) / 4;
template<typename _CharT, typename _Traits, typename _Alloc>
! const basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::npos;
// Linker sets _S_empty_rep_storage to all 0s (one reference, empty string)
// at static init time (before static ctors are run).
template<typename _CharT, typename _Traits, typename _Alloc>
! basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::_S_empty_rep_storage[
(sizeof(_Rep) + sizeof(_CharT) + sizeof(size_type) - 1)/sizeof(size_type)];
--- 44,66 ----
{
template<typename _CharT, typename _Traits, typename _Alloc>
! const _CharT
basic_string<_CharT, _Traits, _Alloc>::
_Rep::_S_terminal = _CharT();
template<typename _CharT, typename _Traits, typename _Alloc>
! const typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
_Rep::_S_max_size = (((npos - sizeof(_Rep))/sizeof(_CharT)) - 1) / 4;
template<typename _CharT, typename _Traits, typename _Alloc>
! const typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::npos;
// Linker sets _S_empty_rep_storage to all 0s (one reference, empty string)
// at static init time (before static ctors are run).
template<typename _CharT, typename _Traits, typename _Alloc>
! typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::_S_empty_rep_storage[
(sizeof(_Rep) + sizeof(_CharT) + sizeof(size_type) - 1)/sizeof(size_type)];