[Issue 12542] New: No function attribute inference for recursive functions
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Apr 7 23:06:25 PDT 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12542
Summary: No function attribute inference for recursive
functions
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: critical
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: monarchdodra at gmail.com
--- Comment #0 from monarchdodra at gmail.com 2014-04-07 23:06:23 PDT ---
I've seen this being mentioned before in other bugs, but haven't been able to
find an issue proper for it.
Basically, if a function is recursive, then none of it's attributes are
inferred: It's always impure, throwing and unsafe.
//----
int logOf(int n)
{
if (n)
return 1 + logOf(n/2);
return 0;
}
void main() @safe nothrow pure
{
int log = logOf(9);
}
//----
Error: pure function 'D main' cannot call impure function 'main.logOf'
Error: safe function 'D main' cannot call system function 'main.logOf'
Error: 'main.logOf' is not nothrow
Error: function 'D main' is nothrow yet may throw
//----
The compiler should be able to tell that logOf is nothrow and pure. I think
it's safe too: Potential risk of stack overflow aren't considered memory
unsafe, are they?
In any case it's blocking the fixing of certain function attributes, such as
those of sort, or sum.
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list