[Issue 20142] Incorrect auto ref inference for manifest constant member

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Dec 10 00:19:09 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=20142

Basile-z <b2.temp at gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |b2.temp at gmx.com
                 OS|Linux                       |All

--- Comment #3 from Basile-z <b2.temp at gmx.com> ---
The reduced test case is not catching the problem anymore. This one does:

---
void empty(T)(auto /*const*/ ref T a) { }


struct Foo {
    int i;
}

void main() {
    enum Foo foo = Foo(0);
    foo.i.empty();
}
---

The regression is caused by a protection on function parameters (and on assign
exp too) to prevent writing member of manifest constants that are aggregates,
more specifically struct literals (`enum Foo foo` from the front-end POV is
actually a struct literal).

Without the protection, in the past, `i` could be modified, which made no sense
and could even create crashes.

See https://github.com/dlang/dmd/pull/10115, which added the protection.

--


More information about the Digitalmars-d-bugs mailing list