-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Safety comment in std::ptr::NonNull::dangling code was invalidated by a refactoring #132004
Copy link
Copy link
Closed
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsLibs-SmallLibs issues that are considered "small" or self-containedLibs issues that are considered "small" or self-containedT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsLibs-SmallLibs issues that are considered "small" or self-containedLibs issues that are considered "small" or self-containedT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
The implementation of the
std::ptr::NonNull::danglingfunction looked like this:until a recent change (b58f647) made it into this:
The code has changed, but the comment has not, and is now unrelated to the code.
Furthermore, it is unclear how to rewrite this comment correctly. The documentation of
std::ptr::dangling_mutfunction only guarantees that it “Creates a new pointer that is dangling, but well-aligned”. However, the documentation ofstd::ptrmodule defines a dangling pointer with “We say that a pointer is "dangling" if it is not valid for any non-zero-sized accesses. This means out-of-bounds pointers, pointers to freed memory, null pointers, and pointers created withNonNull::danglingare all dangling”. Since a dangling pointer can technically be null, the fact thatstd::ptr::dangling_mutreturns a non-null pointer is an undocumented behaviour. This means that the safety ofstd::ptr::NonNull::danglinghinges on an undocumented behavior of another function.