https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79024

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Xidorn Quan from comment #2)
> ABI requires a different alignment than in struct?

Yes.

> That's interesting. But I
> think developers (I mean, users of compilers) are generally more interested
> on alignment requirement in struct rather than that for ABI, and most
> description of the concept "alignment" refers to that in struct, so it is
> probably better make alignof / alignas report that value.

It's arguable whether that would be standard conforming. alignas(T) tells you
the alignment needed for an obejct of type T. If you want the alignment for a
subobject of type T that's a different question, and you can get it by doing:

struct S { T t; };
alignas(S)

Or more generally:

template<typename T>
  struct alignof_subobject
  {
    struct S { T t; };
    static constexpr std::size_t value = alignof(S);
  };

struct Test2 { char c; alignas(alignof_subobject<uint64_t>::value) uint64_t u;
};

Reply via email to