Bug 20623 – std.conv.to!string error when argument is an inout float

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-02-29T23:13:52Z
Last change time
2022-03-08T16:10:03Z
Keywords
pull
Assigned to
moonlightsentinel
Creator
daniele.m.bondi

Comments

Comment #0 by daniele.m.bondi — 2020-02-29T23:13:52Z
import std.conv : to; struct Foo { float f = 0f; void foo() inout { to!string(this.f); } } void main() { Foo().foo(); } The above code causes these errors /usr/include/dlang/dmd/std/math.d(282): Error: variable std.math.floatTraits!(inout(float)).RECIP_EPSILON only parameters or stack based variables can be inout /usr/include/dlang/dmd/std/math.d(6814): Error: template instance std.math.floatTraits!(inout(float)) error instantiating /usr/include/dlang/dmd/std/format.d(2654): instantiated from here: isInfinity!(inout(float)) /usr/include/dlang/dmd/std/format.d(1875): instantiated from here: formatValueImpl!(Appender!string, inout(float), char) /usr/include/dlang/dmd/std/conv.d(1072): instantiated from here: formatValue!(Appender!string, inout(float), char) /usr/include/dlang/dmd/std/conv.d(222): instantiated from here: toImpl!(string, inout(float)) main.d(8): instantiated from here: to!(inout(float)) /usr/include/dlang/dmd/std/format.d(2694): Error: template instance std.math.signbit!(inout(float)) error instantiating /usr/include/dlang/dmd/std/format.d(1875): instantiated from here: formatValueImpl!(Appender!string, inout(float), char) /usr/include/dlang/dmd/std/conv.d(1072): instantiated from here: formatValue!(Appender!string, inout(float), char) /usr/include/dlang/dmd/std/conv.d(222): instantiated from here: toImpl!(string, inout(float)) main.d(8): instantiated from here: to!(inout(float)) /usr/include/dlang/dmd/std/format.d(2732): Error: forward reference to inferred return type of function call function () @trusted { import core.stdc.stdio : snprintf; return snprintf(buf2.ptr, buf2.length, sprintfSpec.ptr, fs.width, fs.precision == fs.UNSPECIFIED ? -1 : fs.precision, tval); } () I tried adding Unqual! to the declaration of RECIP_EPSILON and the error seems to go away
Comment #1 by mrsmith33 — 2020-03-03T13:37:26Z
Got the same problem: void main() {} struct Struct { double member; string fun() inout { import std.conv : text; return member.text; } }
Comment #2 by moonlightsentinel — 2020-03-03T15:49:28Z
git bisect blames this commit: commit 2b2ed40f611231d7f5b92747b619bbe067fd827b (HEAD, refs/bisect/bad) Author: Robert Schadek <[email protected]> Date: Thu Oct 10 15:26:22 2019 +0100 Fix Issue 20288 std.format with separator and double causes RangeError
Comment #3 by dlang-bot — 2020-03-03T16:34:57Z
@MoonlightSentinel created dlang/phobos pull request #7413 "Fix Issue 20623 - std.conv.to!string error when argument is an inout float" fixing this issue: - Fix Issue 20623 - std.conv.to!string error when argument is an inout float https://github.com/dlang/phobos/pull/7413
Comment #4 by dlang-bot — 2020-03-10T23:55:44Z
dlang/phobos pull request #7413 "Add tests for issue 20623 - std.conv.to!string error when argument is an inout float" was merged into master: - d7e0c0ce70bea6ca41094e7fd7981c929c7aacbf by MoonlightSentinel: Add tests for Issue 20623 - std.conv.to!string error when argument is an inout float. This bug was fixed as side effect of #7407. https://github.com/dlang/phobos/pull/7413
Comment #5 by madric — 2022-03-08T16:10:03Z
This error is also reproducible using enums, e.g.: ``` d import std.conv : to; struct Foo { enum Type { HAM, BREAD } Type t; void foo() inout { to!string(this.t); } } void main() { Foo().foo(); } ``` > /dlang/dmd/linux/bin64/../../src/phobos/std/conv.d(1217): Error: variable `std.conv.value` only parameters or stack based variables can be `inout`