33 – No short-circuit evaluation for compile-time expressions?

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 33 - No short-circuit evaluation for compile-time expressions?
Summary: No short-circuit evaluation for compile-time expressions?
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:
Depends on:
Blocks:
Reported: 2006年03月10日 13:46 UTC by Sean Kelly
Modified: 2014年02月15日 02:08 UTC (History)
0 users

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 Sean Kelly 2006年03月10日 13:46:11 UTC
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 Don 2006年03月13日 07:25:15 UTC
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.
Comment 2 Thomas Kühne 2006年03月21日 04:50:38 UTC
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
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
-----BEGIN PGP SIGNATURE-----
iD8DBQFEH+AF3w+/yD4P9tIRAic1AKCSrOmy1GOb0Lsry6wfLQ2H7b/IFQCgvDT9
BPkzHqg8uz8ZkR+y3x+WD3g=
=dpwQ
-----END PGP SIGNATURE-----
Comment 3 Walter Bright 2006年04月28日 02:55:30 UTC
Fixed 0.155


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