Comment #0 by andrej.mitrovich — 2011-07-26T05:33:56Z
import std.typetuple;
struct Foo
{
this(void delegate() dg) { }
}
void test()
{
Foo[] result;
foreach (Type; TypeTuple!(int, int))
{
result ~= Foo( (){} );
}
}
void main()
{
test();
}
OPTLINK (R) for Win32 Release 8.00.12
Copyright (C) Digital Mars 1989-2010 All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
C:\DOCUME~1\Andrej\LOCALS~1\Temp\.rdmd\rdmd-ctfe_bug22.d-97E30C11895AB443DA692FB4CE11A18B\ctfe_bug22-d-97E30C11895AB443DA692FB4CE11A18B.obj(ctfe_bug22-d-97E30C11895AB443DA692FB4CE11A18B) Offset 00960H Record Type 00C3
Error 1: Previous Definition Different : _D12createFields4testFZv12__dgliteral1MFZv
It seems as if the compiler generates two delegates with the same name inside of test(), and they end up clashing. Of course, this function should be called at compile time, not runtime. The fix is to use it as a template:
import std.typetuple;
struct Foo
{
this(void delegate() dg) { }
}
void test()() // template func
{
Foo[] result;
foreach (Type; TypeTuple!(int, int))
{
result ~= Foo( (){} );
}
}
void main()
{
test!(); // call it as a template
}
I don't know if the first case is accepts-invalid or completely legal, but linker errors are never nice to see. Anyway I thought this was worth putting here.
Comment #1 by k.hara.pg — 2013-11-22T02:49:23Z
The problem is finally fixed in 2.064, by fixing bug 9571.