C++ Logo

liaison

Advanced search

Re: [wg14/wg21 liaison] A request for feedback on "P2152: Querying the Alignment of an Object [Aligning Alignment]"

From: Jens Maurer <Jens.Maurer_at_[hidden]>
Date: Sun, 3 Oct 2021 16:09:19 +0200
On 01/10/2021 12.37, Inbal Levi wrote:
>> I can't find any in the standard. Please list those
> I ment 'alignas(exp)' for example - 'alignas(obj)' even though it's undefined. I added examples to the paper (E.g. under [expr.const] section 10, N4892)

It is defined. "alignas(constant-expression)"; see [dcl.align].

And alignas(T...) is also defined there.

What exactly is unspecified here?

>> "The alignment of an object in C is resolved to the strictest amongst its members"
>> While I believe such a rule might be reasonable to provide explicitly (at least for standard-layout or trivial types), I fail to find it in WG14 N2573 6.7.5
> This appears on reference [6] in the paper. It's under '6.7.5 Alignment specifier' / section 5 (in N2596 C standard). To my understanding, this results from: "The combined effect of all alignment specifiers in a declaration shall not specify an alignment that is less strict than the alignment that would otherwise be required for the type of the object or member being declared."
> This does not exist on C++,

It does; see [dcl.align] p5.

>> [expr.alignof] talks about alignof(expr), but doesn't say what it means at all.
> I'll point out that I did avoid specifying the value of alignof(obj) on purpose (just like there is no explicit value specification of alignof(type-id),

That's wrong. We say

"An alignof expression yields the alignment requirement of its operand type."

With alignof(id-expression), there is no type as the operand, but an id-expression.
What's the result here?

"id-expression" needs to be italics and should have a cross-reference.

What if the id-expression designates a bit-field?

> I refer to it as an issue, it's only mentioned that it cannot be smaller than the alignment value if it was omitted). I also refer in the paper to implementation details and Itanium ABI.

{expr.alignof] needs a change to the alignof grammar to allow id-expression
and class member access expressions (apparently, you want to restrict to these;
fine).

>> [dcl.align] This wording should move to [basic.align], saying that the alignment requirement of a (trivial? standard-layout?) class type is the strictest alignment of its non-static data members or so.
> The change in [dcl.align] is an attempt to 'fix' the paragraph to be like in C, in order to address the issue brought up in the previous section. I removed this.
[basic.align] The sentence about "object type" should come first,
and then the standard-layout class type thing.

"the alignment of an entity"

Do you mean object here?

> We already have under section [basic.align/1]: "An object type imposes an alignment requirement on every object of that type; stricter alignment can be requested using the alignment specifier", but I feel comfortable with adding wording as you suggested.

"and equals alignof(decltype(obj));" feels duplicate with [expr.alignof].

Jens

Received on 2021-10-03 09:09:26