Bug 7892 – Compiler-generated struct copies can result in errors when ctor is @disable'd
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-04-11T19:24:00Z
Last change time
2013-09-30T04:33:09Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
alex
Comments
Comment #0 by alex — 2012-04-11T19:24:34Z
Two such cases:
alexrp@alexrp ~/Projects/tests $ cat test.d
struct S
{
@disable this();
this(int x) {}
}
void main()
{
S f()
out (result)
{
}
body
{
return S(1);
}
}
alexrp@alexrp ~/Projects/tests $ dmd test.d
test.d(12): Error: variable test.main.f.result initializer required for type const(S)
alexrp@alexrp ~/Projects/tests $ cat test2.d
struct S
{
@disable this();
this(int x) {}
}
interface I
{
S f();
}
class C
{
invariant()
{
}
S f()
{
return S(1);
}
}
void main()
{
}
alexrp@alexrp ~/Projects/tests $ dmd test2.d
test2.d(19): Error: variable test2.C.f.__result initializer required for type S
I bet more can be uncovered, but these are the only ones I've run into.
Comment #1 by alex — 2012-04-11T19:26:33Z
OK, the first one is probably not due to an invisible copy, but rather just a bug in the assignment analysis (it follows that if the function returns properly, it must have returned a proper S instance, so the error is wrong).
The second case is only caused when C has an invariant, since the result of every function is then stored in a temporary in order to call the invariant before exiting the function.