www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17487] New: CTFE should allow casting delegate function

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

          Issue ID: 17487
           Summary: CTFE should allow casting delegate function attributes
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: eyal weka.io

import std.traits;

struct S {
    int f() { return 1; }
    int delegate()  nogc fAsNoGc() {
        alias F = typeof(&f);
        enum oldAttrs = functionAttributes!F;
        return cast(SetFunctionAttributes!(F, functionLinkage!F, oldAttrs |
FunctionAttribute.nogc))&f;
    }
}

int moo() { return S().fAsNoGc()(); }

auto x = moo();                 // CTFE, fails
void main() {
    auto y = moo();             // runtime, succeeds
}

--
Jun 09