[Issue 14769] Cannot instantiate templates for locally defined struct when constructor is present

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Jul 4 23:19:42 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14769

--- Comment #1 from Kenji Hara <k.hara.pg at gmail.com> ---
(In reply to Simon Sigurdhsson from comment #0)
> The following fails to compile, with the error "Error: template
> std.conv.toImpl cannot deduce function from argument types !(S2)(string)"
> (i.e. S1 works fine, but S2 doesn't):

S2 is a nested struct and you can create the instance only inside the enclosing
unittest, because it requires valid context. Therefore, to!S2 function cannot
create it.

> Moving the struct definitions out of the unittest block also works fine:

Moving declarations out of the unittest will make S2 non-nested. Then the
limitation will be lifted.

A quick workaround is adding `static` to struct S2.

--


More information about the Digitalmars-d-bugs mailing list