import std.typecons;
class Foo {
private this(int num) {}
}
void main() {
auto s = scoped!Foo(1);
}
d:\dmd2\windows\bin\..\..\src\phobos\std\conv.d(3903): Error: static assert "Don't know how to initialize an object of type Foo with arguments (int _param_1)"
d:\dmd2\windows\bin\..\..\src\phobos\std\typecons.d(2314): instantiated from here: emplace!(Foo,int)
test9.d(8): instantiated from here: scoped!(Foo,int)
Changing the c'tor to public fixes this.
Comment #1 by monarchdodra — 2013-09-10T23:50:24Z
Is this really valid?
If the constructor is private, then how could "scoped" (or "emplace" in this case) be expected to call it?
Comment #2 by public — 2013-09-11T08:17:54Z
This is invalid as per current D specification but once again highlights fundamental flaw of protection attribute resolution done from definition scope for templates.
Semantically it is the same module who constructs the Foo and access to private constructor is expected. But in fact it is done in `scoped` body which does reside in different module and this does not have access.
Comment #3 by maxim — 2013-09-11T08:37:33Z
This can be probably fixed by providing additional parameter which takes a delegate to private constructor (in a scope which have access to it) as an argument (with default null value). But it looks like it would require hoard of additional parameters along call chain which probably does not worth issue. Right now I close it as WONTFIX, but if some wants to fix, this can be reopened.