Bug 22051 – compiler allows compilation of malformed writefln statement, causing run-time crashes

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2021-06-20T07:10:52Z
Last change time
2021-06-20T10:05:54Z
Assigned to
No Owner
Creator
james.p.leblanc

Comments

Comment #0 by james.p.leblanc — 2021-06-20T07:10:52Z
// this compiles (but notice the naked percent sign), causing run-time crash import std.stdio; void main (){ bool myvar = true; writefln("Bool: %: ", myvar); }
Comment #1 by b2.temp — 2021-06-20T09:58:44Z
The specifier is only checked if you pass it has a template value parameter, like this: --- import std.stdio; void main (){ bool myvar = true; writefln!"Bool: % "(myvar); } --- otherwise a run-time error is the only way to get it checked. The string literal gives the impression that it is verifiable it could very well be something build from random sources.
Comment #2 by b2.temp — 2021-06-20T10:05:54Z
Maybe you expected https://dlang.org/spec/pragma.html#printf to work ? If so then that is also an invalid report because this works only on C variadic functions. writefln is a D variadic function.