www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Bug 152] New: static assert fails with recursive templates

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

           Summary: static assert fails with recursive templates
           Product: D
           Version: 0.157
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: shro8822 uidaho.edu


This hangs until the stack overflows:

template hang(int i)
{
        static assert(0);
        const int hang = hang!(i-1);
}
const int x = hang!(1);

        This correctly asserts:

template hang()
{
        static assert(0);
        const int hang = hang!();
}
const int x = hang!();

        My guess is that the static assert is evaluated after the next hang!(i)
is evaluated (e.i. never) If a terminating case is added and a pragma(msg,"")
put in, only the terminating case gets the assert.


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

d-bugmail puremagic.com schrieb am 2006-05-23:
 This hangs until the stack overflows:

 template hang(int i)
 {
         static assert(0);
         const int hang = hang!(i-1);
 }
 const int x = hang!(1);

         This correctly asserts:

 template hang()
 {
         static assert(0);
         const int hang = hang!();
 }
 const int x = hang!();

         My guess is that the static assert is evaluated after the next hang!(i)
 is evaluated (e.i. never) If a terminating case is added and a pragma(msg,"")
 put in, only the terminating case gets the assert.

Added to DStress as http://dstress.kuehne.cn/nocompile/a/assert_15_A.d http://dstress.kuehne.cn/nocompile/a/assert_15_B.d http://dstress.kuehne.cn/nocompile/a/assert_15_C.d http://dstress.kuehne.cn/nocompile/a/assert_15_D.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFEdC333w+/yD4P9tIRAvryAJ0V//ccGr/fC350nW/Pd/2G91IGmQCg0oNc qeGu+jyY3gONa6IWvh398Tk= =3ub6 -----END PGP SIGNATURE-----
May 24 2006