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.
*** 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