Boost logo

Boost :

Subject: Re: [boost] boost::aligned_storage broken on VC12 for alignment values of 8
From: John Maddock (boost.regex_at_[hidden])
Date: 2014-04-24 08:22:29

>> AFAIK, with Windows 32-bit, you cannot reliably have an object with
>> alignment greater than 4 on the stack.
> I have seen that VC has notoriously strange alignment and layout rules
> for 32-bit code. I wonder if that should inhibit making
> boost::aligned_storage<..., N>::type at least as reliable as VC12's
> std::aligned_storage<..., N>::type or __declspec(align(8)), both of
> which seem to work correctly.

Sorry to be so late in coming to this: this is both nasty but also
apparently unfixable, on the one hand, VC++ basically lies about the
alignment of some types:

int main(int argc, _TCHAR* argv[])
    typedef long long align_t;
    std::cout << __alignof(align_t) << std::endl;
    assert(__alignof(align_t) % 8 == 0); // OK
    align_t a;
    assert(((std::uintptr_t)&a % 8) == 0); // OK
    char c = 0;
    align_t a1;
    assert(((std::uintptr_t)&a1 % 8) == 0); // Fails
    return 0;

BTW this is true also of std::aligned_storage which also fails the final
assert above. If instead we had:

typedef __declspec(align(8)) struct some_struct_type align_t;

Then the asserts all pass, but now align_t can not be passed through a
function call by value. In fact this was a previous bug in the type
traits lib:

So we're basically screwed whatever we do.

Regards, John.

Boost list run by bdawes at, gregod at, cpdaniel at, john at