www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Struct hidden context pointers

Today, while trying to track down what I thought was a bug in GDC, I
discovered the following, which looks suspiciously like a bug / quality
of implementation issue:

	import std.conv;

	// Function to test if T is independently instantiable.
	void f(T)() {
	    T t;

	unittest {
	    struct S {
		int x;
	    struct T {
		int y;
		bool f() { return true; }

	    f!S();	// works
	    f!T();	// test.d(4): Error: cannot access frame pointer of
	    		// test.d(17): Error: template instance test.f!(T) error instantiating

	void main() { }

The thing is, nowhere in the definition of T is any frame pointer
required; apparently the frame pointer is triggered by the existence of
any methods in the struct.

Shouldn't the frame pointer be generated only if f() actually tries to
access something outside of the definition of T?


Meat: euphemism for dead animal. -- Flora
Jul 06 2013