www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - predefined version for "nogc" option

reply a11e99z <black80 bk.ru> writes:
I need function that do one thing if GC enabled and other when 
disabled.

I filled issue about it, but maybe u can show some trick:
how to determine in code that "nogc" is enabled?

=======================================================
LDC supports command option:
-nogc = Do not allow code that generates implicit garbage 
collector calls.

but I cannot find corresponding predefined version in 
https://dlang.org/spec/version.html#predefined-versions

need to add version LDC_nogc or D_nogc.
the one should be enabled for -betterC too.
Sep 02 2019
parent reply Kagamin <spam here.lot> writes:
__traits(compiles,new int)
Sep 03 2019
parent reply a11e99z <black80 bk.ru> writes:
On Tuesday, 3 September 2019 at 08:18:13 UTC, Kagamin wrote:
 __traits(compiles,new int)
it doesn't work https://run.dlang.io/is/zdD2cU 2 version of runtime exists: - at compiletime when compiler/ctfe can use all features. - and app runtime when constraints can exist such as no GC, no exceptions.. what exactly __traits(compiles) checks "can this code compile without any conditions?" ? maybe need another trait "rtcompiles" to take into account current options/conditions?
Sep 03 2019
parent reply Kagamin <spam here.lot> writes:
At least

void f()  nogc
{
     static assert(__traits(compiles,new int));
}

fails
Sep 05 2019
parent a11e99z <black80 bk.ru> writes:
On Thursday, 5 September 2019 at 08:02:15 UTC, Kagamin wrote:
 At least
 void f()  nogc
 {
     static assert(__traits(compiles,new int));
 }
 fails
u know that u haven't gc in blocks nogc. try to run
 static assert( __traits( compiles, new int));
 extern(C) int main() { return 0; }
for DMD/LDC:-betterC or LDC:-nogc __traits( compiles, new int) is true. but shouldn't cuz when u use "new int" in code u will get error - module compiled for noGC. (probably we have issue here with __traits) and I don't need error, I am trying to find workaround, so I need some flag/version to choose right code for version with GC and another.
Sep 05 2019