www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Trouble with destroy

reply "Namespace" <rswhite4 googlemail.com> writes:
Code:
----
import std.stdio;

struct A {
public:
	int[4] val;
	
	alias val this;
}

void main()
{
	A a;
	a.destroy();
}
----

/d824/f630.d(13): Error: template object.destroy matches more 
than one template declaration, 
/opt/compilers/dmd2/include/object.di(593):destroy(T)(ref T obj) 
if (is(T == struct)) and 
/opt/compilers/dmd2/include/object.di(604):destroy(T : U[n], U, 
ulong n)(ref T obj)

Nice. What should I do?
Sep 23 2013
parent reply "Namespace" <rswhite4 googlemail.com> writes:
On Monday, 23 September 2013 at 19:06:48 UTC, Namespace wrote:
 Code:
 ----
 import std.stdio;

 struct A {
 public:
 	int[4] val;
 	
 	alias val this;
 }

 void main()
 {
 	A a;
 	a.destroy();
 }
 ----

 /d824/f630.d(13): Error: template object.destroy matches more 
 than one template declaration, 
 /opt/compilers/dmd2/include/object.di(593):destroy(T)(ref T 
 obj) if (is(T == struct)) and 
 /opt/compilers/dmd2/include/object.di(604):destroy(T : U[n], U, 
 ulong n)(ref T obj)

 Nice. What should I do?
As always. As soon as you wrote it, you've got the solution. ---- destroy!A(a); ----
Sep 23 2013
next sibling parent reply "Meta" <jared771 gmail.com> writes:
On Monday, 23 September 2013 at 19:11:53 UTC, Namespace wrote:
 As always. As soon as you wrote it, you've got the solution.
 ----
 destroy!A(a);
 ----
This still seems like it should be worth reporting. I can't remember... Is partial ordering done between multiple matching template functions like it is with regular functions? If so, there should be no ambiguity in choosing the second one.
Sep 23 2013
next sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Tuesday, September 24, 2013 05:18:38 Meta wrote:
 On Monday, 23 September 2013 at 19:11:53 UTC, Namespace wrote:
 As always. As soon as you wrote it, you've got the solution.
 ----
 destroy!A(a);
 ----
This still seems like it should be worth reporting. I can't remember... Is partial ordering done between multiple matching template functions like it is with regular functions? If so, there should be no ambiguity in choosing the second one.
The problem is that the type matches two different templated functions, and as it stands, there is no way for the compiler to disambiguate. They're both equally valid. The only way that they could be disambiguated would be if the compiler preferred the actual type over the aliased one (which arguably, it should, but it clearly it doesn't at this point, and I don't know what all of the ramifications are if it did). But I don't think that there's anything wrong with destroy in this case. If there's a problem, it's with how alias this is handled when determining which overloaded template to use. - Jonathan M Davis
Sep 23 2013
prev sibling next sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Tue, Sep 24, 2013 at 05:18:38AM +0200, Meta wrote:
 On Monday, 23 September 2013 at 19:11:53 UTC, Namespace wrote:
As always. As soon as you wrote it, you've got the solution.
----
destroy!A(a);
----
This still seems like it should be worth reporting. I can't remember... Is partial ordering done between multiple matching template functions like it is with regular functions? If so, there should be no ambiguity in choosing the second one.
IIRC, D templates don't have best-match like C++ does; it was an explicit design choice that multiple matching templates is an error. T -- Lawyer: (n.) An innocence-vending machine, the effectiveness of which depends on how much money is inserted.
Sep 23 2013
prev sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Monday, September 23, 2013 22:45:33 H. S. Teoh wrote:
 On Tue, Sep 24, 2013 at 05:18:38AM +0200, Meta wrote:
 On Monday, 23 September 2013 at 19:11:53 UTC, Namespace wrote:
As always. As soon as you wrote it, you've got the solution.
----
destroy!A(a);
----
This still seems like it should be worth reporting. I can't remember... Is partial ordering done between multiple matching template functions like it is with regular functions? If so, there should be no ambiguity in choosing the second one.
IIRC, D templates don't have best-match like C++ does; it was an explicit design choice that multiple matching templates is an error.
Correct. For IFTI to work, the arguments need to pass exactly one of the overloads' template constraints. If they pass the template constraints for multiple overloads, then it's an ambiguity error. There is no attempt to figure out which matches "better." - Jonathan M Davis
Sep 23 2013
prev sibling parent reply "Namespace" <rswhite4 googlemail.com> writes:
On Monday, 23 September 2013 at 19:11:53 UTC, Namespace wrote:
 On Monday, 23 September 2013 at 19:06:48 UTC, Namespace wrote:
 Code:
 ----
 import std.stdio;

 struct A {
 public:
 	int[4] val;
 	
 	alias val this;
 }

 void main()
 {
 	A a;
 	a.destroy();
 }
 ----

 /d824/f630.d(13): Error: template object.destroy matches more 
 than one template declaration, 
 /opt/compilers/dmd2/include/object.di(593):destroy(T)(ref T 
 obj) if (is(T == struct)) and 
 /opt/compilers/dmd2/include/object.di(604):destroy(T : U[n], 
 U, ulong n)(ref T obj)

 Nice. What should I do?
As always. As soon as you wrote it, you've got the solution. ---- destroy!A(a); ----
Because this solution does not work anymore with dmd 2.064 beta: Are there any other tips and tricks?
Oct 25 2013
parent reply "Dicebot" <public dicebot.lv> writes:
On Friday, 25 October 2013 at 07:29:16 UTC, Namespace wrote:
 Because this solution does not work anymore with dmd 2.064 
 beta: Are there any other tips and tricks?
File regression and write to dmd beta mail list. It is clearly lack of extra constraint on `T : U[n]` overload (it should explicitly check that T is not an aggregate)
Oct 25 2013
parent reply "Namespace" <rswhite4 googlemail.com> writes:
On Friday, 25 October 2013 at 11:10:03 UTC, Dicebot wrote:
 On Friday, 25 October 2013 at 07:29:16 UTC, Namespace wrote:
 Because this solution does not work anymore with dmd 2.064 
 beta: Are there any other tips and tricks?
File regression and write to dmd beta mail list. It is clearly lack of extra constraint on `T : U[n]` overload (it should explicitly check that T is not an aggregate)
http://forum.dlang.org/thread/bug-11344-3 http.d.puremagic.com%2Fissues%2F
Oct 25 2013
parent "Dicebot" <public dicebot.lv> writes:
On Friday, 25 October 2013 at 12:09:34 UTC, Namespace wrote:
 http://forum.dlang.org/thread/bug-11344-3 http.d.puremagic.com%2Fissues%2F
K, I have sent a mail to beta list pointing to it. IMHO `destroy` constraints need to be much more strict as destroying only part of object via `alias this` unlikely ever to make sense and is very error-prone.
Oct 25 2013