cplusplus / cplusplus/draft

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

Open
#4,794 0 comments 0 reactions 1 assignee View on GitHub

@jensmaurer is already working on this.

Since Aug 12, 2021.

Dominant language
TeX
Stars
221
Forks
813
Avg merge
16h 4m
Merged PRs (30d)
36

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.