Unexpected undefined behavior when assigning a function pointer to std::mem::zeroed() #51615
Labels
A-docs
Area: Documentation for any part of the project, including the compiler, standard library, and tools
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
P-medium
Medium priority
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
Note: the following behavior only exists when compiling with optimizations (a.k.a. release mode).
Example 1:
This emits (as of 1.26.0):
Whereas it used to have expected behavior up until 1.19.0:
Example 2:
A bit of an odd case I discovered, which results in what seems to be some stack corruption:
Playground link
What I think is striking here is that this behavior occurs while never even dereferencing the pointer!. This allows one to shoot oneself in the foot when trying to, for example, set a default value for a function pointer member.
The text was updated successfully, but these errors were encountered: