Bug 7438 – Functions from std.conv should be pure

Status
RESOLVED
Resolution
WONTFIX
Severity
trivial
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-02-04T12:55:56Z
Last change time
2022-08-31T09:18:02Z
Keywords
bootcamp
Assigned to
No Owner
Creator
SyntaxColoring

Comments

Comment #0 by SyntaxColoring — 2012-02-04T12:55:56Z
The conversion functions in std.conv always yield the same results for the same input, so they should be marked as pure.
Comment #1 by issues.dlang — 2012-02-04T13:54:13Z
There's no need. They're templates, so they'll be inferred as pure if they can actually be pure. If they aren't pure, it's because their implementation prevents it. And it might actually be too restrictive to _require_ that they all be pure (especially when dealing with stuff like a user-defined opCast).
Comment #2 by lovelydear — 2012-04-19T08:46:04Z
Should we close ?
Comment #3 by bearophile_hugs — 2012-04-19T15:02:53Z
(In reply to comment #2) > Should we close ? I agree with Jonathan M Davis that maybe asking for them to be always pure is a bit too much (this is debatable. Maybe it's a good thing still). But I think we can't close this bug report before this little program, that shows a very basic usage of to!(), compiles with no errors or warnings: import std.conv: to; void main() pure { string r = to!string(to!real("2.5")); }
Comment #4 by issues.dlang — 2012-04-19T15:11:15Z
I'd be very tempted to argue that that should be a separate bug. There's a big difference between std.conv.to should always be pure for everything and std.conv.to should be pure when converting to strings.
Comment #5 by rburners — 2013-08-12T13:16:56Z
Is somebody working on this? I would even argue that it should be @safe.
Comment #6 by issues.dlang — 2013-08-13T19:47:19Z
Whether std.conv.to can be @safe or pure depends entirely on what you're converting. For all of the built-in types, it should be @safe and pure, but once user-defined types enter the mix, it depends on how the user-defined types are defined. A lot of the underlying stuff which relates to arrays (like appender) hasn't been able to be pure in the past (I don't know quite where that sits now though), making it so that stuff like std.conv.to!string(10) hasn't been able to be pure even though it should be. So, odds are that the lack of purity or @safety in std.conv.to isn't std.conv.to's fault at all.
Comment #7 by rburners — 2013-08-14T00:35:16Z
yes it turtles down. Just to see how hard it breaks I mark some pure. I stopped somewhere in format. So looks like not so much fun.
Comment #8 by blah38621 — 2014-09-19T22:46:14Z
Float to string and back is not pure.
Comment #9 by bugzilla — 2019-12-07T14:03:18Z
*** Issue 17628 has been marked as a duplicate of this issue. ***
Comment #10 by razvan.nitu1305 — 2022-08-31T09:18:02Z
(In reply to bearophile_hugs from comment #3) > (In reply to comment #2) > > Should we close ? > > I agree with Jonathan M Davis that maybe asking for them to be always pure > is a bit too much (this is debatable. Maybe it's a good thing still). > > But I think we can't close this bug report before this little program, that > shows a very basic usage of to!(), compiles with no errors or warnings: > > > import std.conv: to; > void main() pure { > string r = to!string(to!real("2.5")); > } The above example compiles now (even if we mark main as @safe) so as per Jonathan's comments I will close this as WONTFIX.