Bug 22209 – NRVO variable detection ignoring `alias this` conversion => segfaults

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-08-14T04:19:17Z
Last change time
2021-08-14T10:16:48Z
Keywords
pull, wrong-code
Assigned to
No Owner
Creator
kinke

Comments

Comment #0 by kinke — 2021-08-14T04:19:17Z
This segfaults at runtime (for all versions currently on run.dlang.io): ``` struct U { size_t[4] a; } struct S { int x; U u; alias u this; } U foo() { S s = S(42, U([1, 2, 3, 4])); return s; } void main() { assert(foo().a[0] == 1); } ``` It's apparently caused by the frontend wrongly marking `s` in `foo()` as the NRVO variable (FuncDeclaration.nrvo_var), ignoring that it requires an implicit conversion via `alias this` - return type and variable type clearly differ.
Comment #1 by dlang-bot — 2021-08-14T07:47:38Z
@kinke created dlang/dmd pull request #12977 "Fix Issue 22209 - NRVO variable detection ignoring `alias this` conversion" fixing this issue: - Fix Issue 22209 - NRVO variable detection ignoring `alias this` conversion https://github.com/dlang/dmd/pull/12977
Comment #2 by dlang-bot — 2021-08-14T10:16:48Z
dlang/dmd pull request #12977 "Fix Issue 22209 - NRVO variable detection ignoring `alias this` conversion" was merged into master: - 0fc065aecf02d849b4502f1e1b2c2b72f6f4e0c0 by Martin Kinkelin: Fix Issue 22209 - NRVO variable detection ignoring `alias this` conversion https://github.com/dlang/dmd/pull/12977