Thread overview
[DMD 0.101] Version statement without else clause within if crashes compiler
Sep 19, 2004
Burton Radons
Sep 19, 2004
Lars Ivar Igesund
Re: [DMD 0.101] Version statement without else clause within if crashes
Sep 28, 2004
Stewart Gordon
Sep 19, 2004
Walter
Sep 27, 2004
Stewart Gordon
Sep 30, 2004
Walter
September 19, 2004
This code causes the compiler to crash:

    void foo ()
    {
        if (x)
            version (none)
                foo;
    }

The specification doesn't say what a collapsed version/debug statement turns into, so I don't know how it's supposed to behave.
September 19, 2004
Burton Radons wrote:

> This code causes the compiler to crash:
> 
>     void foo ()
>     {
>         if (x)
>             version (none)
>                 foo;
>     }
> 
> The specification doesn't say what a collapsed version/debug statement turns into, so I don't know how it's supposed to behave.

I think this leads to an incorrect program, as version (none) becomes nothing:

void foo ()
{
  if (x)
}

which is wrong because there is no statement following if (x). The compiler shouldn't crash, though.

Lars Ivar Igesund
September 19, 2004
It's fixed now. It turns into:

    if (x) ;


September 27, 2004
In article <cil2q3$1l6i$1@digitaldaemon.com>, Walter says...
>
>It's fixed now. It turns into:
>
>    if (x) ;

You mean you've changed it so that that's valid D syntax?

Stewart.


September 28, 2004
In article <cikkvs$1f9n$1@digitaldaemon.com>, Lars Ivar Igesund says...

> Burton Radons wrote:
> 
>> This code causes the compiler to crash:
>> 
>>     void foo ()
>>     {
>>         if (x)
>>             version (none)
>>                 foo;
>>     }
<snip>
> void foo ()
> {
> if (x)
> }
> 
> which is wrong because there is no statement following if (x).  The compiler shouldn't crash, though.

The D versioning system isn't a text preprocessor.  As such, it is pointless to try and think of version blocks as reducing to textual nothingness.

Rather, it reduces to semantic nothingness, an effective 'nop' statement.

Another way to think of it is by imagining that there are braces:

void foo() {
if (x) {
version (none) {
foo;
}
}
}

The statement forms

if ( Expression ) Statement

if ( Expression ) { Statement }

are identical in effect,  By converting to the latter, it is easy to see the result of version reduction.

Stewart.


September 30, 2004
"Stewart Gordon" <Stewart_member@pathlink.com> wrote in message news:cj9ltc$16k1$1@digitaldaemon.com...
> In article <cil2q3$1l6i$1@digitaldaemon.com>, Walter says...
> >
> >It's fixed now. It turns into:
> >
> >    if (x) ;
>
> You mean you've changed it so that that's valid D syntax?

No. I meant:

    if (x) { }