D Article: Memory Safety

Jakob Ovrum via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Wed Jan 20 20:38:08 PST 2016


On Wednesday, 20 January 2016 at 15:28:05 UTC, jmh530 wrote:
> I like the description of @trusted and template inference. 
> Template inference, in particular, was not something that was 
> obvious to me when first reading about D. I'm not sure how 
> clear you make it that you can still mark templates @safe and 
> what have you (you seem to just say don't make templates 
> @trusted).

Templated functions can still be explicitly annotated with 
attributes, which disables inference for those attributes. This 
is often a good idea even for templated functions when template 
arguments do not inject code, so that every instantiation has the 
same, known set of attributes. Attribute inference can handle it, 
but explicit annotations provide documentation value. I might 
incorporate this into the article, but I'm wary of it losing 
focus.

> I wasn't aware of the point that "@trusted nested functions in 
> templated functions do not have to have a memory safe interface 
> as long as all calls to the function are memory safe". 
> Interesting.

It is a necessary evil to propagate attributes correctly. Don't 
use it when you don't have to.



More information about the Digitalmars-d-announce mailing list