Bug 2083 – Cannot convert char[] to string

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2008-05-08T17:20:00Z
Last change time
2015-06-09T01:14:35Z
Assigned to
bugzilla
Creator
jlquinn

Comments

Comment #0 by jlquinn — 2008-05-08T17:20:39Z
This is really ugly. The following program: void test(char[] s) { string t = s; } gives the following error: junk2.d(2): Error: cannot implicitly convert expression (s) of type char[] to invariant(char)[] I haven't found a way around this yet. It really should be handled as an implicit conversion, with a copy being made under the covers as needed.
Comment #1 by caron800 — 2008-05-09T00:15:35Z
On 08/05/2008, [email protected] <[email protected]> wrote: > http://d.puremagic.com/issues/show_bug.cgi?id=2083 > > Summary: Cannot convert char[] to string > Product: D > Version: 2.012 > Platform: PC > OS/Version: Linux > Status: NEW > Severity: normal > Priority: P2 > Component: DMD > AssignedTo: [email protected] > ReportedBy: [email protected] > > > This is really ugly. The following program: > > void test(char[] s) { > string t = s; > } > > gives the following error: > > junk2.d(2): Error: cannot implicitly convert expression (s) of type char[] to > invariant(char)[] And so it should. That /is/ an error, and a serious one. > I haven't found a way around this yet. string t = s.idup; > It really should be handled as an > implicit conversion, with a copy being made under the covers as needed. A copy is made when you add ".idup", but D doesn't like to make silent copies "under the covers as needed".
Comment #2 by kamm-removethis — 2008-05-09T01:03:00Z
*** This bug has been marked as a duplicate of 2082 ***