www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20670] New: immutable template specialization pattern matches

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

          Issue ID: 20670
           Summary: immutable template specialization pattern matches
                    immutable struct, strips immutable
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: default_357-line yahoo.de

Consider an immutable struct:

```
immutable struct S { }
```

Let's define a template specialization that tries to strip away immutable from
a type, like Unqual.

```
mixin template Foo(T) { static assert(is(S == T)); }

mixin template Foo(T: immutable U, U) {
  pragma(msg, U.stringof);
  // even if this matches, S should still be S. There is only one S.
  static assert(is(S == U));
}
```

Let's apply it to our immutable struct:

```
mixin Foo!S;
```

Since 2.076.1, it takes the second template and fails with the static assert!
We've somehow  managed to take a struct type and strip away its inherent
constness attribute.

This is of course very bad. If we define S as `immutable struct S`, we should
not be able by any mechanism to get the non-immutable struct S back out.

--
Mar 13