Is this a bug?

David L. Davis SpottedTiger at yahoo.com
Tue Apr 11 20:05:21 PDT 2006


In article <e1hm4c$l39$1 at digitaldaemon.com>, Li Jie says...
>
>In article <e1fa64$17nq$1 at 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
think is sort of what you were trying to do (just remove the '#' characters from
the code, they're only there for holding the formating). But I could be
wrong...it has happen before. ;)

# // Template Test1 
# // temptest1.d - dmd v0.153 WinXP SP2
# // To compiled: C:\dmd>dmd temptest1.d
# private import std.stdio;
#
# template testT(T : char[])
# {
#     char[] value(in char[] T) 
#     { 
#         writefln("Called testT(T=\"%s\" : char[]).value 
#                   alias Test(in char[])", T);
#         return T; 
#     }
# }
#
# template testT(T : char)
# {
#     char value(in char T) 
#     { 
#         writefln("Called testT(T='%s' : char).value alias Test(in char)", T);
#         return T; 
#     }
# }
#
# alias testT!(char).value   Test;
# alias testT!(char[]).value Test;
#
# int main()
# { 
#     const char[] s = "ABC";
#     writefln("const char[] s = \"%s\"", s);
#     writefln("Test(s[0])='%s', Test(s)=\"%s\"", Test(s[0]), Test(s));
#     return 0;
# }

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



More information about the Digitalmars-d mailing list