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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Dec 7 13:28:32 UTC 2021


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

RazvanN <razvan.nitu1305 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from RazvanN <razvan.nitu1305 at gmail.com> ---
(In reply to Basile-z from comment #3)
> 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.

I cannot reproduce this. Running this code:

void empty(T)(auto ref T a)
{
    pragma(msg, __traits(isRef, a));
}


struct Foo {
    int i;
}

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

Yields `false` which is correct. Closing as fixed, please reopen if I am
missing something.

--


More information about the Digitalmars-d-bugs mailing list