Bug 19004 – Allow passing a string literal to an extern(C) variadic parameter

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2018-06-18T12:54:08Z
Last change time
2018-06-23T10:29:52Z
Keywords
pull
Assigned to
No Owner
Creator
Nick Treleaven

Comments

Comment #0 by nick — 2018-06-18T12:54:08Z
A string literal usually implicitly converts to a const(char)*. This is not considered when passing one to an extern(C) variadic parameter - due to the literal being interpreted as a slice, which is disallowed. The string should be implicitly cast to a pointer, as string literals are always \0-terminated. This is handy for C string compatibility, e.g. for formatting arguments: dmd/toobj.d: f.error("must be `extern(C)` for `pragma(%s)`", isCtor ? "crt_constructor".ptr : "crt_destructor".ptr); The `.ptr` property should not be necessary.