www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [ .. ] isn't parsed correctly in nested template char[] parameters

reply Don Clugston <dac nospam.com.au> writes:
The error message is:
  found '..' when expecting ']'

But it compiles correctly if parentheses are used around either of the 
slice arguments.
It only seems to happen if the string itself comes from another char[] 
parameter.
Tested on DMD 0.141, 0.142 and 0.143.
-----------------------------------------
template whale(char [] walrus)
{
    const char [] whale = walrus;
}

template dolphin(char [] fish)
{
//  const char [] dolphin = fish[0..3];           // OK
//  const char [] dolphin = whale!(fish[0..(3)]); // OK
//  const char [] dolphin = whale!(fish[(0)..3]); // OK
   const char [] dolphin = whale!(fish[0..3]);     // fails
}

//const char [] urchin = whale!("anenome"[0..3]); // OK
const char [] urchin = dolphin!("anenome");
Jan 12 2006
parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Don Clugston schrieb am 2006-01-12:
 The error message is:
   found '..' when expecting ']'

 But it compiles correctly if parentheses are used around either of the 
 slice arguments.
 It only seems to happen if the string itself comes from another char[] 
 parameter.
 Tested on DMD 0.141, 0.142 and 0.143.
 -----------------------------------------
 template whale(char [] walrus)
 {
     const char [] whale = walrus;
 }

 template dolphin(char [] fish)
 {
 //  const char [] dolphin = fish[0..3];           // OK
 //  const char [] dolphin = whale!(fish[0..(3)]); // OK
 //  const char [] dolphin = whale!(fish[(0)..3]); // OK
    const char [] dolphin = whale!(fish[0..3]);     // fails
 }

 //const char [] urchin = whale!("anenome"[0..3]); // OK
 const char [] urchin = dolphin!("anenome");
Added to DStress as http://dstress.kuehne.cn/run/t/template_24_A.d http://dstress.kuehne.cn/run/t/template_24_B.d http://dstress.kuehne.cn/run/t/template_24_C.d http://dstress.kuehne.cn/run/t/template_24_D.d http://dstress.kuehne.cn/run/t/template_24_E.d http://dstress.kuehne.cn/run/t/template_24_F.d http://dstress.kuehne.cn/run/t/template_24_G.d http://dstress.kuehne.cn/run/t/template_24_H.d http://dstress.kuehne.cn/run/t/template_24_I.d http://dstress.kuehne.cn/run/t/template_24_J.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFDyjrk3w+/yD4P9tIRAkM+AJ48hNLHO0PWdVzOJT+Z5xTQpz296wCeIUOV Y1FIwpT4woveCGNxv7q1+nA= =+g6u -----END PGP SIGNATURE-----
Jan 15 2006