Struct hidden context pointers
Jonathan M Davis
jmdavisProg at gmx.com
Sat Jul 6 14:41:24 PDT 2013
On Saturday, July 06, 2013 14:13:29 H. S. Teoh wrote:
> 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?
Probably, but that's arguably an optimization. Regardless, marking it as
static will force the issue.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list