www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Is this a bug?

reply Li Jie <cpunion gmail.com> writes:
Code:

template test(char[] str)
{
const char test = test1!(str[0]);  // #LINE 87
}

template test1(char c)
{
const char test1 = c;
}

void main()
{
writefln(test!("a")); // #LINE 105
}


Compile error(dmd 0.150 and dmd 0.153):

testcom.d(87): str is used as a type
testcom.d(87): template instance test1!(void[0]) does not match any template
declaration
testcom.d(87): cannot implicitly convert expression (test1!(void[0])) of type
void to char
testcom.d(105): template instance testcom.test!("a") error instantiating



This is no error:

template test(char[] str)
{
const char test = test1!(str);  // #LINE 87
}

template test1(char[] c)
{
const char test1 = c[0];
}

void main()
{
writefln(test!("a")); // #LINE 105
}


Thanks,

- Li Jie
Apr 10 2006
parent reply Li Jie <cpunion gmail.com> writes:
In article <e1fa64$17nq$1 digitaldaemon.com>, Li Jie says...
Code:

template test(char[] str)
{
const char test = test1!(str[0]);  // #LINE 87
}

template test1(char c)
{
const char test1 = c;
}
Modify "test1!(str[0])" to "test1!((str[0]))" can solve the problem.
Apr 11 2006
next sibling parent reply David L. Davis <SpottedTiger yahoo.com> writes:
In article <e1hm4c$l39$1 digitaldaemon.com>, Li Jie says...
In article <e1fa64$17nq$1 digitaldaemon.com>, Li Jie says...
Code:

template test(char[] str)
{
const char test = test1!(str[0]);  // #LINE 87
}

template test1(char c)
{
const char test1 = c;
}
Modify "test1!(str[0])" to "test1!((str[0]))" can solve the problem.
Li Jie, I don't think it's a bug. Below is some code I pull together that I the code, they're only there for holding the formating). But I could be wrong...it has happen before. ;) Output: ---------- C:\dmd>dmd temptest1.d C:\dmd\bin\..\..\dm\bin\link.exe temptest1,,,user32+kernel32/noi; C:\dmd>temptest1 const char[] s = "ABC" Called testT(T="ABC" : char[]).value alias Test(in char[]) Called testT(T='A' : char).value alias Test(in char) Test(s[0])='A', Test(s)="ABC" C:\dmd> David L. ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!" ------------------------------------------------------------------- MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html
Apr 11 2006
parent reply Li Jie <cpunion gmail.com> writes:
In article <e1hqph$q8g$1 digitaldaemon.com>, David L. Davis says...
Li Jie, I don't think it's a bug. Below is some code I pull together that I

the code, they're only there for holding the formating). But I could be
wrong...it has happen before. ;)
Thanks David. Your code is function call, my code is value-parameter template. I want to write a "__uuidof" template, like VC++. A simple implemention is: 0x00, 0x00, 0x00, 0x46]}; It's too long. I think the D-template can calculate it from a string, at compile-time. I write some code: IIDFromStr!("00000000-0000-0000-C000-000000000046"); and {0x00000000, 0x0000, 0x0000, [0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46]}; I like the first.
Apr 11 2006
parent reply David L. Davis <SpottedTiger yahoo.com> writes:
In article <e1hvg6$vqj$1 digitaldaemon.com>, Li Jie says...
In article <e1hqph$q8g$1 digitaldaemon.com>, David L. Davis says...
Li Jie, I don't think it's a bug. Below is some code I pull together that I

the code, they're only there for holding the formating). But I could be
wrong...it has happen before. ;)
Thanks David. Your code is function call, my code is value-parameter template. I want to write a "__uuidof" template, like VC++. A simple implemention is: 0x00, 0x00, 0x00, 0x46]}; It's too long. IIDFromStr!("00000000-0000-0000-C000-000000000046"); and {0x00000000, 0x0000, 0x0000, [0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46]}; I like the first.
Li Jie, I'm still not sure I see the problem...but it looks like your code should compile and work fine in D. (I made a few changes, but nothing major) Output: C:\dmd>dmd uui.d ole32.lib uuid.lib C:\dmd\bin\..\..\dm\bin\link.exe uui,,,ole32.lib+uuid.lib+user32+kernel32/noi; C:\dmd>uui {00000000, 0000, 0000, [192,0,0,0,0,0,0,70]} toString(iu)={00000000-0000-0000-C000-000000000046} IIDFromStr!("00000000-0000-0000-C000-000000000046")="{00000000-0000-0000-C000-000000000046}" C:\dmd> David L. ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!" ------------------------------------------------------------------- MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html
Apr 14 2006
parent Li Jie <cpunion gmail.com> writes:
In article <e1ooai$2tp4$1 digitaldaemon.com>, David L. Davis says...
Li Jie, I'm still not sure I see the problem...but it looks like your code
should compile and work fine in D. (I made a few changes, but nothing major)
Yes, it works find. But it must call like this:
Apr 14 2006
prev sibling parent reply Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Li Jie schrieb am 2006-04-12:
 In article <e1fa64$17nq$1 digitaldaemon.com>, Li Jie says...
Code:

template test(char[] str)
{
const char test = test1!(str[0]);  // #LINE 87
}

template test1(char c)
{
const char test1 = c;
}
Modify "test1!(str[0])" to "test1!((str[0]))" can solve the problem.
Added to DStress as http://dstress.kuehne.cn/compile/t/template_35_A.d http://dstress.kuehne.cn/compile/t/template_35_B.d http://dstress.kuehne.cn/compile/t/template_35_C.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFEP4Ro3w+/yD4P9tIRAsciAJ92mhtJjmFeDZ+1QhdPuG7w8za1rACfU6Z1 HaBN+ofDk3QWW73XnFruEyY= =8E8Q -----END PGP SIGNATURE-----
Apr 14 2006
parent Walter Bright <newshound digitalmars.com> writes:
Thomas Kuehne wrote:
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
 Li Jie schrieb am 2006-04-12:
 In article <e1fa64$17nq$1 digitaldaemon.com>, Li Jie says...
 Code:

 template test(char[] str)
 {
 const char test = test1!(str[0]);  // #LINE 87
 }

 template test1(char c)
 {
 const char test1 = c;
 }
Modify "test1!(str[0])" to "test1!((str[0]))" can solve the problem.
Added to DStress as http://dstress.kuehne.cn/compile/t/template_35_A.d http://dstress.kuehne.cn/compile/t/template_35_B.d http://dstress.kuehne.cn/compile/t/template_35_C.d
This is a known issue - a template argument that looks like a type is treated as a type.
Apr 15 2006