Bug 509 – [wd]char[1] does not convert to [wd]char

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P4
Component
dlang.org
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-11-15T05:14:00Z
Last change time
2014-02-15T13:29:09Z
Keywords
spec
Assigned to
bugzilla
Creator
matti.niemenmaa+dbugzilla
Blocks
511

Comments

Comment #0 by matti.niemenmaa+dbugzilla — 2006-11-15T05:14:04Z
The Arrays spec, under the "Strings" section, has the following example code: wchar w; w = \r; // w is assigned the carriage return wchar character This code does not compile: cannot implicitly convert expression ("\x0d") of type char[1] to wchar. Trying to explicitly cast it to wchar[1], wchar[], or wchar also fails with similar error messages. Yet, the spec says right above this code that "[s]trings a single character in length can also be exactly converted to a char, wchar or dchar constant". Which is correct? To solve, change compiler behaviour to make the code compile and then change the 'w = "b"[0]' part of the code to 'w = "b"', or remove the sentence quoted and change the 'w = \r' line to 'w = \r[0]'.
Comment #1 by smjg — 2006-11-16T19:25:44Z
Why w = \r[0] rather than w = '\r'; ?
Comment #2 by matti.niemenmaa+dbugzilla — 2006-11-17T06:45:41Z
(In reply to comment #1) > Why > > w = \r[0] > > rather than > > w = '\r'; > > ? > Because there's already an example of assigning that way ("w = 'b'"). This example, in my humble opinion, is useful even if the [0] is added since it shows how quotes around the \r aren't necessary.
Comment #3 by matti.niemenmaa+dbugzilla — 2006-12-03T03:49:49Z
Spec corrected for DMD 0.176.