what are the rules for @nogc and @safe attributes inference?

Steven Schveighoffer schveiguy at gmail.com
Thu Nov 15 21:55:18 UTC 2018


On 11/15/18 4:09 PM, Adam D. Ruppe wrote:
> On Thursday, 15 November 2018 at 21:00:48 UTC, ikod wrote:
>> what are the rules for @nogc inference?
> 
> It attempts it if and only if it is a template.

Well, the general "rule" is, if it's code that must be available to the 
compiler when it's called, then it will be inferred.

Examples of code that must be processed every time it's used:

1. Template functions
2. auto-returning functions
3. functions inside templates (like member functions of a templated struct)
4. Inner functions

There may be others I didn't think of.

Everything else must be manually attributed. The reasoning is that the 
function may be stubbed in a .di file, and in that case, attribute 
inference wouldn't be possible.

-Steve


More information about the Digitalmars-d-learn mailing list