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

CWG2536 Zero-initialization in addition to constant initialization and stability of padding bits #1380

Open
jensmaurer opened this issue Dec 3, 2022 · 4 comments
Labels
EWG Evolution needs-revision Paper needs changes before it can proceed

Comments

@jensmaurer
Copy link
Member

See CWG2558 and CWG2536

CWG2558: Is it intentional that uninitialized subobjects can appear in prvalues returned by constant expressions?
P1331R2 dropped the corresponding restriction, but maybe that wasn't entirely intentional.

  struct A {
    int n;
    consteval A() {}
  };
  constexpr A a;

CWG2536: The variable a is a variable with static storage duration, which previously could not have subobjects with indeterminate value (because of zero-initialization). The status quo wording does permit such indeterminate values. Is that intentional?

@jensmaurer jensmaurer added the EWG Evolution label Dec 3, 2022
@jensmaurer jensmaurer changed the title CWG2558, CWG2536 Uninitialized subobjects as a result of an immediate invocation CWG2558, CWG2536 Uninitialized subobjects as a result of constant expressions Dec 3, 2022
@hubert-reinterpretcast
Copy link

hubert-reinterpretcast commented Dec 3, 2022

Note that the restriction explicitly dropped in P1331R2 was one that prevented the constructor from leaving subobjects uninitialized during evaluation of a core constant expression. It happens so that is was also the restriction that (aside from pointer types) prevented uninitialized subobjects from being part of the result of a constant expression.

A related question arises from the resolution of CWG2424, "constexpr initialization requirements for variant members": Is it intended that union results of a constant expression may have no active member?

Also note that the question of CWG2536 does not arise from the wording out of the case presented if the resolution to CWG2558 is that uninitialized subobjects cannot be part of the result of a constant expression. However, the question would then be whether there is a desire to prohibit dynamic initialization for the case presented by applying zero initialization before or after the fact (including to temporaries bound to references). The additional questions for a before-the-fact application of zero initialization is also the topic of CWG2301, "Value-initialization and constexpr constructor evaluation". Note that the status quo also allows constant-initialized variables of static storage duration to be statically initialized such that there is uninitialized padding.

Edits:

  • Added union with no active member case
  • Added note re: status quo allowance for uninitialized padding

@erichkeane
Copy link
Collaborator

This was discussed at the Jan, 19, 2023 CWG Issues Review

And the following polls were taken:
Uninitialized non-variant direct subobjects should not be allowed to appear in the result of a constant expression.

SF F N A SA
6 3 0 0 0

Result: Strong Consensus

Union types shall be initialized such that they have an active member in the result of a constant expression.

SF F N A SA
0 1 2 3 1

Result: Not Consensus

EWG confirms that padding bits and data belonging to non-active variant members are permitted to have indeterminate values in the static initialization of objects.

SF F N A SA
0 3 2 2 2

Result: Not Consensus

@erichkeane erichkeane added CWG Core and removed EWG Evolution labels Jan 19, 2023
@jensmaurer
Copy link
Member Author

@erichkeane , it seems to me that CWG2558 (Is it intentional that uninitialized subobjects can appear in prvalues returned by constant expressions?) was answered, and CWG will proceed to restrict constant expression results so that they contain no uninitialized members.

However, CWG2536 and the question whether zero-initialization of static and thread storage duration variables happens in addition to constant initialization and whether the padding bits that got zeroed that way have a stable value is unanswered, and still the subject of ongoing discussions on -ext. I've changed the subject of this issue accordingly and I'm giving this issue back to EWG.

@jensmaurer jensmaurer changed the title CWG2558, CWG2536 Uninitialized subobjects as a result of constant expressions CWG2536 Zero-initialization in addition to constant initialization and stability of padding bits Jan 21, 2023
@jensmaurer jensmaurer added EWG Evolution and removed CWG Core labels Jan 21, 2023
@jensmaurer jensmaurer added this to the 2023-telecon milestone Jan 25, 2023
@erichkeane
Copy link
Collaborator

This was discussed briefly in the February 6th, 2023 Afternoon session in Issaquah.

No polls were taken, as the room didn't feel comfortable with our understanding of the issue. We either need a paper, or to re-visit this with a CWG representative (@hubert-reinterpretcast ?).

@erichkeane erichkeane added the needs-revision Paper needs changes before it can proceed label Feb 7, 2023
@jensmaurer jensmaurer removed this from the 2023-telecon milestone Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
EWG Evolution needs-revision Paper needs changes before it can proceed
Projects
None yet
Development

No branches or pull requests

3 participants