D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5453 - ICE(statement.c): invalid switch statement forward referenced by CTFE
Summary: ICE(statement.c): invalid switch statement forward referenced by CTFE
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: ice-on-valid-code
: 6326 (view as issue list)
Depends on:
Blocks:
 
Reported: 2011-01-14 00:17 UTC by Don
Modified: 2015-06-09 05:11 UTC (History)
2 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-01-14 00:17:27 UTC
Reported by %u.
------------
struct S
{    
  static int func() {
    S s;
    int e;
    switch( e )
    {  default: return 0;
    }
  }    
  static int[1] ARR = [func() ];
}
----
Assertion failure: '!cases' on line 2741 in file 'statement.c'

abnormal program termination


It's happening because the CTFE for ARR speculatively runs func().
There's a 'no size yet for forward referenced struct' error because S isn't complete yet. But this happens with errors gagged.
The SwitchStatement completes its semantic pass correctly. 
But, because "S s;" failed, semantic gets run again for func(), without errors gagged this time. SwitchStatement::semantic() detects it's been run twice, and asserts.
Comment 1 Don 2011-07-26 21:11:27 UTC
*** Issue 6326 has been marked as a duplicate of this issue. ***