Thread overview
[Bug 33] New: No short-circuit evaluation for compile-time expressions?
Mar 10, 2006
d-bugmail
Mar 13, 2006
d-bugmail
Mar 21, 2006
Thomas Kuehne
Apr 28, 2006
d-bugmail
March 10, 2006
http://d.puremagic.com/bugzilla/show_bug.cgi?id=33

           Summary: No short-circuit evaluation for compile-time
                    expressions?
           Product: D
           Version: 0.149
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: sean@f4.ca


I think this is arguably not a bug in the same way that compile-time "?:" expressions evaluate both their arguments regardless of which is selected, but it's definately non-intuitive:


C:\code\d\bugs>type 149_2.d
import std.c.stdio;

void main()
{
    static if( int.mangleof.length > 1 && int.mangleof[1] == 'x' )
        printf( "'x' as second char\n" );
}
C:\code\d\bugs>dmd 149_2.d
149_2.d(5): array index [1] is outside array bounds [0 .. 1]

C:\code\d\bugs>


-- 

March 13, 2006
http://d.puremagic.com/bugzilla/show_bug.cgi?id=33





------- Comment #1 from clugdbug@yahoo.com.au  2006-03-13 07:25 -------
Definitely a bug -- but maybe not in &&. This example compiles:

void main()
{
    const char [] s = int.mangleof;
    static if( s.length > 1 && s[1] == 'x' )
        printf( "'x' as second char\n" );
}

And this one gives a quite bizarre error message:

void main()
{
    const char [] s = (int*).mangleof;
    static if( s.length > 1 && s[2] == 'x' )
        printf( "'x' as second char\n" );
}

something about TOK58 doesn't evaluate to a boolean.


-- 

March 21, 2006
d-bugmail@puremagic.com schrieb am 2006-03-13:
>
> And this one gives a quite bizarre error message:
>
> void main()
> {
>     const char [] s = (int*).mangleof;
>     static if( s.length > 1 && s[2] == 'x' )
>         printf( "'x' as second char\n" );
> }
>
> something about TOK58 doesn't evaluate to a boolean.

The code above is buggy. s="ab" will result in an  ArrayBoundsError.

Added to DStress http://dstress.kuehne.cn/run/m/mangleof_15_A.d http://dstress.kuehne.cn/run/m/mangleof_15_B.d http://dstress.kuehne.cn/run/m/mangleof_15_C.d http://dstress.kuehne.cn/run/m/mangleof_15_D.d

Thomas


April 28, 2006
http://d.puremagic.com/bugzilla/show_bug.cgi?id=33


bugzilla@digitalmars.com changed:

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




------- Comment #3 from bugzilla@digitalmars.com  2006-04-28 02:55 -------
Fixed 0.155


--