Problem with CTFE

Jarrett Billingsley kb3ctd2 at yahoo.com
Tue Dec 18 12:10:07 PST 2007


"Sean Kelly" <sean at f4.ca> wrote in message 
news:fk98ve$2mgq$1 at digitalmars.com...
> Can someone tell me why compiling with version=Good works, but compiling 
> with version=Bad fails?
>
>     version( Good )
>     {
>         size_t find(Elem)( Elem[] buf, Elem pat )
>         {
>             for( size_t pos = 0; pos < buf.length; ++pos )
>             {
>                 if( buf[pos] == pat )
>                     return pos;
>             }
>             return buf.length;
>         }
>     }
>     else version( Bad )
>     {
>         size_t find(Buf, Pat)( Buf buf, Pat pat )
>         {
>             return 0;
>         }
>     }
>
>     const pos = find( "abcdefg", 'c' );
>
>     void main()
>     {
>
>     }

Seems like a bug to me.  Using the Bad version in a non-constant context 
works fine.  Using the Bad version with explicitly-specified types in a 
constant context also works fine.  Maybe some kind of ordering bug in the 
compiler; it doesn't deduce the two types before it tries to evaluate it or 
something. 




More information about the Digitalmars-d-learn mailing list