Bug 2140 – static if as final statement with no code causes containing code to be skipped
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2008-06-03T13:53:00Z
Last change time
2014-02-24T15:30:38Z
Keywords
wrong-code
Assigned to
bugzilla
Creator
jarrett.billingsley
Comments
Comment #0 by jarrett.billingsley — 2008-06-03T13:53:12Z
Hard to describe.
---------------------
void foo()
{
Stdout.formatln("I'm transient.");
static if(true)
{
// Comment me.
Stdout.formatln("true.");
}
else
{
}
}
void main(char[][] args)
{
foo();
}
---------------------
This code prints
I'm transient.
true.
As expected.
Comment the "comment me" line, however, and the "I'm transient" is never printed.
Alternatively, change the "static if(true)" to "static if(false)" and the same thing happens since the 'else' is empty.
Ways to make it go away:
- Have at least one statement in the static if clause that is selected. Even a no-op statement such as "int x = void;".
- Have more than one statement before the static if.
- Have at least one statement after the static if.
I'm really kind of flabbergasted.
Comment #1 by jarrett.billingsley — 2008-06-03T13:54:37Z
(In reply to comment #0)
Happens in both 1.027 and 1.030
Comment #2 by torhu — 2008-06-04T05:08:56Z
Adding an extra statement like 'int x;' at the top of foo() also fixes it.
This bug is strikingly similiar to issue 1559. In fact, it behaves exactly the same, except it's 'static if' instead of 'version'.