Bug 14553 – The return types of std.array.array for narrow strings conflicts with its documentation

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-05-07T11:24:33Z
Last change time
2022-07-25T15:36:47Z
Keywords
bootcamp
Assigned to
No Owner
Creator
Tomoya Tanjo

Comments

Comment #0 by ttanjo — 2015-05-07T11:24:33Z
The document of std.array.array for narrow string says "This (snip) always returns a dchar[], const(dchar)[], or immutable(dchar)[] depends on the constness of the input." However, array for them always returns dchar[] instead of qualified array. The following example reproduces the problem. I checked it by using dmd trunk in Linux x64. --- import std.stdio; import std.array; import std.traits; import std.typetuple; void main() { foreach(T; TypeTuple!(char, wchar)) { writeln(ReturnType!(array!(T[])).stringof); writeln(ReturnType!(array!(const(T)[])).stringof); writeln(ReturnType!(array!(immutable(T)[])).stringof); } } --- Expected output: dchar[] const(dchar)[] immutable(dchar)[] dchar[] const(dchar)[] immutable(dchar)[] Actual output: dchar[] dchar[] dchar[] dchar[] dchar[] dchar[]
Comment #1 by hsteoh — 2015-06-30T17:52:23Z
The question is, should we change the code to copy the qualifiers to the returned dchar[], or should we fix the docs to match the code? I'm not sure why it's important to keep the qualifiers if we're creating a new array anyway. Why not keep the code as-is and ensure that it's pure, so that the returned array can be implicitly cast to whatever qualifiers the user wants?
Comment #2 by daraban_timotei — 2022-07-23T11:10:45Z
Documentation has changed and no longer conflicts with return types.