This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
Re: libstdc++/8670: Alignment problem in std::basic_string
- From: Martin Sebor <sebor at roguewave dot com>
- To: nobody at gcc dot gnu dot org
- Cc: gcc-prs at gcc dot gnu dot org,
- Date: 21 Nov 2002 18:06:01 -0000
- Subject: Re: libstdc++/8670: Alignment problem in std::basic_string
- Reply-to: Martin Sebor <sebor at roguewave dot com>
The following reply was made to PR libstdc++/8670; it has been noted by GNATS.
From: Martin Sebor <sebor@roguewave.com>
To: gcc-gnats@gcc.gnu.org
Cc:
Subject: Re: libstdc++/8670: Alignment problem in std::basic_string
Date: Thu, 21 Nov 2002 11:05:54 -0700
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8670
This caught my eye because we had the same problem some time ago
(our reference counted implementation of string is similar to yours).
Quickly looking at your code, the alignment bug is due to
_CharT*
basic_string<_CharT>::_Rep::_M_refdata() throw()
{ return reinterpret_cast<_CharT*>(this + 1); }
and the definition of basic_string<_CharT>::_Rep
struct _Rep
{
size_type _M_length;
size_type _M_capacity;
_Atomic_word _M_references;
...
};
which may not have the same alignment requirement as _CharT. The
trick we use is to change _Rep along the lines of
struct _Rep
{
size_type _M_length;
size_type _M_capacity;
union {
_CharT _M_align;
_Atomic_word _M_references;
} _M_ref;
...
};
Note that this change will enforce the requirement that _CharT
be a POD type.
Regards
Martin