Thread overview | ||||||
---|---|---|---|---|---|---|
|
July 08, 2013 Re: Typeinfo.compare and opCmp woes | ||||
---|---|---|---|---|
| ||||
On Sun, Jul 07, 2013 at 09:44:59PM -0700, H. S. Teoh wrote: > I have a partial fix for issues 8435 and 10118, but it's being blocked by issue 10567. Basically, the problem is that opCmp *must* be declared as: > > struct T { > int opCmp(ref const T t) const { ... } > } > > Only when it's declared this way, will T's typeinfo.compare pick up the correct custom opCmp. [...] Upon further investigation (TypeInfoStructDeclaration::toDt in DMD), it appears that the reason for this restriction is that typeinfo.compare is implemented as a call to a func ptr of signature: int function(in void*, in void*) xopCmp the first argument of which is T.this, and the second of which must be ABI-compatible with the argument to opCmp. Basically, it looks like opCmp is simply cast into the appropriate func ptr and stored in typeinfo.xopCmp. This is unfortunate, because it means opCmp declared in any other way cannot possibly be put into the typeinfo, unless DMD generates a wrapper function that conforms to the above function signature. So basically if opCmp is a template function, we're screwed, since due to the bug that we can't have both a template and non-template method of the same name, it's impossible to declare a non-template opCmp with the correct signature. Then typeinfo.compare will always be wrong. T -- Unix was not designed to stop people from doing stupid things, because that would also stop them from doing clever things. -- Doug Gwyn |
July 08, 2013 Re: Typeinfo.compare and opCmp woes | ||||
---|---|---|---|---|
| ||||
On Sunday, July 07, 2013 22:13:59 H. S. Teoh wrote:
> since due
> to the bug that we can't have both a template and non-template method of
> the same name
I believe that Kenji fixed that bug recently.
- Jonathan M Davis
|
July 08, 2013 Re: Typeinfo.compare and opCmp woes | ||||
---|---|---|---|---|
| ||||
On Sun, Jul 07, 2013 at 10:24:12PM -0700, Jonathan M Davis wrote: > On Sunday, July 07, 2013 22:13:59 H. S. Teoh wrote: > > since due to the bug that we can't have both a template and non-template method of the same name > > I believe that Kenji fixed that bug recently. [...] Kenji is awesome!! So I just figured out that the reason my previous attempts didn't work, was because the opCmp that DMD is looking for to include in the typeinfo must be declared BEFORE all of the other opCmp overloads, otherwise it won't find it. So adding: int opCmp(ref const S s) const { ... } *before* the templated versions of opCmp solved the problem. It's ugly but at least it works. OTOH, this appears to be one of those places where order of declaration matters. :-( T -- The fact that anyone still uses AOL shows that even the presence of options doesn't stop some people from picking the pessimal one. - Mike Ellis |
July 08, 2013 Re: Typeinfo.compare and opCmp woes | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | On 07/08/2013 04:55 PM, H. S. Teoh wrote:
> On Sun, Jul 07, 2013 at 10:24:12PM -0700, Jonathan M Davis wrote:
>> On Sunday, July 07, 2013 22:13:59 H. S. Teoh wrote:
>>> since due to the bug that we can't have both a template and
>>> non-template method of the same name
>>
>> I believe that Kenji fixed that bug recently.
> [...]
>
> Kenji is awesome!! So I just figured out that the reason my previous
> attempts didn't work, was because the opCmp that DMD is looking for to
> include in the typeinfo must be declared BEFORE all of the other opCmp
> overloads, otherwise it won't find it. So adding:
>
> int opCmp(ref const S s) const { ... }
>
> *before* the templated versions of opCmp solved the problem. It's ugly
> but at least it works.
>
> OTOH, this appears to be one of those places where order of declaration
> matters. :-(
>
>
> T
>
Bug.
|
Copyright © 1999-2021 by the D Language Foundation