Thread overview | ||||||
---|---|---|---|---|---|---|
|
March 22, 2018 Checking if a flag was passed to the compiler | ||||
---|---|---|---|---|
| ||||
Is there a way to check in code whether a specific flag, -dip1000 in my case, was passed to the compiler? |
March 22, 2018 Re: Checking if a flag was passed to the compiler | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Thursday, 22 March 2018 at 10:08:31 UTC, Nordlöw wrote:
> Is there a way to check in code whether a specific flag, -dip1000 in my case, was passed to the compiler?
Most command line arguments that are detectable set a version, e.g. D_Coverage, unittest, assert,D_BetterC. I don't see dip1000 in LDC's list of version statements.
You could do a !__traits(compiles, { something forbidden by dip1000} );
|
March 22, 2018 Re: Checking if a flag was passed to the compiler | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nicholas Wilson | On Thursday, 22 March 2018 at 12:02:40 UTC, Nicholas Wilson wrote: > On Thursday, 22 March 2018 at 10:08:31 UTC, Nordlöw wrote: >> Is there a way to check in code whether a specific flag, -dip1000 in my case, was passed to the compiler? > > Most command line arguments that are detectable set a version, e.g. D_Coverage, unittest, assert,D_BetterC. I don't see dip1000 in LDC's list of version statements. > > You could do a !__traits(compiles, { something forbidden by dip1000} ); For reference and completeness, a simple example: ```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 (this could of course be fancier) |
March 22, 2018 Re: Checking if a flag was passed to the compiler | ||||
---|---|---|---|---|
| ||||
Posted in reply to Seb | On Thursday, 22 March 2018 at 14:58:56 UTC, Seb wrote:
> For reference and completeness, a simple example:
>
> ```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
>
> (this could of course be fancier)
Thanks
|
Copyright © 1999-2021 by the D Language Foundation