Bug 13055 – @nogc std.string.sformat

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-07-06T13:13:39Z
Last change time
2024-12-01T16:21:46Z
Assigned to
No Owner
Creator
bearophile_hugs
See also
https://issues.dlang.org/show_bug.cgi?id=3248
Moved to GitHub: phobos#10069 →

Comments

Comment #0 by bearophile_hugs — 2014-07-06T13:13:39Z
sformat uses the given buffer, so this should compile: void main() @nogc { import std.string: sformat; char[50] arr; sformat(arr, "%d", 100); } If the given buffer is not large enough, sformat throws an exception. I think throwing this exception should not require a GC memory allocation at run-time.
Comment #1 by bearophile_hugs — 2014-07-11T09:32:09Z
One of my intended usages for this function is to generate messages for exceptions in @nogc code. Chris Cain comments: > It's just stack-allocated this way isn't possible since the > exception can be thrown into a scope above your stack allocated > chars.
Comment #2 by timothee.cour2 — 2016-01-10T08:08:29Z
ping. just ran into this again http://forum.dlang.org/thread/[email protected] formatted assert error messages inside nogc functions
Comment #3 by TeddyBear12311 — 2016-07-14T00:18:09Z
Same problem ;/
Comment #4 by lodovico — 2016-07-14T13:34:11Z
The current sformat signature is: char[] sformat(Char, Args...)(char[] buf, in Char[] fmt, Args args) { // something that uses encode(...) } It should become: char[] sformat(Char, Args...)(char[] buf, in Char[] fmt, Args args) { return sformat!(UseReplacementDchar.no)(buf, fmt, args); } char[] sformat(UseReplacementDchar urd, Char, Args...)(char[] buf, in Char[] fmt, Args args) { // something that uses encode!urd(...) } So that current behaviour does not change and one can opt-in for the @nogc version.
Comment #5 by lodovico — 2016-07-14T13:46:42Z
Also, the current use of enforce inside sformat (which a comment states shall be removed) should be converted to an assert or something else that does not throw.
Comment #6 by robert.schadek — 2024-12-01T16:21:46Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10069 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB