[PATCH] Define max_align_t in C++11 and C11 mode
Howard Hinnant
hhinnant at apple.com
Mon Oct 21 12:33:43 PDT 2013
Please don't post GPL-copyrighted material to this mailing list. It makes the lawyers unhappy and the rest of us nervous.
This code:
#include <iostream>
#include <cstddef>
int
main()
{
std::cout << alignof(std::max_align_t) << '\n';
}
$ clang++ -std=c++11 -stdlib=libc++ test.cpp -arch i386
for me outputs:
16
on OS X, in both 32-bit and 64-bit modes. I have no opinion on what type max_align_t should have, except that it should continue to output alignof == 16 on Apple platforms, that it be a trivially copyable type, and that it not be encumbered with GPL (the latter two requirements do not come from any standard).
I find myself wondering if this question should not be answered by the compiler with a pre-defined macro, perhaps:
_MAX_ALIGN
And then stddef.h/cstddef could do:
struct alignas(_MAX_ALIGN) max_align_t {};
I searched clang's predefined macros, but did not find anything like this (I could have missed it).
Howard
On Oct 20, 2013, at 8:55 PM, David Majnemer <david.majnemer at gmail.com> wrote:
> [CC'ing Howard seeing as how he probably implemented the libc++ max_align_t]
>
> Howard, what do you have thoughts on this?
>
> My reading of 3.11 [basic.align]/p2's 'all contexts' makes me believe that max_align_t should reflect the alignment of 'long double' inside of a struct.
>
>
> On Fri, Oct 18, 2013 at 10:10 PM, Hristo Venev <mustrumr97 at gmail.com> wrote:
> libc++ defines max_align_t as long double. I thought they had the same alignment.
>
>
> On Fri, Oct 18, 2013 at 8:22 PM, David Majnemer <david.majnemer at gmail.com> wrote:
> This implementation of max_align_t disagrees with gcc. They have something like:
> typedef struct {
> long long __max_align_ll __attribute__((__aligned__(__alignof__(long long))));
> long double __max_align_ld __attribute__((__aligned__(__alignof__(long double))));
> } max_align_t;
>
> as their definition while you have something like:
>
> typedef long double max_align_t;
>
> For a 32-bit x86 target, this means that:
> gcc's alignof(max_align_t): 8
> clang's alignof(max_align_t): 4
>
> --
> David Majnemer
>
>
> On Fri, Oct 18, 2013 at 9:58 AM, Hristo Venev <mustrumr97 at gmail.com> wrote:
> Add a definition of max_align_t in stddef.h
> Done by gcc 4.9 and required by libstdc++ 4.9.
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
>
>
More information about the cfe-commits
mailing list