www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2140] New: static if as final statement with no code causes containing code to be skipped

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2140

           Summary: static if as final statement with no code causes
                    containing code to be skipped
           Product: D
           Version: 1.027
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: jarrett.billingsley gmail.com


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.


-- 
Jun 03 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2140





------- Comment #1 from jarrett.billingsley gmail.com  2008-06-03 13:54 -------
(In reply to comment #0)

Happens in both 1.027 and 1.030


-- 
Jun 03 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2140


torhu yahoo.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |torhu yahoo.com




------- Comment #2 from torhu yahoo.com  2008-06-04 05:08 -------
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'.


-- 
Jun 04 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2140


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #3 from bugzilla digitalmars.com  2008-06-22 18:58 -------
Fixed dmd 1.031 and 2.015


-- 
Jun 22 2008