Struct hidden context pointers

H. S. Teoh hsteoh at quickfur.ath.cx
Sat Jul 6 14:13:29 PDT 2013


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.__unittestL7_1.T
	    		// 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?


T

-- 
Meat: euphemism for dead animal. -- Flora


More information about the Digitalmars-d mailing list