Comment #0 by ellery-newcomer — 2013-04-20T15:56:31Z
the code:
void main() {
goo!()();
}
void goo()() {
auto g = &goo; // not ok
}
void goo2() {
auto g = &goo2; // ok
}
the fireworks:
Error: goo()() is not an lvalue
dmd 2.063-devel.
Comment #1 by maxim — 2013-04-20T21:19:50Z
I think it does not work because &goo is address of raw template and dmd does not instantiate it, so you should use pointer to instantiated function. I am not sure this is bug (but it may be an enhancement request).
Comment #2 by ellery-newcomer — 2013-04-20T22:17:10Z
(In reply to comment #1)
> I think it does not work because &goo is address of raw template and dmd does
> not instantiate it, so you should use pointer to instantiated function. I am
> not sure this is bug (but it may be an enhancement request).
It is inconsistent with the way templated structs and classes work:
void main() {
alias T!(int) t1;
}
struct T(j) {
pragma(msg, "a struct ",T); // T is the struct
}
pragma(msg, "a template ", T); // T is the template
Comment #3 by maxim — 2013-04-20T22:32:39Z
(In reply to comment #2)
> It is inconsistent with the way templated structs and classes work:
>
> void main() {
> alias T!(int) t1;
> }
>
> struct T(j) {
> pragma(msg, "a struct ",T); // T is the struct
> }
> pragma(msg, "a template ", T); // T is the template
Sorry I don't see your point. Note, that second message is printed irrespective to instantiation and none of the messages is sensitive to what T is really is.
void main() {
alias T!(int) t1;
}
struct T(j) {
//pragma(msg, "a struct ",T); // T is the struct
pragma(msg, T.stringof);
}
//pragma(msg, "a template ", T); // T is the template
pragma(msg, T.stringof);
Comment #4 by ellery-newcomer — 2013-04-20T22:45:05Z
(In reply to comment #3)
>
> Sorry I don't see your point. Note, that second message is printed irrespective
> to instantiation and none of the messages is sensitive to what T is really is.
My point is that inside the struct template, T without any template instantiation refers to the instantiated struct:
import std.traits;
void main() {
alias T!(int) t1;
}
struct T(j) {
T foo() {
T t;
return t;
}
}
static assert(is(ReturnType!(T!int.foo) == T!int));
static assert(is(ReturnType!(T!double.foo) == T!double));
But in a templated function, T refers to the template:
Comment #5 by deadalnix — 2013-04-20T22:49:27Z
(In reply to comment #1)
> I think it does not work because &goo is address of raw template and dmd does
> not instantiate it, so you should use pointer to instantiated function. I am
> not sure this is bug (but it may be an enhancement request).
No, within the function, the function must be resolve before the template.
Comment #6 by k.hara.pg — 2013-04-20T23:10:56Z
I think this is a bug.
Inside template function, the name 'goo' should be resolved to the instantiated function 1st, then rewritten to template 'goo' if needed.
For example, this code should work.
void main() {
goo(1); // 1. instantiate goo!int
}
void goo(T...)(T args) {
auto g = &goo; // 2. &goo!int == void function(int)
// 4. &goo!() == void function()
pragma(msg, typeof(g));
static if (T.length)
goo(args[1..$]); // 3. instantiate goo!()
}