digitalmars.D.bugs - [Issue 6382] New: edge case with static foreach
- d-bugmail puremagic.com (63/63) Jul 26 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6382
http://d.puremagic.com/issues/show_bug.cgi?id=6382 Summary: edge case with static foreach Product: D Version: D2 Platform: Other OS/Version: Windows Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: andrej.mitrovich gmail.com --- Comment #0 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2011-07-26 05:33:56 PDT --- 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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 26 2011