what are the rules for @nogc and @safe attributes inference?
ikod
geller.garry at gmail.com
Fri Nov 30 20:41:03 UTC 2018
On Thursday, 15 November 2018 at 21:55:18 UTC, Steven
Schveighoffer wrote:
> 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
Hello, Steve!
I can't find the reason why nogc/nothrow can't be inferred in
this case:
class S(K,V)
{
auto get/*()*/(K a)
{
return 0;
}
}
void main() @nogc nothrow
{
S!(int, string) sia;
auto v = sia.get(1);
}
But everything is ok if you uncomment parentheses after get. get
is already a member of templated class, what can be wrong with
this code?
Thanks!
More information about the Digitalmars-d-learn
mailing list