Bug 11344 – [2.064 beta] Error: object.destroy called with argument types matches both
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-10-24T12:58:00Z
Last change time
2013-10-28T18:33:31Z
Assigned to
nobody
Creator
rswhite4
Comments
Comment #0 by rswhite4 — 2013-10-24T12:58:07Z
Code:
----
import std.stdio;
struct vec2f {
public:
float[2] values;
alias values this;
}
struct array(T) {
public:
T* ptr;
size_t length;
~this() {
static if (is(T == struct) || is(T == class)) {
foreach (ref T item; this.ptr[0 .. this.length]) {
.destroy!T(item);
}
}
}
}
void main() {
array!vec2f foo;
}
----
C:\Users\Besitzer\D\destroy_bug.d(18): Error: object.destroy called with argument types (vec2f) matches both:
D:\D\dmd2\windows\bin\..\..\src\druntime\import\object.di(513): destroy(T)(ref T obj) if (is(T == struct))
and:
D:\D\dmd2\windows\bin\..\..\src\druntime\import\object.di(524): destroy(T : U[n], U, uint n)(ref T obj)
C:\Users\Besitzer\D\destroy_bug.d(25): Error: template instance destroy_bug.array!(vec2f) error instantiating
Tested with the latest beta.
Worked in dmd 2.063.2
Comment #1 by rswhite4 — 2013-10-24T13:42:23Z
I reduced it.
This code fails in dmd 2.063.2 and dmd 2.064 beta:
----
import std.stdio;
struct vec2f {
public:
float[2] values;
alias values this;
}
void main() {
vec2f v;
destroy(v);
}
----
But this fails only with 2.064 beta:
----
import std.stdio;
struct vec2f {
public:
float[2] values;
alias values this;
}
void main() {
vec2f v;
destroy!vec2f(v);
}
----
Comment #2 by rswhite4 — 2013-10-25T02:08:16Z
Seems that there is something wrong with the array specialization.
This prints almost the same error messages:
-----
import std.stdio;
struct vec2f {
public:
float[2] values;
alias values this;
}
void foo(T)(ref T obj) if (is(T == struct)) {
writeln("#1");
}
void foo(T : U[n], U, size_t n)(ref T obj) {
writeln("#2");
}
void main() {
vec2f v;
foo!vec2f(v);
foo(v);
foo(v.values);
}
----
But this works fine:
----
import std.stdio;
import std.traits;
struct vec2f {
public:
float[2] values;
alias values this;
}
void foo(T)(ref T obj) if (is(T == struct)) {
writeln("#1");
}
void foo(T)(ref T obj) if (isStaticArray!T) {
writeln("#2");
}
void main() {
vec2f v;
foo!vec2f(v);
foo(v);
foo(v.values);
}
----
And prints the expected result:
#1
#1
#2