@johnno1962 I've read the latest draft of your proposal at apple/swift-evolution#917.
I don't like the proposed solution, which treats -DNUMBER=10
as true
within an #if NUMBER
condition. I think Swift previously had some implicit conversions to Bool
but they were removed. Although you could argue that compilation directives are different from normal Swift code.
Could this feature be more like:
- the special literals such as
#file
and#line
; - or the playground literals such as
#colorLiteral
?
For example, a compiler flag other than -D
could be used:
- either to allow
#tolerance
and other custom literals; - or
#userLiteral("tolerance")
where only the string argument is user-defined.
The implementation uses strtoll
and strtod
to validate numeric literals, which won't recognize binary 0b
or octal 0o
prefixes, or _
underscores used as separators. Should multiline and raw string literals be allowed? Should interpolated string literals be disallowed? Is it possible to inject arbitrary code via the compiler flag?
@jrose Could the package manager's compelling use cases be added to the Motivation section?
The current motivation (to embed information in the binary) might be solved in a different way. For example: