[Issue 12448] New: "in" argument for std.string.toStringz
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Mar 23 20:16:08 PDT 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12448
Summary: "in" argument for std.string.toStringz
Product: D
Version: D2
Platform: x86
OS/Version: Windows
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2014-03-23 20:15:27 PDT ---
The signature of the second overload of toStringz is:
immutable(char)* toStringz(string s) @trusted pure nothrow
If you replace it with:
immutable(char)* toStringz(in string s) @trusted pure nothrow
Then the compiler gets able to catch some not used result bugs:
import std.exception: assumeUnique;
import core.stdc.string: memcmp, strlen;
import std.array: empty;
immutable(char)* toStringz(const(char)[] s) @trusted pure nothrow {
auto copy = new char[s.length + 1];
copy[0 .. s.length] = s[];
copy[$ - 1] = '\0';
return assumeUnique(copy).ptr;
}
immutable(char)* toStringz(in string s) @trusted pure nothrow {
if (s.empty)
return "".ptr;
immutable p = s.ptr + s.length;
if ((cast(size_t) p & 3) && *p == 0)
return s.ptr;
return toStringz(cast(const char[]) s);
}
void main() {
string foo;
foo.toStringz; // Warning
}
test.d(32,8): Warning: Call to strictly pure function test.toStringz discards
return value of type immutable(char)*, prepend a cast(void) if intentional
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list