Skip to content
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

[expr.sizeof]p2 makes an unjustified inference about the size of an array #4794

Open
zygoloid opened this issue Aug 5, 2021 · 0 comments · May be fixed by #4808
Open

[expr.sizeof]p2 makes an unjustified inference about the size of an array #4794

zygoloid opened this issue Aug 5, 2021 · 0 comments · May be fixed by #4808
Assignees

Comments

@zygoloid
Copy link
Member

zygoloid commented Aug 5, 2021

We have:

When applied to an array, the result is the total number of bytes in the array. This implies that the size of an array of n elements is n times the size of an element.

That's the intent, but it's not implied by the other rules we specify, and starting this sentence with "This implies that" makes it sound like it's not adding a normative requirement, which it is. I think this is implied (weakly) for arrays of class types, where we say:

When applied to a class, the result is the number of bytes in an object of that class including any padding required for placing objects of that type in an array.

But even that doesn't seem to disallow, say, allocating some constant amount of extra space at the start of the array to store a bound.

Perhaps:

When applied to an array, the result is the total number of bytes in the array. This implies that the size of an array of n elements, the result is n times the size of an element.

? The "the result is the total number of bytes in the array" part seems redundant anyway, given p1:

The sizeof operator yields the number of bytes occupied by a non-potentially-overlapping object of the type of its operand.

@jensmaurer jensmaurer self-assigned this Aug 12, 2021
@jensmaurer jensmaurer linked a pull request Aug 12, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants