[Issue 19763] New: Cannot construct immutable struct from pure mutable struct
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Tue Mar 26 12:04:31 UTC 2019
    
    
  
https://issues.dlang.org/show_bug.cgi?id=19763
          Issue ID: 19763
           Summary: Cannot construct immutable struct from pure mutable
                    struct
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: doob at me.com
The following example fails to compile:
struct Foo
{
    const(char)* filename;
    this(const(char)*) pure { }
}
void main()
{
    immutable a = Foo(null);
}
Error:
cannot implicitly convert expression `Foo(null).this(null)` of type `Foo` to
`immutable(Foo)`
But this code compiles:
struct Foo
{
    const(char)* filename;
    this(const(char)*) pure { }
}
Foo newFoo() pure
{
    return Foo(null);
}
void main()
{
    immutable a = newFoo();
}
Also if "const(char)* filename" is changed to "char* filename" the first
example compiles.
--
    
    
More information about the Digitalmars-d-bugs
mailing list