------- Additional Comments From ncm-nospam at cantrip dot org  2005-01-21 
15:22 -------
This is a real bug, but easily fixed, and (I think) without breaking ABI.

The problem is in basic_string.h, where it says

  struct _Rep : _Rep_base
  {
    // Types:
    typedef typename _Alloc::template rebind<char>::other _Raw_bytes_alloc;

Technically this should be "rebind<_Rep>::other".  Of course then 
it's not really a raw-bytes allocator, but we have no need for a 
raw_bytes allocator.  We need an allocator of space for a _Rep with 
room for raw bytes at the end.  Remaining to fix is to change the name 
in the very few places where it's used, and to change the argument to 
allocate() (and deallocate) so that it ends up allocating the right 
number of bytes.

Probably a better fix would be to use "rebind<T>::other", where 
T is the most strictly-aligned of members of _Rep, i.e. size_type 
or _Atomic_word.  This is easily determined as the union of the 
two:

  union { _Atomic_word w; size_type s; } _Alloc_unit;
  typedef typename _Alloc::template rebind<_Alloc_unit>::other _Raw_alloc;

and then scale the argument to allocate() by the size of _Alloc_unit.
Fortunately, the required "/ sizeof(_Alloc_unit)" may (will?) be 
weakened to ">> 2" or ">> 4" on all real targets.

Either way, then, it's up to __gnu_cxx::array_allocator<char_type, 
array_type> to make sure its argument is aligned properly.  If it 
can't, that's a (more serious) bug in that template.  The test case 
2.cc had better leave enough room in the byte array for that 
alignment adjustment, which it does not quite do, I think, on 64-bit 
targets.

Of course all this means this bug is not really an "enhancement",
but bugzilla won't let me fix that.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ncm-nospam at cantrip dot
                   |                            |org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19495

Reply via email to