DIP60: @nogc attribute

Artur Skawina via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 17 03:38:40 PDT 2014


On 04/17/14 11:33, Rikki Cattermole via Digitalmars-d wrote:
> On Thursday, 17 April 2014 at 09:22:55 UTC, Dejan Lekic wrote:
>> On Tuesday, 15 April 2014 at 17:01:38 UTC, Walter Bright wrote:
>>> http://wiki.dlang.org/DIP60
>>>
>>> Start on implementation:
>>>
>>> https://github.com/D-Programming-Language/dmd/pull/3455
>>
>> This is a good start, but I am sure I am not the only person who thought "maybe we should have this on a module level". This would allow people to nicely group pieces of the application that should not use GC.
> 
> Sure it does.
> 
> module mymodule;
> @nogc:
> 
>      void myfunc(){}
> 
>      class MyClass {
>          void mymethod() {}
>      }
> 
> 
> Everything in above code has @nogc applied to it.
> Nothing special about it, can do it for most attributes like
> static, final and UDA's.

It does not work like that. User defined attributes only apply to
the current scope, ie your MyClass.mymethod() would *not* have the
attribute. With built-in attributes it becomes more "interesting" -
for example '@safe' will include child scopes, but 'nothrow" won't.

Yes, the current attribute situation in D is a mess. No, attribute
inference isn't the answer.

artur


More information about the Digitalmars-d mailing list