Boost logo

Boost :

From: Markus Schöpflin (markus.schoepflin_at_[hidden])
Date: 2004-08-24 07:40:49


Joaquín Mª López Muñoz wrote:

> Most templates in these header take an alignment parameter
> of type size_t, yet a few of them accept an int instead:
>
> is_aligned
> type_with_alignment
>
> These causes in some compilers nasty truncation warnings when using
> aligned_storage with its default alignment_ parameter (maximum
> alignment)

[snip]

> 1. Is there any fundamental reason why some alingment parameters are
> int instead of size_t?
> 2. If not, any objection to fixing this in the CVS?
> 3. Could it be the other way around, namely that aligned_storage must
> use ints instead of size_t's?

Well I simply tried to change the ints to std::size_t to see what happens.
(See attached patch.) The truncation warnings are gone now and the test for
  type_with_alignment still passes.

Could any of the autors please (David Abrahams and/or Doug Gregor) please
verify that this is the correct way of dealing with the issue. If yes, I
will happily apply the patch myself.

TIA, Markus

Index: type_with_alignment.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/type_traits/type_with_alignment.hpp,v
retrieving revision 1.24
diff -u -r1.24 type_with_alignment.hpp
--- type_with_alignment.hpp 26 Jan 2004 12:20:03 -0000 1.24
+++ type_with_alignment.hpp 24 Aug 2004 12:19:25 -0000
@@ -158,7 +158,7 @@
 #undef BOOST_TT_CHOOSE_MIN_ALIGNMENT
 #undef BOOST_TT_CHOOSE_T
 
-template<int TAlign, int Align>
+template<std::size_t TAlign, std::size_t Align>
 struct is_aligned
 {
     BOOST_STATIC_CONSTANT(bool,
@@ -189,7 +189,7 @@
 
 // This alignment method originally due to Brian Parker, implemented by David
 // Abrahams, and then ported here by Doug Gregor.
-template <int Align>
+template <std::size_t Align>
 class type_with_alignment
 {
     typedef detail::lower_alignment<Align> t1;


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk