www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - template bug?

reply "gedaiu" <szabobogdan yahoo.com> writes:
Hi,

Is this a bug in the compiler?


import std.stdio;
import std.typetuple;

class A {

	int foo() {
		return 0;
	}
}

class B : A {
	alias A.foo foo;

	override int foo() {
		return 1;
	}

}


template ItemProperty(item, string method) {
	static if(__traits(hasMember, item, method)) {
		static if(__traits(getProtection, ItemProperty!(item, 
method)).stringof[1..$-1] == "public") {
			alias ItemProperty = TypeTuple!(ItemProperty!(item, method));
		} else {
			alias ItemProperty = TypeTuple!();
		}

	} else {
		alias ItemProperty = TypeTuple!();
	}
}

void test()() {

	static if(ItemProperty!(B, "foo").length > 1) {
		writeln("found");
	} else {
		writeln("not found");
	}
}


void main()
{
	
	test;

	
}
Dec 03 2014
parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 12/03/2014 09:10 AM, gedaiu wrote:
 Hi,

 Is this a bug in the compiler?
Attempting to compile with a recent dmd git head causes segmentation fault. Any compiler crash is a compiler bug. Please report it at https://issues.dlang.org/ Ali
Dec 03 2014
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Ali Çehreli:

 Attempting to compile with a recent dmd git head causes 
 segmentation fault. Any compiler crash is a compiler bug. 
 Please report it at

   https://issues.dlang.org/

 Ali
A first reduction for Bugzilla: alias TypeTuple(T...) = T; struct A { void foo() {} } template ItemProperty(item, string method) { static if(__traits(getProtection, ItemProperty!(item, method)).stringof) alias ItemProperty = TypeTuple!(ItemProperty!(item, method)); } void main() { auto l = ItemProperty!(A, "foo").length; } Bye, bearophile
Dec 03 2014
parent "gedaiu" <szabobogdan yahoo.com> writes:
On Wednesday, 3 December 2014 at 18:25:41 UTC, bearophile wrote:
 Ali Çehreli:

 Attempting to compile with a recent dmd git head causes 
 segmentation fault. Any compiler crash is a compiler bug. 
 Please report it at

  https://issues.dlang.org/

 Ali
A first reduction for Bugzilla: alias TypeTuple(T...) = T; struct A { void foo() {} } template ItemProperty(item, string method) { static if(__traits(getProtection, ItemProperty!(item, method)).stringof) alias ItemProperty = TypeTuple!(ItemProperty!(item, method)); } void main() { auto l = ItemProperty!(A, "foo").length; } Bye, bearophile
Thanks for the code revised version. I thought that the compiler crashes because I was trying to get the access of an overrided method. Bogdan
Dec 04 2014