www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - offsetof fails when parameter to a template

reply Mark Guidarelli <guido grumpy-cat.com> writes:
import std.stdio;

struct foo(T) {
	int a;
	T b;
	int c;
}

void output(int offset) {
	writefln("offset = ", offset);
}

void main() {
	// works
	alias foo!(int) bar;
	output(bar.b.offsetof);
	// fails
	// test.d(20): Error: 'this' is only allowed in non-static member functions,
not main
	// test.d(20): Error: this for b needs to be type foo not type int
	output(foo!(int).b.offsetof);
}
Feb 03 2007
parent Mark Guidarelli <guido grumpy-cat.com> writes:
When I change line 20 to "output((foo!(int)).b.offsetof);" it compiles
properly.  Looking at the grammar I believe the original version was valid
though.



import std.stdio;

struct foo(T) {
 int a;
 T b;
 int c;
}

void output(int offset) {
 writefln("offset = ", offset);
}

void main() {
 // works
 alias foo!(int) bar;
 output(bar.b.offsetof);
 // fails
 // test.d(20): Error: 'this' is only allowed in non-static member functions,
not main
 // test.d(20): Error: this for b needs to be type foo not type int
 output(foo!(int).b.offsetof);
}
Feb 05 2007