Skip to content

P2795 R5 Erroneous behaviour for uninitialized reads #1460

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

Closed
ben-craig opened this issue Feb 10, 2023 · 22 comments · Fixed by cplusplus/draft#6897
Closed

P2795 R5 Erroneous behaviour for uninitialized reads #1460

ben-craig opened this issue Feb 10, 2023 · 22 comments · Fixed by cplusplus/draft#6897
Labels
C++26 Targeted at C++26 CWG Core LWG Library plenary-approved Papers approved for inclusion in their target vehicle by plenary vote. SG22 C / C++ liaison
Milestone

Comments

@ben-craig
Copy link

ben-craig commented Feb 10, 2023

P2795R0 Correct and incorrect code, and “erroneous behaviour” (Thomas Köppe)

@ben-craig ben-craig added the EWG Evolution label Feb 10, 2023
@erichkeane
Copy link
Collaborator

EWG discussed this paper during the February 10th, 2023 morning session in Issaquah. The following poll was taken:

EWG is interested in adding the concept of erroneous behavior as an alternative to undefined behavior, as proposed in D2795R0.

SF F N A SA
11 13 10 7 1

Result: Not Consensus

@erichkeane erichkeane added the needs-revision Paper needs changes before it can proceed label Feb 10, 2023
@ben-craig
Copy link
Author

D2795R0

SG23 (Safety and Security) saw this paper on Feb 9 in Issaquah.

Presenter: Thomas Köppe
Chair: Roger Orr, Ben Craig
Minutes: Mungo Gill

POLL: Do we want the standard to be able to speak in terms of erroneous behavior in addition to undefined behavior

Strongly Favor Weakly Favor Neutral Weakly Against Strongly Against
14 18 10 7 1

Outcome: Weak consensus

SA: My vote would be altered if I saw concrete example in the standard were undefined would turn to erroneous. Worried we will add complexity without solving a problem

A: Need more examples. Need examples of what compiler should do instead.

@erichkeane
Copy link
Collaborator

erichkeane commented Jun 15, 2023

EWG discussed D2795R1 on Thursday Morning in Varna. The following poll was taken:

EWG approves D2795R1, which changes uninitialized automatic variable use to be erroneous behavior, and forwards it to CWG.

SF F N A SA
16 21 7 2 3

Result: Consensus

Note: The chair failed to include "for inclusion in C++26" in the poll wording, however believes that this was a well understood consequence of the poll, so does not require re-polling.

@erichkeane erichkeane added CWG Core and removed EWG Evolution needs-revision Paper needs changes before it can proceed labels Jun 15, 2023
@jensmaurer jensmaurer added the needs-revision Paper needs changes before it can proceed label Jun 15, 2023
@jensmaurer
Copy link
Member

CWG 2023-06-15: Reviewed; needs updates.

@jensmaurer jensmaurer added EWG Evolution and removed CWG Core needs-revision Paper needs changes before it can proceed labels Jun 16, 2023
@jensmaurer
Copy link
Member

jensmaurer commented Jun 16, 2023

CWG 2023-06-16: Reviewed; wording looks good.

Consensus: CWG is unhappy with forwarding this paper without an integrated opt-out mechanism for this particular application of "erroneous behavior".

We also noticed that this feature is a potential performance pessimization even if a constructor fully initializes an object, because now the initialization of all padding is required.

@wg21bot
Copy link
Collaborator

wg21bot commented Jul 21, 2023

P2795R1 Erroneous behaviour for uninitialized reads (Thomas Köppe)

@wg21bot wg21bot added this to the 2023-telecon milestone Jul 21, 2023
@wg21bot wg21bot changed the title P2795 Correct and incorrect code, and “erroneous behaviour” P2795 R1 Erroneous behaviour for uninitialized reads Jul 21, 2023
@wg21bot
Copy link
Collaborator

wg21bot commented Jul 21, 2023

P2795R2 Erroneous behaviour for uninitialized reads (Thomas Köppe)

@wg21bot wg21bot changed the title P2795 R1 Erroneous behaviour for uninitialized reads P2795 R2 Erroneous behaviour for uninitialized reads Jul 21, 2023
@wg21bot wg21bot changed the title P2795 R2 Erroneous behaviour for uninitialized reads P2795 R1 Erroneous behaviour for uninitialized reads Jul 21, 2023
@wg21bot wg21bot changed the title P2795 R1 Erroneous behaviour for uninitialized reads P2795 R2 Erroneous behaviour for uninitialized reads Jul 21, 2023
@wg21bot wg21bot changed the title P2795 R2 Erroneous behaviour for uninitialized reads P2795 R1 Erroneous behaviour for uninitialized reads Jul 21, 2023
@wg21bot wg21bot changed the title P2795 R1 Erroneous behaviour for uninitialized reads P2795 R2 Erroneous behaviour for uninitialized reads Jul 21, 2023
@wg21bot
Copy link
Collaborator

wg21bot commented Aug 23, 2023

P2795R3 Erroneous behaviour for uninitialized reads (Thomas Köppe)

@wg21bot wg21bot changed the title P2795 R2 Erroneous behaviour for uninitialized reads P2795 R3 Erroneous behaviour for uninitialized reads Aug 23, 2023
@jfbastien
Copy link
Collaborator

jfbastien commented Nov 7, 2023

EWG reviewed this on Kona on Monday.

Poll:forward P2795r3 “Erroneous behaviour for uninitialized reads” to CWG for inclusion in C++26, but also provide EB for all automatic variables (including function parameters and temporary objects).

SF F N A SA
6 14 4 3 2

Consensus.

Poll: forward P2795r3 “Erroneous behaviour for uninitialized reads” to CWG for inclusion in C++26 as is.

SF F N A SA
8 7 7 4 5

Not consensus.

@jfbastien jfbastien added LWG Library and removed EWG Evolution labels Nov 7, 2023
@jensmaurer

This comment was marked as outdated.

@jensmaurer
Copy link
Member

jensmaurer commented Nov 10, 2023

CWG 2023-11-09: Reviewed.

@jensmaurer
Copy link
Member

CWG 2023-11-10: Reviewed; needs updates.

@jensmaurer jensmaurer added the needs-revision Paper needs changes before it can proceed label Nov 11, 2023
@jensmaurer
Copy link
Member

This has a small bit of library wording that is unlikely to be affected by further CWG review, but (of course) needs to be seen by LWG.

@jensmaurer jensmaurer added the LWG Library label Nov 22, 2023
@wg21bot
Copy link
Collaborator

wg21bot commented Dec 19, 2023

P2795R4 Erroneous behaviour for uninitialized reads (Thomas Köppe)

@wg21bot wg21bot removed the needs-revision Paper needs changes before it can proceed label Dec 19, 2023
@wg21bot wg21bot modified the milestones: 2023-telecon, 2024-telecon Dec 19, 2023
@wg21bot wg21bot changed the title P2795 R3 Erroneous behaviour for uninitialized reads P2795 R4 Erroneous behaviour for uninitialized reads Dec 19, 2023
@jensmaurer
Copy link
Member

CWG 2024-03-19: Reviewed D2795R5 and approved for Saturday's plenary vote.

Still outstanding: LWG approval for the library parts.

@jensmaurer
Copy link
Member

CWG 2024-03-21: Reviewed LWG updates of D2795R5; needs re-review of LWG changes.

Question to EWG: This feature does not change the net "undefined behavior" situation for uninitialized variables of bool and pointer types (or uninitialized members of that type), because the initialization with erroneous values can't guarantee a valid value for those types. Is that accepted?

@jensmaurer jensmaurer added the EWG Evolution label Mar 21, 2024
@jfbastien jfbastien added the SG22 C / C++ liaison label Mar 21, 2024
@erichkeane
Copy link
Collaborator

erichkeane commented Mar 21, 2024

EWG discussed this during the Friday Morning session in Tokyo. The following poll was taken:

Poll: D2795R5: Erroneous behavior for uninitialized reads: EWG agrees that EB may create values which later trigger UB, for example an EB read of a pointer has a defined value but dereferencing the pointer may then be UB.

SF F N A SA
5 7 3 0 0

Result: Consensus

@erichkeane erichkeane removed the EWG Evolution label Mar 21, 2024
@jensmaurer
Copy link
Member

CWG 2024-03-22: Approved for Saturday's plenary straw polls.

@cor3ntin cor3ntin added the plenary-approved Papers approved for inclusion in their target vehicle by plenary vote. label Mar 23, 2024
@jensmaurer jensmaurer modified the milestones: 2024-telecon, 2024-03 Apr 3, 2024
@wg21bot
Copy link
Collaborator

wg21bot commented Apr 17, 2024

P2795R5 Erroneous behaviour for uninitialized reads (Thomas Köppe)

@wg21bot wg21bot changed the title P2795 R4 Erroneous behaviour for uninitialized reads P2795 R5 Erroneous behaviour for uninitialized reads Apr 17, 2024
@ByteEater-pl
Copy link

A change from the earlier revision P2795R0 is that the permission for an implementation to reject a translation unit “if it can determine that erroneous behaviour is reachable within that translation unit” has been removed: Richard Smith pointed out that such a determination is not generally possible. Any attempt to reject any erroneous behaviour at all would most likely have false positives

While the first sentence is true (a simple reduction from the halting problem can be shown), I find the second fragment surprising. There can be and indeed are such attempts successfully performed by compilers of other languages, by proof assistants and by tools used to analyze similar situations for software security purposes. Both deterministic and nondeterministic. None of them can be sound and complete, i.e. have neither false positives, nor negatives, but a wide span of cases (and quickly growing nowadays with advances in theory and practice of the field) can be usefully, and retaining soundness, statically determined.

Without allowing implementations to reject translation units based on its ability to prove it exhibits erroneous behaviour, the result is that erroneous behaviour wouldn't differ from defined behaviour in any hard way. Just an encouragement to emit warnings. Which can be emitted for defined behaviour too whenever the implementation considers something smelly. And thus the erroneous behaviour presumably will be treated as a feature and relied upon more than intended.

In summary, the change reduces the value of the proposal to almost nothing, it doesn't seem well argued (although I haven't acquainted myself with Richard Smith's original statement), and I propose to revert it.

@jensmaurer
Copy link
Member

@ByteEater-pl , this issue tracker is for administrative tracking of in-flight WG21 papers. Any technical discussion should happen in the appropriate venues, e.g. on the committee reflectors or during committee meetings. Also note that the paper in question has been approved for the C++ working draft; if you wish to argue for it to be reverted, please write a paper for WG21 to consider, containing strong rationale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++26 Targeted at C++26 CWG Core LWG Library plenary-approved Papers approved for inclusion in their target vehicle by plenary vote. SG22 C / C++ liaison
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

7 participants