Bug 23601 – [std.format] acceptedSpecs do match baseOfSpec

Status
NEW
Severity
normal
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-01-05T00:29:40Z
Last change time
2024-12-01T16:40:57Z
Assigned to
No Owner
Creator
João Lourenço
Moved to GitHub: phobos#9853 →

Comments

Comment #0 by jlourenco5691 — 2023-01-05T00:29:40Z
```d import std; void main() { int i; "12.34".formattedRead!"%f"(i); } ``` This code sample compiles incorrectly to then fail at run time. The validation fails because it validates 'i' as a valid argument for the used spec. Any of [FfGgAaEe] counts as a valid base for any integral argument (int, bool, char, ...) and when checking acceptedSpecs at run time they do not match. It seems to me that baseOfSpec is the one in the wrong here, but the real issue is using the writing format to validate the reading format since 'int' can format into a 'float' but not the other way around. Moreover, 'a' is missing from acceptedSpecs, and all the upper case versions of spec are allowed by the 'write' version but not the 'read' alternative, which also leads to the run-time error `not supported with formatted read` instead of a compile-time assertion. Formatted read should validate the format specs with its own implementation if it differs this much from the 'write' version.
Comment #1 by jlourenco5691 — 2023-01-05T09:45:35Z
Another core feature that does not work is ignoring values with '*' with a compile-time format string. The reasoning is the same as above, the validation goes through the 'write' version, and because the meaning is different, the following should compile but doesn't ```d import std; void main() { int i; "123".formattedRead!"%d %*u"(i).writeln; } ```
Comment #2 by robert.schadek — 2024-12-01T16:40:57Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/9853 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB