Bug 17381 – Checked format string is permissive after floating point argument

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-05-07T11:49:14Z
Last change time
2021-03-31T10:28:28Z
Keywords
pull
Assigned to
No Owner
Creator
Ali Cehreli
See also
https://issues.dlang.org/show_bug.cgi?id=3248

Comments

Comment #0 by acehreli — 2017-05-07T11:49:14Z
A float argument eliminates subsequent orphan argument checks. import std.format; void main() { static assert(!__traits(compiles, format!"%s"(1.5, 2))); } static assert fails because the expression should not compile because there is an orphan argument. (In real code, it would compile but throw FormatException at runtime.) Replacing %s with %f does not make a difference; it still compiles. You can have more arguments before the floating point argument; it always breaks the subsequent orphan argument checks. Ali
Comment #1 by bugzilla — 2021-03-27T10:46:10Z
Meanwhile I found the reason for this: When checking at compile time, there is a cannot-format-floats-at-compiletime-exception thrown. For testing purpose this is ignored (as it is supposed to work in runtime) and hence the orphan-arguments-exception overlooked. Meanwhile format is able to format floats and doubles at compiletime (but yet not reals). Therefore the code above works meanwhile, but not with 1.5L yet.
Comment #2 by bugzilla — 2021-03-27T14:24:54Z
dlang-bot seems to have forgotton to mention this: https://github.com/dlang/phobos/pull/7916
Comment #3 by bugzilla — 2021-03-27T19:48:48Z
*** Issue 21529 has been marked as a duplicate of this issue. ***
Comment #4 by dlang-bot — 2021-03-31T09:24:44Z
@berni44 updated dlang/phobos pull request #7916 "Fix Issue 17381 - Checked format string is permissive after floating point argument" fixing this issue: - Fix Issue 17381 - Checked format string is permissive after floating point argument https://github.com/dlang/phobos/pull/7916
Comment #5 by dlang-bot — 2021-03-31T10:28:28Z
dlang/phobos pull request #7916 "Fix Issue 17381 - Checked format string is permissive after floating point argument" was merged into master: - 88547b8cbbbc70aa6c393286cab6314df3e0c77c by berni44: Fix Issue 17381 - Checked format string is permissive after floating point argument https://github.com/dlang/phobos/pull/7916