On Saturday, 9 October 2021 at 05:46:50 UTC, jfondren wrote:>
I don't quite get it, but it looks like your
enum T A is treated like a manifest constant
Note, the spec doesn't have the "copy and paste" language that people use to describe the pitfall with enum array literals. I think that behavior's purely implied by enums not referring to runtime locations:>
Manifest constants are not lvalues, meaning their address cannot be taken. They exist only in the memory of the compiler.
Better, the manifest constant has no runtime location in the executable.
const T A version,
A.b refers to a specific location in the process's memory. With the
enum T A version,
A.b since it's in a runtime context must build the struct on the spot, and since the struct is mutable (unlike a string's bytes) it must be freshly constructed on each occurrence.