Bug 4886 – Template (alias) tuple parameters cannot take .length property in compiletime

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-09-18T00:54:00Z
Last change time
2012-05-30T20:38:39Z
Assigned to
nobody
Creator
zan77137

Attachments

IDFilenameSummaryContent-TypeSize
764mtype-resolvehelper.patchPatch against dmd r680, fixes resolveHelper()text/plain10424

Comments

Comment #0 by zan77137 — 2010-09-18T00:54:05Z
This code doesn't work! ---- auto test(ARGS...)() { int[ARGS.length] x; return x; } void main(string[] args) { void func(){ } auto t = test!(func)(); } ---- Results: prog.d(3): Error: identifier 'length' of 'ARGS.length' is not defined prog.d(3): Error: index is not a type or an expression prog.d(10): Error: template instance prog.main.test!(func) error instantiating Workaround is this: ---- size_t lengthof(ARGS...)() { return ARGS.length; } auto test(ARGS...)() { int[lengthof!(ARGS)()] x; return x; } void main(string[] args) { void func(){ } auto t = test!(func)(); } ----
Comment #1 by bearophile_hugs — 2010-09-19T17:44:54Z
Reduced test case: template Foo(T...) { int[T.length] x; } static assert(Foo!(1, 2, 3).x.length == 3); void main() {} A workaround: template Foo(T...) { int[cast(int)T.length] x; } static assert(Foo!(1, 2, 3).x.length == 3); void main() {}
Comment #2 by rsinfu — 2010-09-22T22:04:28Z
Created attachment 764 Patch against dmd r680, fixes resolveHelper() This patch fixes the reported issue and bug 2953 (D2). It passed dmd, druntime and phobos tests. The patch also fixes the following problems: -------------------- struct R { alias int T; } struct S { R r; alias r this; } S.T x; // (10) int[S.r.offsetof] y; // (11) -------------------- % dmd -o- -c test.d test.d(10): Error: S.T is used as a type test.d(11): Error: no property 'offsetof' for type 'R'
Comment #3 by k.hara.pg — 2012-05-30T20:38:39Z
All of cases work in 2.060head.