www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Bug 160] New: static if short-circuit && doesn't work for template arguments

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/bugzilla/show_bug.cgi?id=160

           Summary: static if short-circuit && doesn't work for template
                    arguments
           Product: D
           Version: 0.158
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: clugdbug yahoo.com.au


In the code below, the second term should not be evaluated at all, since
'bird.length>99' is not true. Currently, short-circuit correctly prevents
'fish!()' from being evaluated, but it still incorrectly tries to evaluate
'bird[95]', so compilation fails. I believe this is a regression (though
possibly not a recent one).

-------

template fish( char s)
{
  const bool fish = true;
}

template dog(char [] bird)
{
        static if (bird.length>99 && fish!( (bird[95])) )
           const int dog = 2;
        else const int dog = 3;
}

const int pig = dog!("a");


-- 
May 29 2006
parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

d-bugmail puremagic.com schrieb am 2006-05-29:
 http://d.puremagic.com/bugzilla/show_bug.cgi?id=160
 In the code below, the second term should not be evaluated at all, since
 'bird.length>99' is not true. Currently, short-circuit correctly prevents
 'fish!()' from being evaluated, but it still incorrectly tries to evaluate
 'bird[95]', so compilation fails. I believe this is a regression (though
 possibly not a recent one).

 -------

 template fish( char s)
 {
   const bool fish = true;
 }

 template dog(char [] bird)
 {
         static if (bird.length>99 && fish!( (bird[95])) )
            const int dog = 2;
         else const int dog = 3;
 }

 const int pig = dog!("a");
Added to DStress as http://dstress.kuehne.cn/run/o/opAndAnd_02_A.d http://dstress.kuehne.cn/run/o/opAndAnd_02_B.d http://dstress.kuehne.cn/run/o/opAndAnd_02_C.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFEftC43w+/yD4P9tIRAh1+AJ48/1RxYWPDDOT8fVJC7JcoJucqYgCgmcNI 28ZqwqdwCCEoMMIYc8QBITo= =cg/e -----END PGP SIGNATURE-----
Jun 01 2006