function pointer bug?

bitwise via Digitalmars-d digitalmars-d at puremagic.com
Mon Oct 27 15:17:24 PDT 2014


On Monday, 27 October 2014 at 16:08:26 UTC, Solomon E wrote:
> It works after I added 'static' to the declaration of 
> 'invoke()' (and import std.stdio, std.traits.)
>
> I fiddled around with it for hours before I tried 'static' 
> there, because I've only been studying D for a week, so only 
> about half of this code and the error messages made any sense 
> to me when I started on it.
>
> Once it started passing all the tests, I still didn't quite get 
> how it all worked, because of suspecting there was a typo in 
> the code between writing TestClass and testClass. So I tested 
> whether specific instances are called (instead of maybe just 
> the first one constructed) by adding a static counter to 
> TestClass, and storage of the counter by each instance. It 
> looks all right.

I'm pretty sure this is a bug. I'm going to file a report. If one
of those template works, both should.

I have been trying to build a reflection system over the last few
weeks, and noticed different incarnations of this problem several
times:

<b>
&(__error).instanceMethod
</b>

In certain cases, the compiler seems to drop the enclosing type
of the method, but I'm not sure why.


This error seems like it may be related some how:

enum index = __traits(getVirtualIndex, TestClass.instanceMethod);
enum p = TestClass.classinfo.vtbl[index];

The above code will produce this error:
Error: typeid(main.TestClass).vtbl is not yet implemented at
compile time

but if this is the problem, shouldn't Both of the test cases fail?


More information about the Digitalmars-d mailing list