www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - concat bug?

reply Nick <Nick_member pathlink.com> writes:
Is this intended behaviour?

# import std.stdio;
#
# void main()
# {
#   char c = 'a';
#   char[] str;
#
#   str = str ~ c;
# 
#   writefln(str);
#   c = 'b';
#   writefln(str);
# }

Output:
a
b

In other words, 'str ~ c' when str is empty results in a 'slice' of the
character c. If it IS intended, I don't think it should be, because it probably
isn't what the programmer intended (in my case 'c' was the loop variable in a
foreach loop, and this bug was NOT easy to find, believe me...) It's also
inconsistent with the behaviour of str ~= c in the same situation.

Nick
Jun 21 2005
next sibling parent Derek Parnell <derek psych.ward> writes:
On Tue, 21 Jun 2005 17:16:33 +0000 (UTC), Nick wrote:

 Is this intended behaviour?
 
 # import std.stdio;
 #
 # void main()
 # {
 #   char c = 'a';
 #   char[] str;
 #
 #   str = str ~ c;
 # 
 #   writefln(str);
 #   c = 'b';
 #   writefln(str);
 # }
 
 Output:
 a
 b
 
 In other words, 'str ~ c' when str is empty results in a 'slice' of the
 character c. If it IS intended, I don't think it should be, because it probably
 isn't what the programmer intended (in my case 'c' was the loop variable in a
 foreach loop, and this bug was NOT easy to find, believe me...) It's also
 inconsistent with the behaviour of str ~= c in the same situation.
 
 Nick

I'm sure this is a bug. Replace "str = str ~ c;" with "str ~= c;" and it works as expected. -- Derek Melbourne, Australia 22/06/2005 10:05:04 AM
Jun 21 2005
prev sibling parent Thomas Kuehne <thomas-dloop kuehne.this-is-spam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Nick schrieb am Tue, 21 Jun 2005 17:16:33 +0000 (UTC):
 Is this intended behaviour?

 # import std.stdio;
 #
 # void main()
 # {
 #   char c = 'a';
 #   char[] str;
 #
 #   str = str ~ c;
 # 
 #   writefln(str);
 #   c = 'b';
 #   writefln(str);
 # }

 Output:
 a
 b

 In other words, 'str ~ c' when str is empty results in a 'slice' of the
 character c. If it IS intended, I don't think it should be, because it probably
 isn't what the programmer intended (in my case 'c' was the loop variable in a
 foreach loop, and this bug was NOT easy to find, believe me...) It's also
 inconsistent with the behaviour of str ~= c in the same situation.

 Nick

Added to DStress as http://dstress.kuehne.cn/run/o/opCat_15_A.d http://dstress.kuehne.cn/run/o/opCat_15_B.d http://dstress.kuehne.cn/run/o/opCat_15_C.d http://dstress.kuehne.cn/run/o/opCat_15_D.d http://dstress.kuehne.cn/run/o/opCat_15_E.d http://dstress.kuehne.cn/run/o/opCat_15_F.d http://dstress.kuehne.cn/run/o/opCat_15_G.d http://dstress.kuehne.cn/run/o/opCat_15_H.d http://dstress.kuehne.cn/run/o/opCat_15_I.d http://dstress.kuehne.cn/run/o/opCat_15_J.d http://dstress.kuehne.cn/run/o/opCat_15_K.d http://dstress.kuehne.cn/run/o/opCat_15_L.d http://dstress.kuehne.cn/run/o/opCat_15_M.d http://dstress.kuehne.cn/run/o/opCat_15_N.d http://dstress.kuehne.cn/run/o/opCat_15_O.d http://dstress.kuehne.cn/run/o/opCat_15_P.d http://dstress.kuehne.cn/run/o/opCat_15_Q.d http://dstress.kuehne.cn/run/o/opCat_15_R.d http://dstress.kuehne.cn/run/o/opCat_15_S.d http://dstress.kuehne.cn/run/o/opCat_15_T.d http://dstress.kuehne.cn/run/o/opCat_15_U.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCuU2n3w+/yD4P9tIRAhJmAJ9Uc3xG8fDEaiJd35BaXZvLzWzm4QCggEOV tu8XP5PVZvWHyEuMAGmqsVc= =ymTe -----END PGP SIGNATURE-----
Jun 22 2005