Bug 5920 – Cannot create std.algorithm.Array of structs with custom destructor (hasElaborateDestructor).
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Mac OS X
Creation time
2011-05-03T02:26:00Z
Last change time
2011-05-03T07:24:45Z
Keywords
patch, rejects-valid
Assigned to
andrei
Creator
kennytm
Comments
Comment #0 by kennytm — 2011-05-03T02:26:41Z
Test case:
-------------------
import std.container;
struct S {
~this() {}
}
alias Array!S A;
void main() {}
-------------------
/usr/include/phobos/std/container.d(1506): Error: function std.container.Array!(S).Array.clear () is not callable using argument types (S)
/usr/include/phobos/std/container.d(1506): Error: function std.container.Array!(S).Array.clear () is not callable using argument types (S)
/usr/include/phobos/std/container.d(1506): Error: this for clear needs to be type Array not type Payload
/usr/include/phobos/std/container.d(1506): Error: expected 0 arguments, not 1 for non-variadic function type void()
/usr/include/phobos/std/container.d(1506): Error: cannot pass types that need destruction as variadic arguments
-------------------
Line 1506 of std.container calls the method 'clear()' on a variable 'e', which I think it should call the global function '.clear()' (this again shows the name 'clear()' is bad.)
The fix is to add back the missing dot:
-------------------------------------------------
diff --git a/std/container.d b/std/container.d
index 94f6ef6..df89c2f 100755
--- a/std/container.d
+++ b/std/container.d
@@ -1503,7 +1503,7 @@ struct Array(T) if (!is(T : const(bool)))
{
foreach (ref e; _payload.ptr[newLength .. _payload.length])
{
- clear(e);
+ .clear(e);
}
}
_payload = _payload.ptr[0 .. newLength];
-------------------------------------------------
Because of this bug (and issue 5792), an Array of Array cannot be created.