Bug 3209 – Please allow pure functions with input known at compile time to be executed at compile time
Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
Mac OS X
Creation time
2009-07-25T04:24:00Z
Last change time
2015-06-09T01:28:07Z
Assigned to
nobody
Creator
asd
Comments
Comment #0 by asd — 2009-07-25T04:24:56Z
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?");
}
}
Comment #1 by smjg — 2009-07-26T16:24:12Z
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