Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
March 31, 2016 [Issue 15842] struct is being copied when returned directly | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=15842 hsteoh@quickfur.ath.cx changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords|wrong-code | CC| |hsteoh@quickfur.ath.cx --- Comment #1 from hsteoh@quickfur.ath.cx --- I'm pretty sure this behaviour is according to spec. Structs are supposed to behave like glorified ints, meaning they are value types and may be freely copied around and moved when passing between functions. This is one reason it's a bad idea to keep internal pointers to a struct, as the pointers will become invalid once the struct is moved. Returning a struct from a function is generally implemented as storing in a temporary area on the stack, and moving to the final stack variable once control returns to the caller. -- |
March 31, 2016 [Issue 15842] struct is being copied when returned directly | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=15842 --- Comment #2 from hsteoh@quickfur.ath.cx --- (Small structs may also be returned via registers alone, but I surmise that using & on the struct will suppress this.) -- |
June 12, 2018 [Issue 15842] struct is being copied when returned directly | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=15842 RazvanN <razvan.nitu1305@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |razvan.nitu1305@gmail.com Resolution|--- |FIXED --- Comment #3 from RazvanN <razvan.nitu1305@gmail.com> --- Running both examples in the original bug report on master git HEAD results in printing the same address. Closing as fixed. -- |
June 12, 2018 [Issue 15842] struct is being copied when returned directly | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=15842 --- Comment #4 from Atila Neves <atila.neves@gmail.com> --- I'd only close the bug if there's a test in the testsuite that would fail if the current behaviour ever changes. -- |
June 12, 2018 [Issue 15842] struct is being copied when returned directly | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=15842 Steven Schveighoffer <schveiguy@yahoo.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |schveiguy@yahoo.com --- Comment #5 from Steven Schveighoffer <schveiguy@yahoo.com> --- What is there to test? Either way is valid -- you can have the struct constructed in one location, and then moved to the return value, or you can have it constructed in place for the return value. There is no postblit or dtor, so the struct is movable without any notification. IMO, this should be resolved INVALID. -- |
Copyright © 1999-2021 by the D Language Foundation