www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Template declaration doesn't match

reply "tcak" <tcak pcak.com> writes:
I started writing a piece code today. It is as following.

class Test{
	public enum DATA_LENGTH = 16;

	public static void foo( T )( in T[DATA_LENGTH] msg ) if( is(T: 
ubyte) || is(T: char)){
		//...
	}

	public static void bar( in ubyte[DATA_LENGTH] msg ){
		//...
	}
}

void main(){
	ubyte[ Test.DATA_LENGTH ] msg;

	Test.foo( msg ); // error: template bugtest.Test.foo does not 
match any function template declaration.

	Test.bar( msg ); // ok. works
}

If I call `foo`, it gives error as noted. I am on Ubuntu 13.10 
64-bit, DMD 2.064.2.

Is that error normal and I am missing something? or a bug?
Feb 09 2014
next sibling parent "Peter Alexander" <peter.alexander.au gmail.com> writes:
On Sunday, 9 February 2014 at 19:16:35 UTC, tcak wrote:
 Is that error normal and I am missing something? or a bug?

Bizarre, if you replace DATA_LENGTH with 16 in foo then it works: public static void foo( T )( T[16] msg ) if( is(T: ubyte) || is(T: char)){ //... } Definitely a bug. Please file it. https://d.puremagic.com/issues/enter_bug.cgi?product=D
Feb 09 2014
prev sibling next sibling parent "John Colvin" <john.loughran.colvin gmail.com> writes:
On Sunday, 9 February 2014 at 19:16:35 UTC, tcak wrote:
 I started writing a piece code today. It is as following.

 class Test{
 	public enum DATA_LENGTH = 16;

 	public static void foo( T )( in T[DATA_LENGTH] msg ) if( is(T: 
 ubyte) || is(T: char)){
 		//...
 	}

 	public static void bar( in ubyte[DATA_LENGTH] msg ){
 		//...
 	}
 }

 void main(){
 	ubyte[ Test.DATA_LENGTH ] msg;

 	Test.foo( msg ); // error: template bugtest.Test.foo does not 
 match any function template declaration.

 	Test.bar( msg ); // ok. works
 }

 If I call `foo`, it gives error as noted. I am on Ubuntu 13.10 
 64-bit, DMD 2.064.2.

 Is that error normal and I am missing something? or a bug?

bug. Pretty sure it's only a problem with static arrays. Here's a workaround, using std.traits.isStaticArray and std.range.ElementType : public static void foo(T)(in T msg) if(isStaticArray!T && T.length == DATA_LENGTH &&(is(ElementType!T : ubyte) || is(ElementType!T : ubyte))) { //... }
Feb 09 2014
prev sibling parent "tcak" <tcak pcak.com> writes:
On Sunday, 9 February 2014 at 19:34:45 UTC, Peter Alexander wrote:
 On Sunday, 9 February 2014 at 19:16:35 UTC, tcak wrote:
 Is that error normal and I am missing something? or a bug?

Bizarre, if you replace DATA_LENGTH with 16 in foo then it works: public static void foo( T )( T[16] msg ) if( is(T: ubyte) || is(T: char)){ //... } Definitely a bug. Please file it. https://d.puremagic.com/issues/enter_bug.cgi?product=D

It is filed. Issue 12122. https://d.puremagic.com/issues/show_bug.cgi?id=12122
Feb 09 2014