This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
PATCH:stl/stl_alloc.h triggers compiler warnings
- To: libstdc++@sourceware.cygnus.com
- Subject: PATCH:stl/stl_alloc.h triggers compiler warnings
- From: Nathan Sidwell <nathan@acm.org>
- Date: Wed, 28 Apr 1999 08:56:57 +0100
- Organization: University of Bristol
- Reply-To: nathan@compsci.bristol.ac.uk
Hi,
attached is a patch to stl/stl_alloc.h, to stop it triggering egcs compiler
warnings when -Wcast-align has been given to the compiler. If you compile with
-Wcast-align, to catch potential problems in your own code, it is rather
disturbing that each instantiation of an allocator produces several!
The default allocator contains code of the form ((T *)ptr), where ptr is a char
*. A T might be more strictly aligned, and so the compiler warns. However, a
correctly working allocator will not cause a problem here (and the default
allocator better be correct!), so it'd be nice to tell the compiler we know
what's going on. The way to do that is via a void *, as in ((T *)(void *)ptr).
Let me know if you need a copyright assignment for this (it looks small enough
to not need one to me, but IANAL) -- it won't be a problem providing one.
Enjoy,
nathan
--
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
You can up the bandwidth, but you can't up the speed of light
nathan@acm.org http://www.cs.bris.ac.uk/~nathan/ nathan@cs.bris.ac.uk
libstdc++/stl/ChangeLog:
Wed Apr 28 08:42:25 BST 1999 Nathan Sidwell <nathan@acm.org>
* stl_alloc.h (__default_alloc_template): Convert pointers via
void *, to avoid alignment warnings.
Index: egcs/libstdc++/stl/stl_alloc.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/libstdc++/stl/stl_alloc.h,v
retrieving revision 1.6
diff -c -3 -p -r1.6 stl_alloc.h
*** stl_alloc.h 1999/02/04 15:51:42 1.6
--- stl_alloc.h 1999/04/27 15:01:10
*************** __default_alloc_template<__threads, __in
*** 484,491 ****
_Obj* __VOLATILE* __my_free_list =
_S_free_list + _S_freelist_index(__bytes_left);
! ((_Obj*)_S_start_free) -> _M_free_list_link = *__my_free_list;
! *__my_free_list = (_Obj*)_S_start_free;
}
_S_start_free = (char*)malloc(__bytes_to_get);
if (0 == _S_start_free) {
--- 484,491 ----
_Obj* __VOLATILE* __my_free_list =
_S_free_list + _S_freelist_index(__bytes_left);
! ((_Obj*)(void *)_S_start_free) -> _M_free_list_link = *__my_free_list;
! *__my_free_list = (_Obj*)(void *)_S_start_free;
}
_S_start_free = (char*)malloc(__bytes_to_get);
if (0 == _S_start_free) {
*************** __default_alloc_template<__threads, __in
*** 539,549 ****
__my_free_list = _S_free_list + _S_freelist_index(__n);
/* Build free list in chunk */
! __result = (_Obj*)__chunk;
! *__my_free_list = __next_obj = (_Obj*)(__chunk + __n);
for (__i = 1; ; __i++) {
__current_obj = __next_obj;
! __next_obj = (_Obj*)((char*)__next_obj + __n);
if (__nobjs - 1 == __i) {
__current_obj -> _M_free_list_link = 0;
break;
--- 539,549 ----
__my_free_list = _S_free_list + _S_freelist_index(__n);
/* Build free list in chunk */
! __result = (_Obj*)(void *)__chunk;
! *__my_free_list = __next_obj = (_Obj*)(void *)(__chunk + __n);
for (__i = 1; ; __i++) {
__current_obj = __next_obj;
! __next_obj = (_Obj*)(void *)((char*)__next_obj + __n);
if (__nobjs - 1 == __i) {
__current_obj -> _M_free_list_link = 0;
break;