www.digitalmars.com         C & C++   DMDScript  

D - A bug?

reply calvin <calvin_member pathlink.com> writes:
When dmd for Windows NT is used to compile the following code, dmd crashes and 
generates an exception. 

import c.stdio;

template TCopy(T) {
void copy(out T to, T from)
{
to = from;
}
}

template TCopy(char[]) 
{
void copy(out char[] to, char[] from)
{
printf("Specialization\n");
to = from;	
}
}

int main()
{	
int i = 0;
float f = 0;
char[] s;

instance TCopy(int) copyint;
instance TCopy(char[]) copystr;

copyint.copy(i, 3); 
printf("%d\n", i);

copystr.copy(s, "Here it comes");
printf("%.*s\n", s);

return 0;
}

The dump captured by Dr. Watson is like,


*----> Task List <----*
0 Idle.exe
2 System.exe
20 SMSS.exe
30 CSRSS.exe
34 WINLOGON.exe
40 SERVICES.exe
43 LSASS.exe
69 SPOOLSS.exe
97 mcshield.exe
124 NALNTSRV.exe
156 RPCSS.exe
154 SNABASE.exe
165 SNMP.exe
180 wm.exe
198 Wuser32.exe
220 clisvcl.exe
227 PSTORES.exe
231 mstask.exe
235 WinMgmt.exe
213 nddeagnt.exe
281 EXPLORER.exe
65 systray.exe
292 PELMICED.exe
287 LOADWC.exe
304 dpmw32.exe
307 nwtray.exe
309 launch32.exe
217 shstat.exe
323 mozilla.exe
340 WZQKPICK.exe
342 SMSMon32.exe
215 rundll32.exe
331 CMD.exe
356 bash.exe
375 exceed.exe
386 CMD.exe
393 bash.exe
249 OUTLOOK.exe
417 MAPISP32.exe
346 DDHELP.exe
372 FrameworkServic.exe
408 UpdaterUI.exe
140 vstskmgr.exe
399 SMSAPM32.exe
479 naPrdMgr.exe
105 bash.exe
447 phoenix.exe
349 bash.exe
444 dmd.exe
428 DRWTSN32.exe
0 _Total.exe

(00400000 - 004c4000) 
(77f60000 - 77fbf000) dll\ntdll.dbg
(77f00000 - 77f5f000) dll\kernel32.dbg
(77e70000 - 77ec2000) dll\user32.dbg
(77ed0000 - 77efc000) dll\gdi32.dbg
(77dc0000 - 77dff000) dll\advapi32.dbg
(77e10000 - 77e67000) dll\rpcrt4.dbg
(10000000 - 10000000) 

State Dump for Thread Id 0x192

eax=008a8248 ebx=00000000 ecx=008c715c edx=008aaa50 esi=008aaa50 edi=008a820c
eip=00404282 esp=0012fee4 ebp=008a8248 iopl=0         nv up ei pl nz na po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=0038  gs=0000             efl=00000206


function: <nosymbols>
0040426e 31c0             xor     eax,eax
00404270 5e               pop     esi
00404271 5b               pop     ebx
00404272 83c408           add     esp,0x8
00404275 c20400           ret     0x4
00404278 51               push    ecx
00404279 8b442408         mov     eax,[esp+0x8]          ss:0108e8eb=????????
0040427d 51               push    ecx
0040427e 53               push    ebx
0040427f 8b5804           mov     ebx,[eax+0x4]          ds:01806c4e=????????
FAULT ->00404282 8b13             mov     edx,[ebx]
ds:00000000=????????
00404284 56               push    esi
00404285 89d9             mov     ecx,ebx
00404287 ff5214           call    dword ptr [edx+0x14]   ds:01809456=????????
0040428a 50               push    eax
0040428b e830ee0700       call    004830c0
00404290 83c404           add     esp,0x4
00404293 8b33             mov     esi,[ebx]              ds:00000000=????????
00404295 50               push    eax
00404296 8bcb             mov     ecx,ebx
00404298 ff5614           call    dword ptr [esi+0x14]   ds:01809456=????????
0040429b 50               push    eax

*----> Stack Back Trace <----*


008a8248 00000000 00000000 00000000 00000000 00000000 !<nosymbols> 
00497994 00403a3c 00481470 00481474 0048148c 00403aa4 !<nosymbols> 
00415334 2b74cb89 799403c7 03c70049 004977a4 17ec03c7 !<nosymbols> 

*----> Raw Stack Dump <----*
0012fee4  94 ae 85 00 5c 71 8c 00 - 5c 71 8c 00 1d 4d 42 00  ....\q..\q...MB.
0012fef4  48 82 8a 00 98 ad 85 00 - 28 48 85 00 2c 0f 41 00  H.......(H..,.A.
0012ff04  48 82 8a 00 40 ae 85 00 - 64 1c 85 00 98 ad 85 00  H... ...d.......
0012ff14  04 00 00 00 94 ae 85 00 - 00 00 00 00 fb 44 42 00  .............DB.
0012ff24  40 ae 85 00 e4 45 85 00 - 64 1c 85 00 00 00 00 00   ....E..d.......
0012ff34  00 00 00 00 01 00 00 00 - 00 00 00 00 00 00 00 00  ................
0012ff44  e7 2a 40 00 00 00 00 00 - 00 00 00 00 c0 ff 12 00  .* .............
0012ff54  00 f0 fd 7f 04 00 00 00 - 08 db 4a 00 01 00 00 00  ..........J.....
0012ff64  01 00 00 00 dc 03 85 00 - 00 00 00 00 44 45 85 00  ............DE..
0012ff74  08 db 4a 00 01 00 00 00 - 01 00 00 00 dc a2 85 00  ..J.............
0012ff84  2e 2b 48 00 03 00 00 00 - 94 45 85 00 60 04 85 00  .+H......E..`...
0012ff94  00 00 00 00 00 00 00 00 - 00 00 00 00 00 f0 fd 7f  ................
0012ffa4  00 00 00 00 98 ff 12 00 - 30 fd 12 00 e0 ff 12 00  ........0.......
0012ffb4  5c 85 48 00 e8 dd 4a 00 - 00 00 00 00 f0 ff 12 00  \.H...J.........
0012ffc4  b5 bb f1 77 00 00 00 00 - 00 00 00 00 00 f0 fd 7f  ...w............
0012ffd4  05 00 00 c0 c8 ff 12 00 - 2c fd 12 00 ff ff ff ff  ........,.......
0012ffe4  6c b9 f3 77 60 d2 f3 77 - 00 00 00 00 00 00 00 00  l..w`..w........
0012fff4  00 00 00 00 a4 2a 48 00 - 00 00 00 00 b0 00 00 00  .....*H.........
00130004  00 01 00 00 ff ee ff ee - 02 00 01 00 00 00 01 00  ................
00130014  00 fe 00 00 00 00 10 00 - 00 20 00 00 00 02 00 00  ......... ......

The specialization for template TCopy is wrong, but a compiler should ...
Jul 09 2003
parent "Walter" <walter digitalmars.com> writes:
Replacing:

template TCopy(char[])

with:

template TCopy(T:char[])

will resolve the issue. The compiler is fixed now to correctly diagnose the
problem.

Thanks!
Jul 11 2003