Bug 33 – No short-circuit evaluation for compile-time expressions?
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-03-10T13:46:00Z
Last change time
2014-02-15T02:08:32Z
Assigned to
bugzilla
Creator
sean
Comments
Comment #0 by sean — 2006-03-10T13:46:11Z
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>
Comment #1 by clugdbug — 2006-03-13T07:25:15Z
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.