D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7630 - declaration in switch scope not initialized + CTFE error
Summary: declaration in switch scope not initialized + CTFE error
Status: RESOLVED DUPLICATE of issue 3820
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-02 09:47 UTC by Martin Nowak
Modified: 2012-03-12 07:24 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Martin Nowak 2012-03-02 09:47:15 UTC
int foo(int a)
{
    switch (a)
    {
        int res;
    case 1:
        res = 1;
        return res;
    case 2:
        return res;

    default:
        return 0;
    }
}

void main()
{
    enum v1 = foo(1);    // CTFE error, v->addrOnStack not set
    enum v2 = foo(2);    // CTFE error, used before initialization
    assert(foo(2) == 0); // runtime error, res is uninitialized
}

--------
Comment 1 Martin Nowak 2012-03-12 07:24:28 UTC

*** This issue has been marked as a duplicate of issue 3820 ***