Boost logo

Boost :

Subject: Re: [boost] boost::aligned_storage broken on VC12 for alignment values of 8
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2014-03-30 12:22:28


On 30/03/14 08:41, Glen Fernandes wrote:
> Very surprising, but easily reproducible with VC12 (2013), Release or
> Debug configuration, Win32 platform: the following program will often*
> throw:
>
> #include <boost/type_traits/aligned_storage.hpp>
> #include <cstdint>
> int main()
> {
> boost::aligned_storage<8, 8>::type a;
> if (((std::uintptr_t)&a % 8) != 0) {
> throw 1;
> }
> }
>
> * Four of every five times it failed because the storage was only
> 4-byte aligned, not 8-byte aligned.
>
> Does not reproduce for x64 builds, just x86 builds. Does not reproduce
> with alignment values other than 8.

AFAIK, with Windows 32-bit, you cannot reliably have an object with
alignment greater than 4 on the stack.

Use dynamic memory allocation.


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