<div>A)</div><div>a number of C++ compilers support temporarily modifying compiler flags in a given scope, via push/pop operations:</div><div><br></div><div>eg:</div><div><br></div><div>----</div><div>//normal code</div><div>
<div>#pragma GCC diagnostic push</div><div>#pragma GCC diagnostic ignored "-Wc++98-compat"</div></div><div>//special code</div><div>#pragma GCC diagnostic pop</div><div><div>//normal code</div><div></div></div><div>
<div>----</div></div><div><br></div><div>(many other use cases).</div><div><br></div><div>I'd like to have that in D to have finer grained setting of compiler && conditional compilation flags.</div><div><br></div>
<div>Proposed syntax for D: use </div><div><br></div><div>----</div><div>//normal code</div><div></div><div>scope{</div><div>version=myversion;</div><div>import std.file;</div><div>extern(C):</div><div><div>//special code</div>
</div><div>}</div><div><div><div><div>//normal code</div><div>//std.file is no longer in scope, version(myversion) no longer holds, code no longer extern(C)</div><div></div></div><div></div></div></div><div>----</div><div>
<br></div><div>Note, it turns out the above syntax compiles in D2.063 (is that a BUG?), even though it seems undocumented and appears to currently have no behavior (ie in code above currently dmd will allow it but version=myversion will take effect till after the closing bracket). </div>
<div><br></div><div>B)</div><div><div>I'd like to be able to set compiler flags inside a given scope as to selectively enable/disable certain compiler options, for example allowing deprecated features only in a given scope, or have a debug build with bounds checking and asserts enabled except for a certain part of the code that would otherwise make the debug code too slow, or even having a check_integer_overflow compiler flag (see recent threads) that would be disabled for code that relies on overflow behavior. </div>
</div><div><br></div><div>Proposed syntax:</div><div>----</div><div>//normal code </div><div>pragma(scope,dmd,"-noboundscheck -d -vtls"){ //dmd because flags could be compiler specific</div><div>  import std.algorithm;</div>
<div>  //code using <b>custom</b> options, including for functions inside std.algorithm and its dependencies</div><div>}</div><div><div>//normal code </div><div>void main(){</div><div>  import std.algorithm;</div><div>  //code using <b>normal</b> options, including for functions inside std.algorithm and its dependencies</div>
<div>}</div><div>----</div></div><div><br></div><div>The behavior of that would be to apply given compiler options recursively for any code inside the scope. The compiler could then compile several versions of a given modules (one per compiler option it appears with). Using a caching mechanism would avoid redoing un-necessary work. The name mangling for custom code would contain a hash of the compiler options.</div>
<div><br></div><div><br></div>