D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6958 - [CTFE] closures are not yet supported in CTFE
Summary: [CTFE] closures are not yet supported in CTFE
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P4 enhancement
Assignee: No Owner
URL:
Keywords: CTFE, industry
Depends on:
Blocks:
 
Reported: 2011-11-16 05:33 UTC by Don
Modified: 2024-12-13 17:56 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Don 2011-11-16 05:33:59 UTC
Test case:
-----------------------
int delegate(int a) bar6958(int x)
{
    int y = x;
    int delegate (int a) xxx = (int a){ return a + y; };
    return xxx;
}
    
int foo6958()
{
    auto z = bar6958(4);
    assert(z(3) == 7);
    return 3;
}

static assert(foo6958());
Comment 1 Lance Bachmeier 2019-05-11 19:10:51 UTC
This is still valid. Tested on DMD 2.080.0:

closure.d(5): Error: closures are not yet supported in CTFE
closure.d(10):        called from here: bar6958(4)
closure.d(15):        called from here: foo6958()
closure.d(15):        while evaluating: static assert(foo6958())

I think it should be an enhancement rather than a bug though.
Comment 2 johanengelen 2021-11-17 22:34:39 UTC
Adding another testcase, because the error message is different from the original testcase:

```
    void func(int x, ref int delegate() dg) {
        int inner() {
            return x;
        }
        dg = &inner;
    }
    int check() {
        int delegate() dg;
        func(5, dg);
        return dg();
    }
    pragma(msg, check());
```

With DMD 2.094.2:

<source>(3): Error: variable `x` cannot be read at compile time
<source>(10):        called from here: `dg()`
<source>(12):        called from here: `check()`
<source>(12):        while evaluating `pragma(msg, check())`
Comment 3 dlangBugzillaToGithub 2024-12-13 17:56:56 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18381

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB