digitalmars.D.bugs - [Issue 21456] New: std.format does not accept enum member with
- d-bugmail puremagic.com (43/43) Dec 04 2020 https://issues.dlang.org/show_bug.cgi?id=21456
https://issues.dlang.org/show_bug.cgi?id=21456 Issue ID: 21456 Summary: std.format does not accept enum member with string base type as template parameter Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Severity: normal Priority: P1 Component: phobos Assignee: nobody puremagic.com Reporter: rmaicle gmail.com D 2.094.2 Linux 5.9.11-3-MANJARO x86_64 ----------------------------- The std.format overload accepts a compile-time string as format string. This code compiles: enum FMTS = "%s is %s"; assert (format!FMTS("Pi", 3.14) == "Pi is 3.14"); This code also compiles: enum { FMTS = "%s is %s" } assert (format!FMTS("Pi", 3.14) == "Pi is 3.14"); This code does not compile: enum FMTS : string { ONE = "%s is %s" } assert (format!FMTS("Pi", 3.14) == "Pi is 3.14"); Formatted error message: Error: template std.format.format cannot deduce function from argument types !("%s is %s")(string, double), candidates are: ../src/phobos/std/format.d(6514,13): format(alias fmt, Args...)(Args args) with fmt = ONE, Args = (string, double) must satisfy the following constraint: isSomeString!(typeof(fmt)) The std.format overload accepting compile-time string as format string should accept named enums with a string base type since the enum member value can be determined during compile-time. --
Dec 04 2020