[Issue 20050] New: pure function should be able to return function pointer to impure static nested function
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jul 14 11:26:42 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=20050
Issue ID: 20050
Summary: pure function should be able to return function
pointer to impure static nested function
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: rejects-valid
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: ag0aep6g at gmail.com
Found while looking into issue 20047.
Should compile:
----
int g = 0;
void impure_function_1() { ++g; }
void function() get_impure_function() pure
{
static void impure_function_2()
{
++g; /* Error: pure function test.get_impure_function cannot access
mutable static data g */
impure_function_1(); /* Error: pure function test.get_impure_function
cannot call impure function test.impure_function_1 */
}
return &impure_function_2;
}
void main()
{
auto f = get_impure_function();
f();
assert(g == 2);
}
----
Just because `get_impure_function` is pure doesn't mean that
`impure_function_2` also has to be pure.
--
More information about the Digitalmars-d-bugs
mailing list