www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Query for -dip1000

reply Per =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
Is there a way to query if the -dip1000 flag has been passed to 
the compiler? I need it for enabling certain DIP-1000 escape 
analysis tests only when -dip1000 has been passed.

For instance

     static assert(!__traits(compiles, {
                 char[] f()
                 {
                     char[2] x;
                     return x[].splitterASCII!(_ => _ == ' 
').front;
                 }
             }));

at

https://github.com/nordlow/phobos-next/blob/bd2fe42978aab2313977042c858d77c5766538e8/src/splitter_ex.d#L110

Or do I have to write a trait myself?
Feb 10 2019
next sibling parent Per =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Sunday, 10 February 2019 at 20:04:29 UTC, Per Nordlöw wrote:
 Or do I have to write a trait myself?
Oops, I had already posted that and got an answer at https://forum.dlang.org/post/qglynupcootocnnnpmhj forum.dlang.org
Feb 10 2019
prev sibling next sibling parent reply Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Sunday, February 10, 2019 1:04:29 PM MST Per Nordlöw via Digitalmars-d-
learn wrote:
 Is there a way to query if the -dip1000 flag has been passed to
 the compiler? I need it for enabling certain DIP-1000 escape
 analysis tests only when -dip1000 has been passed.

 For instance

      static assert(!__traits(compiles, {
                  char[] f()
                  {
                      char[2] x;
                      return x[].splitterASCII!(_ => _ == '
 ').front;
                  }
              }));

 at

 https://github.com/nordlow/phobos-next/blob/bd2fe42978aab2313977042c858d77
 c5766538e8/src/splitter_ex.d#L110

 Or do I have to write a trait myself?
A quick grep of Phobos shows a version(DIP1000) block in std/typecons.d, which appears to be used to make it so that a particular unittest block is only compiled in when -dip1000 is used, so it looks like there's a version identifier for it. - Jonathan M Davis
Feb 11 2019
parent reply Seb <seb wilzba.ch> writes:
On Monday, 11 February 2019 at 09:29:13 UTC, Jonathan M Davis 
wrote:
 On Sunday, February 10, 2019 1:04:29 PM MST Per Nordlöw via 
 Digitalmars-d- learn wrote:
 [...]
A quick grep of Phobos shows a version(DIP1000) block in std/typecons.d, which appears to be used to make it so that a particular unittest block is only compiled in when -dip1000 is used, so it looks like there's a version identifier for it. - Jonathan M Davis
That one has been added manually: https://github.com/dlang/phobos/blob/master/dip1000.mak The detection would have been better...
Feb 11 2019
parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Monday, February 11, 2019 3:23:25 AM MST Seb via Digitalmars-d-learn 
wrote:
 On Monday, 11 February 2019 at 09:29:13 UTC, Jonathan M Davis

 wrote:
 On Sunday, February 10, 2019 1:04:29 PM MST Per Nordlöw via

 Digitalmars-d- learn wrote:
 [...]
A quick grep of Phobos shows a version(DIP1000) block in std/typecons.d, which appears to be used to make it so that a particular unittest block is only compiled in when -dip1000 is used, so it looks like there's a version identifier for it. - Jonathan M Davis
That one has been added manually: https://github.com/dlang/phobos/blob/master/dip1000.mak The detection would have been better...
Honestly, having an explicit version is far better than trying to detect it in an ad-hoc manner. It's actually guaranteed to be right in that case, whereas ad-hoc tests are more likely to have problems - especially if they're around for a while, and things change that weren't anticipated when the code was written. So, I'd actually argue that manually setting it as part of the build was a better idea than trying to detect it, but if it's manually set as part of the build instead of being built into the compiler, then it doesn't help anyone else. Though honestly, it seems to me that having version identifiers for transitional compiler flags like that is probably a good idea, since it makes transitioning code easier. The best that we can do otherwise is generally using __VERSION__, and that only works once the change is the default. - Jonathan M Davis
Feb 11 2019
prev sibling parent Meta <jared771 gmail.com> writes:
On Sunday, 10 February 2019 at 20:04:29 UTC, Per Nordlöw wrote:
 Is there a way to query if the -dip1000 flag has been passed to 
 the compiler? I need it for enabling certain DIP-1000 escape 
 analysis tests only when -dip1000 has been passed.

 For instance

     static assert(!__traits(compiles, {
                 char[] f()
                 {
                     char[2] x;
                     return x[].splitterASCII!(_ => _ == ' 
 ').front;
                 }
             }));

 at

 https://github.com/nordlow/phobos-next/blob/bd2fe42978aab2313977042c858d77c5766538e8/src/splitter_ex.d#L110

 Or do I have to write a trait myself?
https://issues.dlang.org/show_bug.cgi?id=19669
Feb 11 2019