2140 – static if as final statement with no code causes containing code to be skipped

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2140 - static if as final statement with no code causes containing code to be skipped
Summary: static if as final statement with no code causes containing code to be skipped
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: Walter Bright
URL:
Keywords: wrong-code
Depends on:
Blocks:
Reported: 2008年06月03日 13:53 UTC by Jarrett Billingsley
Modified: 2014年02月24日 15:30 UTC (History)
1 user (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Jarrett Billingsley 2008年06月03日 13:53:12 UTC
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 Jarrett Billingsley 2008年06月03日 13:54:37 UTC
(In reply to comment #0)
Happens in both 1.027 and 1.030
Comment 2 torhu 2008年06月04日 05:08:56 UTC
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'.
Comment 3 Walter Bright 2008年06月22日 18:58:43 UTC
Fixed dmd 1.031 and 2.015


AltStyle によって変換されたページ (->オリジナル) /