www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1417] New: templated final const member can't be assigned in constructor from the const const argument

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1417

           Summary: templated final const member can't be assigned in
                    constructor from the const const argument
           Product: D
           Version: 2.003
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: baryluk mpi.int.pl


----
import std.stdio;

class B(T) {
        T z;
        this(T _z) {
                z = _z;
        }
}

alias B!(int) Bi;
alias const(B!(int)) Bic;



class A {
        // final const(Bi) x;    // works
        // final const(Bic) x;    // works
        final const(B!(int)) x;    // doesn't


        this(const const(B!(int)) b) {
                x = b; // Error: cannot implicitly convert expression (_x) 
                                // of type const B to pr3.B!(int).B
                // x.z = 0; // fails. good
        }

        const void print() {
                writefln(x.z);
        }

        //void print2() {
                //x = new const(B!(int))(6) // fails. good
                //x.z = 6; // fails. good
        //}
}

void main() {
        const(B!(int)) b = new const(B!(int))(5);
        A a = new A(b);
        a.print(); // prints 5
}
----


similar problem:

----
class B(T) {
        T z;
}

alias B!(int) Bi;
alias const(B!(int)) Bic;



class A {
        // final const(Bi) x;    // works
        // final const(Bic) x;    // works
        final const(B!(int)) x;    // doesn't

        // const(B!(int)) x;    // works
        this() {
                x = new const(Bi)(); // Error: cannot implicitly convert
expression (_x) 
                                // of type const B to pr3.B!(int).B
                // x = new const(B!(int))(); // works
        }

}

void main() {
        A a = new A();
}
----

This bug prevents writing strictly const code with templates.


-- 
Aug 12 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1417


Witold Baryluk <baryluk smp.if.uj.edu.pl> changed:

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



13:27:44 PST ---

in v2.032. Probably working since 2.022.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 18 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1417


Witold Baryluk <baryluk smp.if.uj.edu.pl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |1410



13:28:20 PST ---

in v2.032. Probably working since 2.022.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 18 2009