Compile-time constness is waaay to strict!

Jarrett Billingsley jarrett.billingsley at gmail.com
Fri Jul 24 20:20:41 PDT 2009


On Fri, Jul 24, 2009 at 11:03 PM, asd<a at s.d> wrote:
> Jarrett Billingsley Wrote:
>
>> Can you post more of your code?
>
> I've reduced it to this:
>
>
> bool isEmptyString(string str) {
>        static if (str == "") return true;

It works if you use 'if' instead of 'static if', oddly.

>        return false;
> }
>
> void main()
> {
>        static if (isEmptyString(""))
>        {
>                int x = 1;
>        }
> }
>
>
> test.d(5): Error: expression str == "" is not constant or does not evaluate to a bool
> test.d(11): Error: cannot evaluate isEmptyString("") at compile time
> test.d(11): Error: expression isEmptyString("") is not constant or does not evaluate to a bool

Be sure to report this on Bugzilla: http://d.puremagic.com/issues/



More information about the Digitalmars-d mailing list