[Issue 13488] New: [reg] implicit conversions to immutable broken

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Sep 16 23:59:24 PDT 2014


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

          Issue ID: 13488
           Summary: [reg] implicit conversions to immutable broken
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: regression
          Priority: P1
         Component: DMD
          Assignee: nobody at puremagic.com
          Reporter: bugzilla at digitalmars.com

I had this working earlier, but subsequent fixes broke it:

    struct T {
      const(int)* p = null;
      this(const(int)* q) pure {
        p = q;
      }
    }

  void foo() {
    int x;
    T p1 = T(&x);            // ok
//    immutable(T) p2 = T(&x); // error
    immutable int y;
    immutable(T) p3 = T(&y); // line 14, should be ok
    immutable(T)* p4 = new T(&y); // line 15, should be ok
  }

C:\cbx\mars>dmd -c foo
DMD v2.066 DEBUG
foo.d(14): Error: cannot implicitly convert expression ((T __ctmp2 = T;
 , __ctmp2).this(& y)) of type T to immutable(T)
foo.d(15): Error: cannot implicitly convert expression (new T(& y)) of type T*
to immutable(T)*

The non-constructor version of it also fails:

    struct S {
      const(int)* p;
    }

  void bar() {
    int x;
//    immutable(S)* q1 = new S(&x);      // Error, &x is not unique
    immutable(S)* q2 = new S(null);    // Ok
    immutable y = 3;
    immutable(S)* q3 = new S(&y);      // line 11, this should work
    immutable(S)* q4 = new S(new int); // Ok
    immutable(int)* i2;
    immutable(S)* q5 = new S(i2);      // line 14, this should work
    pure int* foo();
    immutable(S)* q6 = new S(foo());   // Ok
  }

C:\cbx\mars>dmd -c foo2
DMD v2.066 DEBUG
foo2.d(11): Error: cannot implicitly convert expression (new S(& y)) of type S*
to immutable(S)*
foo2.d(14): Error: cannot implicitly convert expression (new
S(cast(const(int)*)i2)) of type S* to immutable(S)*

It's critical that these get fixed.

--


More information about the Digitalmars-d-bugs mailing list