[Issue 20670] immutable template specialization pattern matches immutable struct, strips immutable

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue May 10 19:34:18 UTC 2022


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

Dennis <dkorpel at live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dkorpel at live.nl
           Hardware|x86_64                      |All
                 OS|Linux                       |All

--- Comment #4 from Dennis <dkorpel at live.nl> ---
I don't think structs can have an 'inherent constness attribute'. The spec
says:

https://dlang.org/spec/struct.html#const-struct

> A struct declaration can have a storage class of const, immutable or shared. 
> It has an equivalent effect as declaring each member of the struct as const, immutable or shared.

So these structs are supposed to be treated the same:
```
immutable struct S0 { int n; }

struct S1 { immutable int n; }
```

Now note that even for S1, `is(S1 == immutable(S1))` does not hold.
I think the real issue is this:
```
pragma(msg, S0); // immutable(S0)
pragma(msg, S1); // S1
```
Referring to `S0` by name results in an `immutable(S0)` type instead of just
`S0` with immutable members.

--


More information about the Digitalmars-d-bugs mailing list