Thread overview
[Issue 3209] New: Please allow pure functions with input known at compile time to be executed at compile time
Jul 25, 2009
asd@mailinator.com
Jul 25, 2009
asd@mailinator.com
Jul 26, 2009
Stewart Gordon
July 25, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3209

           Summary: Please allow pure functions with input known at
                    compile time to be executed at compile time
           Product: D
           Version: 2.031
          Platform: All
               URL: http://www.digitalmars.com/webnews/newsgroups.php?art_
                    group=digitalmars.D&article_id=93790
        OS/Version: Mac OS X
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: asd@mailinator.com


Distinction between compile-time and run-time arguments is not intuitive when the input is constant and function is pure:


pure bool isEmptyString(string str) {
    static if (str == "") return true;
    return false;
}

void main()
{
    static if (isEmptyString(""))
    {
        pragma(msg,"works?");
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 25, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3209


asd@mailinator.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 26, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3209


Stewart Gordon <smjg@iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg@iname.com




--- Comment #1 from Stewart Gordon <smjg@iname.com>  2009-07-26 16:24:12 PDT ---
Please don't set a bug to invalid without giving a reason.  I nearly reopened it pending an explanation, but then realised why this shouldn't work.

isEmptyString won't always be evaluated at compile-time, hence it's an attempt at a static if on a non-CTC expression.

That said, the compiler output is slightly bloated, but that's another matter:
----------
bz3209.d(2): Error: expression str == "" is not constant or does not evaluate
to a bool
bz3209.d(8): Error: cannot evaluate isEmptyString("") at compile time
bz3209.d(8): Error: expression isEmptyString("") is not constant or does not
evaluate to a bool

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------