digitalmars.D.learn - nogc deduction for templated functions
- David Zhang (13/13) Nov 18 2017 Hi,
- Eugene Wissner (3/16) Nov 18 2017 If you instantiate "func" the compiler should correctly infer
- Jonathan M Davis (13/26) Nov 18 2017 pure, nothrow, @safe, and @nogc are infered for templated functions. So,
- David Zhang (2/2) Nov 18 2017 Huh, I think I did something weird. It compiles now, and I don't
Hi,
Is there a way for a templated function to deduce or apply the
safe/ nogc attributes automaticaly? I feel like I remember dmd
doing so at one point, but it doesn't appear to work anymore. In
particular, I need to call a function belonging to a templated
type, but do not know what attributes are applied.
eg.
void func(T)(T t)
{
//Don't know if safe or nogc
t.someFunc();
}
Thanks.
Nov 18 2017
On Saturday, 18 November 2017 at 17:28:14 UTC, David Zhang wrote:
Hi,
Is there a way for a templated function to deduce or apply the
safe/ nogc attributes automaticaly? I feel like I remember dmd
doing so at one point, but it doesn't appear to work anymore.
In particular, I need to call a function belonging to a
templated type, but do not know what attributes are applied.
eg.
void func(T)(T t)
{
//Don't know if safe or nogc
t.someFunc();
}
Thanks.
If you instantiate "func" the compiler should correctly infer
the attributes. Do you have any code where it doesn't work?
Nov 18 2017
On Saturday, November 18, 2017 17:28:14 David Zhang via Digitalmars-d-learn
wrote:
Hi,
Is there a way for a templated function to deduce or apply the
safe/ nogc attributes automaticaly? I feel like I remember dmd
doing so at one point, but it doesn't appear to work anymore. In
particular, I need to call a function belonging to a templated
type, but do not know what attributes are applied.
eg.
void func(T)(T t)
{
//Don't know if safe or nogc
t.someFunc();
}
Thanks.
pure, nothrow, safe, and nogc are infered for templated functions. So,
whether those attributes apply when they're not explicitly marked on a
templated function deponds on the contents of the function. You can test it
with a unit test. e.g.
nogc unittest
{
...
foo.func();
}
will give a compiler error if func wasn't infered as nogc.
- Jonathan M Davis
Nov 18 2017
Huh, I think I did something weird. It compiles now, and I don't know why. Thanks for your answers.
Nov 18 2017









Eugene Wissner <belka caraus.de> 