www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7521] New: Add const inference for templated method and delegate parameters

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

           Summary: Add const inference for templated method and delegate
                    parameters
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: timon.gehr gmx.ch



Not only pure/nothrow/ safe should be inferred, but const on parameters and
methods should be inferred too. This increases the expressiveness of alias
parameters and is required for making templates const correct. Inferring const
for delegate parameters reduces the annotation overhead and makes treatment of
template delegate literals uniform with normal delegate literals.

IOW, the following code should compile:

int glob;

class Foo(alias a){
    int x;
    void foo(){a(this);}
    static int bar(Foo x){return a(foo);}
}

void main(){
    alias Foo!((p){glob=p.x;}) T; // parameter p inferred const
    auto foo = new immutable(T);
    foo.foo();  // OK, T.foo inferred const
    T.bar(foo); // OK, parameter x of T.bar inferred const
    (T x){glob = x.x;}(foo); // OK, parameter x inferred const
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 16 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7521




The original example contained some mistakes, second try:

int glob;

class Foo(alias a){
    int x;
    void foo(){a(this);}
    static void bar(Foo x){a(x);}
}

void main(){
    alias Foo!((a){glob=a.x;}) T; // parameter a inferred const                 
    auto foo = new immutable(T);
    foo.foo();  // OK, foo inferred const                                       
    T.bar(foo); // OK, parameter x inferred const                               
    (T x){glob = x.x;}(foo); // ok, parameter x inferred const                  
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 16 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7521




This probably shouldn't be done for virtual functions of templated classes.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 25 2012