D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1461 - Local variable as template alias parameter breaks CTFE
Summary: Local variable as template alias parameter breaks CTFE
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2007-08-31 09:25 UTC by Reiner Pope
Modified: 2014-02-16 15:25 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Reiner Pope 2007-08-31 09:25:03 UTC
The following code fails to compile with error, "cannot evaluate generate() at compile time." This error is stopped by declaring x in global scope.

void main()
{
    int x;
    const string text = Gen!(x).generate();
}

template Gen(alias A)
{
    string generate()
    {
        return null;
    }
}
Comment 1 Don 2008-06-30 03:50:52 UTC
Changed version, since this applied to D1.x as well. Still not fixed in D1.031.
For phobos2, the code now needs to use 'enum' instead of const to trigger the behaviour:
---
void main()
{
    int x;
    enum string text = Gen!(x).generate();
}

template Gen(alias A)
{
    string generate()
    {
        return null;
    }
}
Comment 2 Walter Bright 2009-09-03 13:22:35 UTC
Fixed dmd 1.047 and 2.032