Bug 24880 – to!string with inout enum argument fails to compile

Status
NEW
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-11-25T15:46:38Z
Last change time
2024-12-01T16:43:16Z
Assigned to
No Owner
Creator
Paul Backus
Moved to GitHub: phobos#10568 →

Comments

Comment #0 by snarwin+bugzilla — 2024-11-25T15:46:38Z
As of DMD 2.109.1, the following program fails to compile: --- enum E { One } inout(E) fun(inout(E) e) { import std.conv; auto s = e.to!string; return e; } --- The error message is: --- /usr/include/dmd/phobos/std/conv.d(1227): Error: variable `std.conv.value` - only parameters or stack-based variables can be `inout` /usr/include/dmd/phobos/std/conv.d(210): Error: template instance `std.conv.toImpl!(string, inout(E))` error instantiating bug.d(6): instantiated from here: `to!(inout(E))` --- This error occurs because toImpl attempts to pass an inout(E) value as an argument to the template enumRep. The instantiation fails because inout values cannot be used as template arguments: --- enum E { One } enum example(T, T value) = true; alias test = example!(inout(E), E.One); // Error: only parameters or stack-based variables can be `inout ---
Comment #1 by dfj1esp02 — 2024-11-26T18:45:25Z
private template enumRep(T, S, S value) if (is (T == immutable) && isExactSomeString!T && is(S == enum)) { static T enumRep = toStr!T(value); } If I mark the argument as immutable, then it compiles: private template enumRep(T, S, immutable S value) Presumably for enums it should be fine. Invoking with enumRep!(immutable(T), immutable(S), member) works too.
Comment #2 by robert.schadek — 2024-12-01T16:43:16Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10568 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB