forcing "@nogc" on class destructors

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Tue Jan 20 13:04:09 PST 2015


On Tue, 20 Jan 2015 15:51:17 -0500
Steven Schveighoffer via Digitalmars-d <digitalmars-d at puremagic.com>
wrote:

> On 1/20/15 3:39 PM, ketmar via Digitalmars-d wrote:
> 
> > and all that mess can be avoided just by enforcing the one simple rule,
> > which compiler is perfectly able to check.
> 
> I think the current situation is fine.
> 
> 1. There are functions that sometimes allocate. I don't want to forbid 
> those, or force someone to write @nogc versions.
> 2. One can invoke destructors without being inside the GC.
> 
> This seems like a good job for a lint tool.
my point is that those who need to run lint doesn't do that. enforcing
"@nogc" on class dtors protecting people who are relatively new to D,
and used to do (maybe invisible) allocations in C++ dtors, for example.
yes, this is bad practice even in C++, but it mostly works there. so
they coming to D and often just doesn't know that class dtors are very
special beasts.

to give seasoned programmer some control it's enough to introduce `@gc`
attribute. there are periodical requests for "cancelling attributes" in
NG, so it's a perfect excuse to both make compiler more helpful for
newcomers (yes, it's better to see error message in compile-time than
to get some strange crashes in run-time), and to introduce "cancelling
attrs".
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20150120/7bd82532/attachment.sig>


More information about the Digitalmars-d mailing list