www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - dmd crash on pointer minus array

reply h3r3tic <foo bar.baz> writes:
This code shouldn't compile, it crashes the compiler:

void main()
{
	int[10] arr;
	int *p = &arr[5];
	cast(uint)(p - arr);
}


When the code is reduced to:

void main()
{
	int[10] arr;
	int *p = &arr[5];
	p - arr;
}

the compiler issues the correct error message "incompatible types for -".

DMD.118; WinXP
Mar 17 2005
parent Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

h3r3tic schrieb am Fri, 18 Mar 2005 00:42:37 +0100:
 This code shouldn't compile, it crashes the compiler:

 void main()
 {
 	int[10] arr;
 	int *p = &arr[5];
 	cast(uint)(p - arr);
 }
produces the expected error message and crashes (DMD 0.118; Linux)
 When the code is reduced to:

 void main()
 {
 	int[10] arr;
 	int *p = &arr[5];
 	p - arr;
 }

 the compiler issues the correct error message "incompatible types for -".

 DMD.118; WinXP
Added to DStress as http://dstress.kuehne.cn/nocompile/cast_23.d http://dstress.kuehne.cn/nocompile/cast_24.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCOmcH3w+/yD4P9tIRAjqlAJ4rQND+dxIimk9AJ55RmKP8WcnJkwCfdqyb VfahD0WwkX0sZXv4/MATZ28= =tNpI -----END PGP SIGNATURE-----
Mar 17 2005