-
Notifications
You must be signed in to change notification settings - Fork 7
CWG2719 [intro.object] p3 The provided storage should satisfy the alignment requirement of the created object #294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
[basic.align] p1 seems already sufficient. I think the intent is that when there's no suffient size after an properly aligned address for a |
We do not say so. The rule simply states that the array will provide storage for the object if the bullets in the list are met. Even the referenced subclause [expr.new] does not place the requirement.
|
This is sufficient. When it's possible to say the storage for the new object, the storage must be properly aligned to be so ([basic.align] p1). |
That's insufficient. Whether the lifetime of an object has begun or ended does not mean that the object is created or not. This is implied by [intro.object] p2
A member subobject is called an object regardless of whether the object is within its lifetime or not. Moreover, in terms of creating object, we just say
Creating an object is unconditional as long as it's the case recorded in the rule. |
Incidentally, [basic.align] p1 use "may", "can" rather than "shall"
The [intro.object] example-1 implies the point struct A { unsigned char a[32]; };
struct B { unsigned char b[16]; };
A a;
B *b = new (a.a + 8) B; // a.a provides storage for *b
int *p = new (b->b + 4) int; // b->b provides storage for *p
// a.a does not provide storage for *p (directly),
// but *p is nested within a (see below)
|
And why it should?
So an array will provide storage for an object whose lifetime has never started (or, rather, this should be fixed separately and become UB) |
I don't see the relation. The member subobject or array element may be not created before. There may be gaps in the specification that may allow some operations to create an object without starting lifetime, which needs to be fixed IMO. |
@frederick-vs-ja See my last comment, which literally negates your opinion: an object won't be created at the storage that does not satisfy the alignment requirement of the object. It is indeed created, merely its lifetime never begins. |
I don't think this can be right. I think [basic.align] p1 imposes a precondition to object creation. How can an object be created at an address where it can't be allocated? |
See #294 (comment), I agree with @languagelawyer here, that is, the object is indeed created. |
So how do you interpret [basic.align] p1 in this case? If we claim that the object is created, then it seems unavoidable to conclude that the object is allocated at some address that violates [basic.align] p1. |
As I said in the above comment, the wording uses "may", and "can" modal verbs, which arguably is a suggestion. If the wording implies the intent as you said, it should say:
Actually, the current wording does not imply this meaning. |
As a side note, the "may" here conveys permission, not possibility, per ISO drafting rules. In any case, I think we should explicitly say somewhere that it's undefined behavior to attempt to create an object in too-small storage or in misaligned storage. This also covers implicitly created objects, because possibly implicitly-created objects that are too big to fit into the storage won't satisfy the "no UB" rule and thus won't be created to start with. |
Such reading seems contradictory. If the first sentence of [basic.align] p1 can be merely a suggestion, then it's wrong to say "place restrictions". |
Full name of submitter (unless configured in github; will be published with the issue): Jim X
[intro.object] p3 says
No bullet in the list explicitly mentions the alignment requirement of the object being created. [basic.life] p1 says
The array with the element of type unsigned char or std::byte has the weakest alignment requirement per [basic.align] p6 and [expr.alignof] p3. That is, the storage provided by the array is not necessary to satisfy the alignment requirement of the object being created.
The text was updated successfully, but these errors were encountered: