www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - wchar[]/dchar[] dup

reply Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

# wchar[] c = "a".dup;

dmd: cannot implicitly convert expression (_adDup("abc",1)) of type char[] to
wchar[]

Fails to compile but should compile.

Added to DStress as
http://dstress.kuehne.cn/run/dup_06.d
http://dstress.kuehne.cn/run/dup_07.d

Thomas


-----BEGIN PGP SIGNATURE-----

iD8DBQFCajJR3w+/yD4P9tIRAhsIAJ0e5kqU4DG/k0TyOMXRGigKnKhvIACbBAWo
8iYG9lSbvgT8Bwc7t8rsMvA=
=P8ET
-----END PGP SIGNATURE-----
Apr 23 2005
parent reply "Walter" <newshound digitalmars.com> writes:
"Thomas Kuehne" <thomas-dloop kuehne.thisisspam.cn> wrote in message
news:ibopj2-3qi.ln1 lnews.kuehne.cn...
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1

 # wchar[] c = "a".dup;

 dmd: cannot implicitly convert expression (_adDup("abc",1)) of type char[]

 Fails to compile but should compile.

I disagree. If the string literal is forced to commit to a type, which it must with the .dup, it goes with char[].
Apr 24 2005
parent =?UTF-8?B?VGhvbWFzIEvDvGhuZQ==?= writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Walter wrote:
| "Thomas Kuehne" <thomas-dloop kuehne.thisisspam.cn> wrote in message
| news:ibopj2-3qi.ln1 lnews.kuehne.cn...
|>
|># wchar[] c = "a".dup;
|>
|>dmd: cannot implicitly convert expression (_adDup("abc",1)) of type
|>char[]
|
| to wchar[]
|
|>Fails to compile but should compile.
|
| I disagree. If the string literal is forced to commit to a type, which
| it must with the .dup, it goes with char[].

Treating this code as illegal was indeed my first reaction and seems
natural.

The reason for posting this was basically the same as Brad Beveridge's
in "Segfault from changing a string".
The different syntax for assigning a value to an editable wchar/dchar[]
on Linux and Windows is a nice bug trap for Windows-based coders.

Windows:
# char[] c="123;
# c[0]='4';
#
# wchar[] w="abc";
# w[0]='D';

Linux:
# char[] c="123".dup;
# c[0]='4';
#
# wchar[] w="abc";
# w=w.dup;
# w[0]='C';

Please unify the behaviour.

I've removed both tests for now.

Thomas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)

iD8DBQFCa84f3w+/yD4P9tIRAj0yAJ9Gp6/EnmQzUREyHlKMxc0U5OBwpACgtiHr
vfq0PTxI7rkubTVW2BrAveY=
=Wgg+
-----END PGP SIGNATURE-----
Apr 24 2005