Bug 19669 – There is no way for code to detect whether -dip1000 is enabled or not

Status
RESOLVED
Resolution
INVALID
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-02-11T18:16:39Z
Last change time
2020-03-04T05:04:48Z
Assigned to
No Owner
Creator
Meta

Comments

Comment #0 by monkeyworks12 — 2019-02-11T18:16:39Z
Currently, there is no way for code to tell whether the -dip1000 switch has been passed to the compiler. This makes it harder to write code that needs to do something different depending on whether dip1000 is in effect or not, and in my opinion, is REQUIRED for any non-trivial code base that wants/has to support legacy compiler versions. There is a hacky workaround: static assert(!__traits(compiles, { char[] f() { char[2] x; return x[].splitterASCII!(_ => _ == ' ').front; } })); But it would be far preferable to be able to use `version(dip1000)` or `static if (dip1000)`.
Comment #1 by greeenify — 2019-02-11T19:20:37Z
For reference and completeness, here's a better example of what you can do already to detect dip1000: ```d void main() { enum isDIP1000 = __traits(compiles, () @safe { int x; int* p; p = &x; }); pragma(msg, isDIP1000); } ``` normal: https://run.dlang.io/is/RID7vh -dip1000: https://run.dlang.io/is/1yJfVQ
Comment #2 by petar.p.kirov — 2019-02-14T16:27:16Z
IMO, https://dlang.org/spec/traits.html#getTargetInfo should be able to give you all specified compiler flags, not just -dip1000.
Comment #3 by bugzilla — 2020-03-04T05:04:48Z
(In reply to ZombineDev from comment #2) > IMO, https://dlang.org/spec/traits.html#getTargetInfo should be able to give > you all specified compiler flags, not just -dip1000. That would be an enhancement request. Seb has shown how to reliably detect if -dip1000 is thrown, so this issue is resolved. (In general, doing things in the existing language is better than adding more features.)