Warn about using the GC

Walter Bright newshound2 at digitalmars.com
Sun Jan 14 18:58:11 UTC 2024


On 1/14/2024 1:44 AM, Daniel N wrote:
> On Sunday, 14 January 2024 at 09:25:18 UTC, Walter Bright wrote:
>> Instead of using @nogc, we could have a compiler switch "warn on use of GC" 
>> which you can turn on if you like, or not, or turn on the -w switch to treat 
>> the gc warnings as errors.
> 
> What if you use @nogc in the hot-path but want to use gc during initialization?


The choices are:

1. throw -wgc switch and get a warning for every use of the GC

2. -wgc -w and get errors for every use of the GC

3. compile the gc and non-gc modules separately, using the warning switches for 
the latter

4. disable GC collections on the hot path with GC.disable()/GC.enable()

5. use @nogc and transitively prevent any GC use at all on such functions

6. forcibly cast away @nogc and use the GC anyway

Surely one of those will work for you!



More information about the Digitalmars-d mailing list