When a template is instantiated with a tuple of local symbols, using those local symbols in template-constraint and/or static-if causes a compile error. See (1) and (2) below. The error does not occur if the tuple is evaluated outside static-if scope before used in a static if. See (3). (1) Using a tuple containing a local delegate literal in a template contraint causes an error: -------------------- template Test(a...) if (a.length == 1) // <-- !! { } void main() { alias Test!((int a) { return a; }) test; // Error: delegate test.__dgliteral1 cannot access frame of // function __dgliteral1 } -------------------- (2) Using the same tuple in a static if does not compile for the same error: -------------------- template Test(a...) { static if (typeof(a[0]).stringof) {} // <-- !! } void main() { alias Test!((int a) { return a; }) test; // Error: delegate test.__dgliteral1 cannot access frame of // function __dgliteral1 } -------------------- (3) NOTE: The error does not occur if the tuple is evaluated outside static-if scope before used in a static if: -------------------- template Test(a...) { alias typeof(a) at; // evaluated once (error w/o this line) static if (a.length == 1) {} } void main() { alias Test!((int a) { return a; }) test; // ok } -------------------- (4) The error does not occur if the argument is not a tuple: -------------------- template Test(alias a) // not tuple { static if (typeof(a).stringof) {} } void main() { alias Test!((int a) { return a; }) test; // ok } --------------------
I can't reproduce this on 2.053. Can you confirm?
These all seem to work on dmd2.054
No, it still doesn't work. I tried making a template and passing it a tuple of mixed literals and local variable names and the same error occurred.
(In reply to comment #3) > No, it still doesn't work. I tried making a template and passing it a tuple of > mixed literals and local variable names and the same error occurred. Please post a test case if you have one.
Created attachment 1014 [details] A struct, using which causes some problems.
(In reply to comment #4) > (In reply to comment #3) > > No, it still doesn't work. I tried making a template and passing it a tuple of > > mixed literals and local variable names and the same error occurred. > > Please post a test case if you have one. Can't reproduce that problem ATM, but another problem was discovered: Hsec[] test(items...)() { return Hsec(items); } unittest { int i; float f; char c; foreach(z; test!(5, i, 2.3f, f, 'a', c)) { writeln(z.type, " ", z.kind); } } this code causes DMD to crash.
(In reply to comment #6) > Can't reproduce that problem ATM, but another problem was discovered: Just pasting the code from the attachment and your test case works fine here (latest DMD on OS X x86) – please provide more detailed instructions for reproducing the problem.